1. A SUMMER TRANNING REPORT ON
CORE JAVA WITH ANDROID
Submitted by-
Gopal Das
ASU2012010100025
B.Tech (CSE)- 7th
Sem
Submitted to-
DEPARTMENT OF COMPUTER SCIENCE &
ENGINEERING
APEEJAY SCHOOL OF ENGINEERING AND
TECHNOLOGY
APEEJAY STYA UNIVERSITY
[Session: July- December 2015]
2. ACKNOWLEDGEMENT
I would like to express my gratitude to all those who helped me in various stages
of this training.
I am grateful to my mentor, Mr. Faiz Mohd Arif Khan for the help provided in
completion of the project. Without his friendly help and guidance it was difficult to
develop this project.
I am also thankful to all the Staff Members of HP Kolkata and my friends for their
support and for making the training valuable and fruitful.
ii
3. PREFACE
Under Apeejay Stya University curriculum of B.Tech, students are required to
undergo summer training at the end of 3rd
year in order to get acquainted with the
humdrum of an industry and contribute to its working. As students of Computer Science
and Engineering Department, 3rd
year, B.Tech, Apeejay Stya University, we underwent 6
weeks training in HP, Kolkata for Core Java with Android.
I take pride in presenting this report prepared on “Core Java with Android”. The
purpose of this report is to assemble under one cover a sufficient body of knowledge
about implementing a successful mobile application under Android Platform. The major
premise of this report is the study of Android OS, its working and applications.
The report first gives an overview of Core Java and the Android OS and then
discusses about the tasks completed during the period of internship. Report also
elaborates on the future works which can be persuaded as an advancement of the current
work.
4. iii
ORGANISATIONAL PROFILE
“Success hinges on consistency of leadership, focus, execution, and most
importantly, great products and services.”
- Meg Whitman, President and CEO, HP.
The Hewlett-Packard Company (HP) is an American global information technology
company headquartered in Palo Alto, California, United States. It develops and provides a
wide variety of hardware components as well as software and related services to
consumers, small- and medium-sized businesses (SMBs) and large enterprises, including
customers in the government, health and education sectors.
The company was founded in a two-car garage in Palo Alto by William "Bill"
Redington Hewlett and David "Dave" Packard starting with a line of electronic test
equipment. It specializes in developing and manufacturing computing, data storage, and
networking hardware, designing software and delivering services. Major product lines
include personal computing devices, enterprise and industry standard servers, related
storage devices, networking products, software and a diverse range of printers and other
imaging products.
With ever changing technologies & methodologies, the competition today is much
greater than ever before. The industrial scenario needs constant technical enhancements to
cater to the rapid demands. Summer Trainings are important because it is the best way to
acquire and clear concepts about respective fields.
HP, the largest IT Company in the world, through its partner offers high quality
courses for six weeks. The approach is based on best practices and a combination of
processes tailored to fit the specific needs. [1]
Goals of HP are:
• Providing the learner with an advantage of acquiring the real world experience.
• Help students learn about the practical facets of design and implementation like coding,
decoding, configuration, debugging, installation etc.
• Helping students to face their first job interview.
• Exposing students to corporate/ organizational environment.
5. iv
CONTENTS
TOPIC PAGE NO.
1. Core Java 1
1.1. Introduction 1
1.2. Features of Java 1
1.3. Different Editions of Java 2
1.4. Language Fundamental 2
1.4.1. Primitive Data Types 2
1.4.2. Different Types of Access Specifiers 2
1.4.3. Declaring Constants Using "Final" Keyword 3
1.4.4. Operators 3
1.4.5. Polymorphism 3
1.4.6. Inheritence 4
1.5. Interface 4
1.6. Exception handling 4
1.7. Multi Threading 5
1.8. Stream based I/O 6
2. Android 7
2.1. Introduction 7
2.2. History 8
2.3. OHA 8
2.4. Android Ecosystem 8
2.5. Android Version 9
3. Android Architecture 10
3.1. Elements 10
3.2. Android Components 11
3.2.1. Android Activity 11
3.2.2. Android Activity Life Cycle 11
3.2.3. Android Intent 12
3.2.4. Android Content Provider 13
3.2.5. Services 13
3.2.6. Broadcast Receiver 14
3.3. Android Environment 15
4. Project Structure 16
5. Android Application Development 17
5.1. Objective 17
5.2. Development Requirements 17
5.3. The Media Player Application 17
5.3.1. The UI of the Player 17
5.3.2. The Toast 18
5.3.3. The List of Songs from SD Card 19
7. vi
LIST OF FIGURES
TOPIC PAGE
NO.
2.1. Open Handset Alliance 8
2.2. Android Ecosystem 9
2.3. Android Versions 9
3.1. Android Architecture 11
3.2. Android Activity 11
3.3. Activity Lifecycle 12
3.4. Android Intent 12
3.5. Content Provider 13
3.6. Services 13
3.7. Broadcast Receiver 14
3.8. Android Virtual Device 15
5.1. UI Screen 18
5.2. Song Played 18
5.3. Song Paused 19
5.4. Song Repeated 19
5.5. Song List 20
8. vii
CHAPTER 1
CORE JAVA
1.1. INTRODUCTION
Java programming language is a state of the art and the object oriented language
that has syntaxes similar to that of C but avoid the overly complex features of C++. As a
result of its elegant design and next generation features, Java language has proven widely
popular with programmers. Java language is the language in which Java Applications are
written. When a Java program is compiled it is converted to byte codes that are portable
to machine language of a CPU Architecture known as the Java Virtual Machine (also
called as JVM or Java VM). The Java Platform is a predefined group of Java classes that
exist on each Java installation. These classes are approachable for use by all Java
programmers. [2]
1.2. FEATURES OF JAVA
Following are some of the main features of Java:
1. Compiled and Interpreted: Programs of Java are first compiled and after
compilation, it generates byte codes which are converted into machine language with the
help of interpreter.
2. Platform Independent (or Architectural Neutral) and Distributed: Java
language is platform independent i.e., the programs of Java written in one platform are
easy to transfer because after compilation, byte codes are created which are easily
executable when transferred to another platform.
3. Object-Oriented: It is purely OOP language that is, all the codes of the Java
language are written into classes and objects which supports reusability, maintainability,
etc.
9. 4. Robust: The codes of java are Robust, which means that, it warns a user not to
convert a higher data type into lower.
5. Simple, Small and Familiar : It is a simple language because it contains many
features of other languages like C,C++ and Java removes complexity because it doesn't
use pointers, storage classes and goto statements and Java doesn't support multiple
inheritances.
1
6. High performance: The advance version of JVM uses adaptive and JIT(Just In
Time compilation) technique that improves the performance by converting the java byte
codes to native machine instructions on the fly.[2]
1.3. DIFFERENT EDITIONS OF JAVA
An application may be developed to cater one user at a time, many users at once or
even users who could be in a different place at a given time. The Java Platform realizes
the differing challenges facing developers and offers choice of different Java technologies
depending on the user's requirements.
The Java platform editions contain additional Java APIs for creating different types
of Applications:
a) Java Standard Edition (J2SE): The J2SE is for developing the desktop
Applications and Applets which typically serve only a small number of users at one time.
b) Java Enterprise Edition (J2EE): The J2EE is tailored for Server-based
Applications focusing on serving the needs of lots of users at one time.
c) Java Micro Edition (J2ME): The J2ME is for applications used on tablets,
mobiles and embedded devices.
1.4. LANGUAGE FUNDAMENTAL
1.4.1. PRIMITIVE DATA TYPES
There are eight primitive data types supported by Java:
[1] Byte
[2] Short
[3] int
[4] long
[5] float
10. [6] double
[7] Boolean
[8] char
1.4.2. DIFFERENT TYPES OF ACCESS SPECIFIERS
One of the excellent features of object oriented programming is data-encapsulation.
This feature enables data to have restricted access.
2
There are currently four various access specifiers in java:
Public: All the data members and member functions which are declared public may be
accessed by through any member functions or any object from outside or inside the class.
Private: All of the data members and member functions which are declared as private
may be accesses only from that specific class where it belongs.
Protected: Any data member and member functions which are declared as a protected
may be accessed from within that class and any sub-class of that specific class to which
they belong if it is in the different package or the same package.
Default (No-Specifier): Any data member and member functions which had no access
specifier related to it, it may be accessed from within that package where a class, field
belongs or method, but not from anywhere outside that package.
1.4.3. DECLARING CONSTANTS USING "final" KEYWORD
The final modifier may be applied to four java constructs:
Variables: A final variable may be set once and only once.
Fields: A final field may also be set once, by the Constructor of the class which defines it.
Methods: A final method may not be hidden nor overridden.
Classes: A final class may not be extended.
1.4.4. OPERATORS
Java provides rich set of operators to manipulate variables. We may divide all the
java operators into the following groups:
• The Relational Operators - = =,! = , > , < , >= , <=.
• The Bitwise Operators - & , | , ^ , ~ , << , >> , >>>.
• The Logical Operators - && , || , ! .
• The Assignment Operators - = , += , -= , *= , /=
11. • The Conditional Operator(ternary operator) - ?:
1.4.5. POLYMORPHISM
Polymorphism is the ability of objects (of various types) to respond uniformly to
achieve the exact behaviour to method calls of the same name. Types of Polymorphism:
• Runtime Polymorphism: Method overriding is an example of runtime
polymorphism. A method in sub-class overrides the method into its super-classes with the
same signature and name.
3
• Compile time Polymorphism: Method overloading is an example of the compile
time polymorphism. Method overloading in java means building more than a single
method with the same name with different arguments.
1.4.6. INHERITANCE
The java inheritance defines a 'is-a' relationship between the super-class and its sub-
classes. This means that an object of a sub-class may be used wherever an object of the
super-class may be used. The class inheritance in java mechanism is used to create new
classes from the existing classes. [2]
1.5. INTERFACE
Interface is a set of abstract methods. An abstract method is one that has empty-
implementation. A class implements an interface, thus inheriting the abstract methods of
an interface. An interface is related to a class in the following ways:
Similarities:
• An interface may include any number of methods.
• An interface is written into the file with a '.java' extension, with the name of the
interface matching the name of the file.
• The bytecode of an interface appears into the '.class' file.
• An interface come in packages, and their corresponding bytecode file should be in
the directory structure that coincides the package name.
Dissimilarities:
• An interface cannot be instantiated.
• An interface doesn't contain any constructors.
12. • An interface may extend multiple interfaces.
• An interface isn't extended by a class. It is implemented by a class.
• All of the methods into an interface are abstract.
1.6. EXCEPTION HANDLING
An exception is a problem that comes during the execution of a program. Some
exceptions are caused by the user error, others by the programmer error, and others by
physical resources that have failed in other manner. There are three types of exceptions:
Checked Exceptions: A checked exception is an exception that is typically a user error or
the problem that can't be foreseen by the programmer.
4
Errors: These are not exception at all, but the problems that get up beyond the control of
the user or the programmer. Errors are irrecoverable.
Runtime Exceptions: A runtime exception is an exception that happens that probably
should have been deferred by the programmer.
All of the exception classes are sub-types of the java.lang.exception class. The
exception class is a sub-class of the Throwable class. Other than the exception class there
is another sub-class called Error which is derived from the Throwable class.
The exception class has two main sub-classes: IOException class and
RuntimeException class.
The method catches an error using the combination of the try, catch keywords. The
catch statement involves declaring the type of exception we are trying to catch.
The finally keyword is used to make a block of code that follows the try block. A
finally block of code always runs, if or not an exception has happened.
1.7. MULTITHREADING
Multithreading enables us to write highly efficient programs that make maximum
use of the processor (CPU), because idle time may be required to a minimum.
LIFE CYCLE OF A THREAD:
• New: A new thread starts its life cycle into the new State. It stays in this state until
the program begins the thread. It is also known as a born-thread.
• Runnable: After the fresh born thread is started, the thread becomes the runnable. A
thread in its state is considered to be running its task.
13. • Waiting: Sometimes the thread transitions to the waiting state while the thread waits
for other thread to perform a task. The thread transitions back to the runnable state only
when thread signals the waiting thread to continue running.
• Timed waiting: The runnable thread may enter the timed waiting state for the
specified interval of time. The thread transitions back to the runnable state when that time
interval finishes or when the event it is waiting for occurs.
• Terminated: The runnable thread enters the terminated state when it completes its
task.
1.8. STREAM-BASED INPUT OUTPUT
The I/O Stream: The byte stream handles the I/O of raw binary data. Scanning and
5
formatting permits the program to read and write formatted text. The I/O from the
command line describes the standard streams and the console object.
The Byte Streams: The program uses the byte streams to perform the input and output
of 8 bit bytes. All of the byte stream classes are descended from the InputStream and
OutputStream.
The FileInput Stream: This Stream is used for reading data from files.
The FileOutput Stream: This Stream is used to make a file and write data into it. [2]
14. 6
CHAPTER-2
ANDROID
2.1. Introduction
Android is an open-source platform unlike other operating systems for mobiles,
such as iOS, which is an O.S., developed by Apple to target only for iPhone, iPad and
other Apple devices. Similarly, Symbian is the O.S. owned by Nokia and is used only in
Nokia handsets. Unlike these O.S., due to its open-source platform feature, Android can
be used by any manufacturer of mobile phones. An Android Operating Systems is Linux
based and is suitable for touch screen mobile devices, such as smart phones and tablet
computers. This has led to the overwhelming popularity of Android and helps in making
Android a household name. According to a recent survey, almost half of the smartphones
in United States run on Android. Among the phone manufacturers, Samsung is the largest
producers of smartphones and tablets that run on Android. [3]
2.2. History
The very first Android-powered phone is dated back to October 2008. However
the history of Android starts a few years before with Google acquiring Android Inc. in
July 2005. Android Inc. is a small start-up company founded in Palo Alto, California. In
October 2003, by Andy Rubin, Rich Miner, Nick Sears and Chris White, they started this
Android Inc. as a software development company for mobile phones or in Rubin’s words,
15. “smarter mobile devices that are more aware of its owner’s location and preferences”.
When Google acquired Android, all the four co-founders went to work at Google for the
development of the first Android-powered mobile device. The early intentions of the
company were to develop an advanced operating system for digital cameras. Though,
when it was realized that the market for the devices was not large enough, the company
diverted its efforts towards producing a smartphone operating system that would rival
Symbian and Microsoft Windows Mobile. Despite the past accomplishments of the
founders and early employees, Android Inc. operated secretly, revealing only that it was
working on software for mobile phones. [3]
2.3. Open Handset Alliance (OHA)
7
Google joined with several other members from the wireless community and tried
to get the answer of the question: “what would it take to build a better mobile phone?” To
answer this question, the open handset alliance was formed in November 2007. The OHA
is a business alliance that consists of 47 companies for developing open standard platform
for mobile devices. They termed it as the Android Project. The members of OHA include
handset manufacturers, chip makers, commercialization companies, software companies
and mobile operators. The role of OHA in Android development is to come up with
technologies that could help in lowering the development and distributing the cost of
mobile devices and services. [5]
Fig. 2.1.: Open Handset Alliance
16. 2.4. Android Ecosystem
Apart from the consumers who purchase and own the android devices, there are other
stakeholders of android:
• Google: Developer of Android.
• Original Equipment Manufacturers: Developer of hardware and custom
application
components.
• Application Development Companies: Employers for Android Developers. They
also outsource product development to service companies.
• Freelance Android Developers: Developers with skill-set for Android
development who create their own applications and publish them on Google Play
Store. [2]
8
Fig. 2.2.: Android Ecosystem
2.5. Android Versions
Android is released in a series of versions, starting from 1.0. The initial two
versions 1.0 and 1.1 of Android were simply termed as beta versions. Since April 2009,
Android versions have been developed under a confectionery-themed code name and
released in alphabetical order, starting from cupcake.
17. Fig. 2.3.: Android Versions
9
CHAPTER-3
ANDROID ARCHITECTURE
3.1. ELEMENTS
The Android architecture defines it as a software stack of different layers. Each of
these layers contains a group of program components, such as operating system,
middleware and essential applications. The Android Architecture is composed of the
following elements/layers:
• Linux kernel: Core services (including hardware drivers, process and memory
management) are handled by a Linux kernel. The kernel also provides an
abstraction layer between the hardware and the rest of the stack.
• Libraries: Running on the top of the kernel, Android includes various C/C++
libraries such as libc and SSL. It contains a media library for playback of media
18. files, OpenGL for 2D and 3D graphics, SQLite for database support and SSL and
WebKit for integrated web browsing and Internet security.
• Android Runtime: It is what makes an Android phone an Android phone rather
than a mobile Linux implementation. Including the core libraries and the Dalvik
VM, the Android Runtime is the engine that powers our applications.
• Core Libraries: Although most of the Android application development is written
using the Java language, Dalvik is not a Java VM. The core android libraries
provide most of the functionality available in core Java libraries, as well as Android
specific libraries.
• Dalvik VM: Dalvik is a register-based Virtual Machine that has been optimized to
ensure that a device can run multiple instances efficiently. It relies on Linux kernel
for threading and low-level memory management.
• Application Layer: All applications, both native and third party, are built on the
application layer by means of the API libraries. [2]
• Application Framework: The application framework provides the classes used to
create Android applications. It also provides a generic abstraction for hardware
access and manages user interfaces and application resources.[3]
10
Fig. 3.1.: Android Architecture
3.2. ANDROID COMPONENTS
19. 3.2.1. Android Activity
The activity represents a single screen or interface that allows the users to interact
with an application. So, depending on the application types, applications have single to
multiple activities. All the activities of an application must work together to provide a
comprehensive and cohesive user experience. However, each of these activities could be
independent of one another, thereby enabling a different application to use those
activities.
Fig. 3.2.: Android Activity
3.2.2. Activity Life Cycle
Android applications are designed to stay alive for a very long time. Unlike other
programming paradigms in which applications are launched with a main() method, the
Android system initiates a code in an activity instance by invoking specific callback
methods that correspond to specific stages of its lifecycle.
11
There are several situations in which an activity transits between different states.
However only three of these states can be static, i.e., the activity can exist in one of only
three states for an extended period of time.
• Resumed: In this state, the activity is in the foreground and the user can interact with it. It
is also referred to as running state.
• Paused: In this state, the activity is partially obscured by another activity. The paused
activity does not receive user input and cannot execute any code.
• Stopped: In this state, the activity is completely hidden and not visible to user. It is
considered to be in the background. While stopped the activity instance and all its state
information is retained, but it cannot execute any code.
20. Fig. 3.3.: Activity Lifecycle
3.2.3. Android Intent
Android intents are the message passing mechanisms to communicate an action.
In other words, it provides a description of the actions that we want to be done. Intent is
very closely related to an activity.
Fig. 3.4.: Android Intent
12
3.2.4. Android Content Provider
The Android content providers make a specific set of application’s data so that other
applications can access that data provided they have appropriate permission.
21. Fig. 3.5.: Content Provider
3.2.5. Services
Services are the faceless components of Android as they do not have their
individual interfaces. They typically run in the background to perform long-running
operations or work for remote processes. Services can communicate with other Android
components and use the Android’s notification framework to notify the users. For
example, a service can play music in the background while the user is accessing other
application. Similarly, a service can also help in transferring or fetching data over a
network without hampering the current activity of the user. Services are job-specific and
they are unaffected by the switching activity. They will continue to run in the background
even if we switch to the interface of a different application.
Fig. 3.6.: Services
13
3.2.6. Broadcast Receivers
A broadcast receiver is the component of Android whose sole responsibility is to
receive and react to broadcast announcements. Due to broadcast receivers, an application
react to a system service, for example, screen turning off, low battery, screen capture, etc.
22. Broadcast receivers also help applications to initiate broadcasts to other applications, for
example broadcasting other applications about data download in the device, which is
available for them to use. Applications can use a broadcast receiver to register for a
particular event. Once that event occurs, all the applications get notifications from the
system about that event.
Fig. 3.7.: Broadcast Receivers
3.3. ANDROID ENVIRONMENT
Like many other mobile phone applications, Android is also developed in a host-
target development environment. The application is built on a host machine and
downloaded on a client or target mobile device. We can test the application either on
mobile or an emulator. Most developers prefer an emulator initially and later do final
testing on real device.[3]
14
24. CHAPTER-4
PROJECT STRUCTURE
After creating an application, we study the structure of the project. The structure
contains several sub-folders:
• src (Source): This folder stores the Java source files.
• gen (Generated): This folder contains the files generated by Android itself.
• res (Resources): This folder contains the resources of the application such as pictures,
layouts etc. This in turn contains the following sub-folders:
Drawable: Stores pictures and other files. Usually has sub-folders according to different
screen resolutions.
Layout: Contains XML files that define how various Android views are organized on a
screen.
Values: XML files which stores string values.
Some other key files in the Android project are:
• AndroidManifest.xml: This is the Android definition file. It contains information about the
Android application such as minimum android version, target sdk version and the
permissions to access Android devices.
• MainLayout.xml: This file describes the layout of the page i.e., the placement of every
component on the application screen.
• Activity class: Every application that occupies the entire device screen needs at least one
class which inherits from the activity class. One major method is called onCreate(). This
method initiates the application and loads the layout page.
25. 16
CHAPTER-5
ANDROID APPLICATION DEVELOPMENT
5.1. Objective
The objectives of this project were to create an Application that can play an mp3 audio
file, from files stored in the application’s resources(raw resources), that we can pause,
resume, go forward and backward in time. At the same time the seek bar will its position,
and the text view will show the name of the song current playing.
5.2. Development Requirements
The project was developed on Eclipse using the Android Developer Toolkit. Eclipse
was used because it is Google approved developed environment for Android
Developments and as such has the greatest level of online support. Android applications
are developed using Java Framework.
Testing was completed on the Android Emulator and later on phone- Micromax running
Android 5.0.
i. Operating System: Windows 8
ii. Programming Languages: Java
iii. Platform: Android API Level 17
iv. Softwares:
• Eclipse- Mars
• Android SDK (Contained a true device emulator and advanced debugging tools).
v. Testing and Debugging: Android Emulator and any Android 4.1 or higher Handset
5.3. The Media Player Application
As mentioned earlier, the objective was to build a Media Player application containing a set
of features. The final output is-
5.3.1. The UI of the Player
This activity provides the user, a list view of categories to choose from. After
choosing any of the options, a desired new activity will open. On choosing the “EXIT”
26. 17
option, this application will be closed.
Fig. 5.1.: UI Screen
5.3.2. The TOAST
After choosing the “Play” option, toast function works works up to show the
message “Song played”.
27. Fig. 5.2.: Song Played
18
“Song Pause” toast while song is paused
Fig. 5.3.: Song Paused
“Song Repeated” toast while the repeat button is pressed.
28. Fig. 5.4.: Repeat Song
5.3.3. The List of Songs from SD Card
Playist page of the player. It can read the song saved in SD Card.
19
Fig. 5.5.: Song List
5.4. POSSIBLE ENHANCEMENTS
29. This application, being my first attempt at app development, is a very simple
application. There is a scope for more enhancement to make it more attractive and useful
to users. Some ideas to make this application more user friendly is are:
1. We can add features like recent activity which will store the list of most recently
played songs,
2. Equaliser which is basically used for audio effect like balanced,vocaliser,off,brilliant
treble, bass punch etc.
3. Help and feedback.
20
CONCLUSION
Mobile phones have never been more popular; powerful smartphones are now a regular
choice for consumers; and the Android ecosystem has expanded to include tablet and TV
devices to further expand the horizons of android application.
With the submission of this project, we successfully completed our training in HP,
Kolkata under the guidance of Mr. Faiz Mohd Arif Khan, Former Trainer and Developer
at HPES.
30. 21
REFERENCES
[1] “Summer Training Program”, a presentation provided by HP upon registration.
[2] “Core Java”. HP Education Academia Program, Student Reference Guide, Version
A.01, HPE.08.5.
[3] “Android Application Development ”. HP Education Academia Program, Student
Reference Guide, Version A.01, HPE.08.5.
[4] “Philosophy and Goals”. http://source.android.com/about/philosophy.html. June 28,
2015.
[5] “Android Overview”. Open Handset Alliance. http://
www.openhandsetalliance.com/android_overview.html. June 28, 2015.