You are on page 1of 35

1

ADVANCED JAVA
PCC-CSE-306G

Faculty : Dr. Ashima Mehta Date:


Branch & Semester : CSE_IT_CSIT_VI SEM Subject with Code : AJAVA(PCC-
2

UNIT-IV
ANDROID
Android is a complete set of software for mobile devices such as tablet computers,
notebooks, smartphones, electronic book readers, set-top boxes etc.
It contains a linux-based Operating System, middleware and key mobile applications.
Android is a software package and linux based operating system for mobile devices such
as tablet computers and smartphones.
It is developed by Google and later the OHA (Open Handset Alliance). Java language is
mainly used to write the android code even though other languages can be used.
OHA is a consortium of 84 companies such as google, samsung, AKM, synaptics, KDDI,
Garmin, Teleca, Ebay, Intel etc.
It was established on 5th November, 2007, led by Google. It is committed to advance
open standards, provide services and deploy handsets using the Android Plateform.
Faculty : Dr. Ashima Mehta Date:
Date:
Branch
Branch &
& Semester
Semester :: CSIT_VI SEM
CSE_IT_CSIT_VI SEM Subject with CodeSubject
: CLOUD COMPUTING(PCC-IT-
with Code : AJAVA(PCC-
3

ANDROID
History of Android
The history and versions of android are interesting to know. The code names of android
ranges from A to J currently, such
as Aestro, Blender, Cupcake, Donut, Eclair, Froyo, Gingerbread, Honeycomb, Ice Cream
Sandwitch, Jelly Bean, KitKat and Lollipop. Let's understand the android history in a
sequence.
1) Initially, Andy Rubin founded Android Incorporation in Palo Alto, California, United
States in October, 2003.
2) In 17th August 2005, Google acquired android Incorporation. Since then, it is in the
subsidiary of Google Incorporation.

Faculty : Dr. Ashima Mehta Date:


Date:
Branch
Branch &
& Semester
Semester :: CSIT_VI SEM
CSE_IT_CSIT_VI SEM Subject with CodeSubject
: CLOUD COMPUTING(PCC-IT-
with Code : AJAVA(PCC-
4

UNIT-IV
ANDROID
The important features of android are given below:
1) It is open-source.
2) Anyone can customize the Android Platform.
3) There are a lot of mobile applications that can be chosen by the consumer.
4) It provides many interesting features like weather details, opening screen, live RSS
(Really Simple Syndication) feeds etc.
It provides support for messaging services(SMS and MMS), web browser, storage
(SQLite), connectivity (GSM, CDMA, Blue Tooth, Wi-Fi etc.), media, handset layout etc.

Faculty : Dr. Ashima Mehta Date:


Date:
Branch
Branch &
& Semester
Semester :: CSIT_VI SEM
CSE_IT_CSIT_VI SEM Subject with CodeSubject
: CLOUD COMPUTING(PCC-IT-
with Code : AJAVA(PCC-
5

UNIT-IV
ANDROID
Android Architecture
Android architecture or Android software stack is categorized into five parts:
linux kernel
native libraries (middleware),
Android Runtime
Application Framework
Applications

Faculty : Dr. Ashima Mehta Date:


Date:
Branch
Branch &
& Semester
Semester :: CSIT_VI SEM
CSE_IT_CSIT_VI SEM Subject with CodeSubject
: CLOUD COMPUTING(PCC-IT-
with Code : AJAVA(PCC-
6

Android Architecture

Faculty : Dr. Ashima Mehta Date:


Date:
Branch
Branch &
& Semester
Semester :: CSIT_VI SEM
CSE_IT_CSIT_VI SEM Subject with CodeSubject
: CLOUD COMPUTING(PCC-IT-
with Code : AJAVA(PCC-
7

Service
Service is a background process that can run for a long time.
There are two types of services local and remote. Local service is accessed from within the
application whereas remote service is accessed remotely from other applications running on
the same device.
Content Provider
Content Providers are used to share data between the applications.
Fragment
Fragments are like parts of activity. An activity can display one or more fragments on the
screen at the same time.
AndroidManifest.xml
It contains informations about activities, content providers, permissions etc. It is like the
web.xml file in Java EE.
Faculty : Dr. Ashima Mehta Date:
Date:
Branch
Branch &
& Semester
Semester :: CSIT_VI SEM
CSE_IT_CSIT_VI SEM Subject with CodeSubject
: CLOUD COMPUTING(PCC-IT-
with Code : AJAVA(PCC-
8

1) Linux kernel
It is the heart of android architecture that exists at the root of android architecture. Linux kernel is
responsible for device drivers, power management, memory management, device management and
resource access.
2) Native Libraries
On the top of linux kernel, their are Native libraries such as WebKit, OpenGL, FreeType, SQLite, Media, C
runtime library (libc) etc.
The WebKit library is responsible for browser support, SQLite is for database, FreeType for font support,
Media for playing and recording audio and video formats.
3)Android Runtime
In android runtime, there are core libraries and DVM (Dalvik Virtual Machine) which is responsible to run
android application. DVM is like JVM but it is optimized for mobile devices. It consumes less memory and
provides fast performance.
4) Android Framework
On the top of Native libraries and android runtime, there is android framework. Android framework
includes Android API's such as UI (User Interface), telephony, resources, locations, Content Providers (data)
and package managers. It provides a lot of classes and interfaces for android application development.
5) Applications
On the top of android framework, there are applications. All applications such as home, contact, settings,
games, browsers are using android framework that uses android runtime and libraries. Android runtime
and native libraries are using linux kernal.

Faculty : Dr. Ashima Mehta Date:


Date:
Branch
Branch &
& Semester
Semester :: CSIT_VI SEM
CSE_IT_CSIT_VI SEM Subject with CodeSubject
: CLOUD COMPUTING(PCC-IT-
with Code : AJAVA(PCC-
9

For example, you may write the following code to view the webpage.
Intent intent=new Intent(Intent.ACTION_VIEW);  
intent.setData(Uri.parse("http://www.javatpoint.com"));  
startActivity(intent);  

Faculty : Dr. Ashima Mehta Date:


Date:
Branch
Branch &
& Semester
Semester :: CSIT_VI SEM
CSE_IT_CSIT_VI SEM Subject with CodeSubject
: CLOUD COMPUTING(PCC-IT-
with Code : AJAVA(PCC-
1
0

Building Blocks
An android component is simply a piece of code that has a well defined life cycle e.g. Activity, Receiver,
Service etc.
The core building blocks or fundamental components of android are activities, views, intents, services,
content providers, fragments and AndroidManifest.xml.
Activity
An activity is a class that represents a single screen. It is like a Frame in AWT.
View
A view is the UI element such as button, label, text field etc. Anything that you see is a view.
Intent
Intent is used to invoke components. It is mainly used to:
Start the service
Launch an activity
Display a web page
Display a list of contacts
Broadcast a message
Dial a phone call etc.
Android Virtual Device (AVD)
It is used to test the android application without the need for mobile or tablet etc. It can be created in
different configurations to emulate different types of real devices.

Faculty : Dr. Ashima Mehta Date:


Date:
Branch
Branch &
& Semester
Semester :: CSIT_VI SEM
CSE_IT_CSIT_VI SEM Subject with CodeSubject
: CLOUD COMPUTING(PCC-IT-
with Code : AJAVA(PCC-
1
1

Service
Service is a background process that can run for a long time.
There are two types of services local and remote. Local service is accessed from within the
application whereas remote service is accessed remotely from other applications running on
the same device.
Content Provider
Content Providers are used to share data between the applications.
Fragment
Fragments are like parts of activity. An activity can display one or more fragments on the
screen at the same time.
AndroidManifest.xml
It contains informations about activities, content providers, permissions etc. It is like the
web.xml file in Java EE.
Faculty : Dr. Ashima Mehta Date:
Date:
Branch
Branch &
& Semester
Semester :: CSIT_VI SEM
CSE_IT_CSIT_VI SEM Subject with CodeSubject
: CLOUD COMPUTING(PCC-IT-
with Code : AJAVA(PCC-
1
2

Android Emulator
The Android emulator is an Android Virtual Device (AVD), which represents a specific Android
device. We can use the Android emulator as a target device to execute and test our Android
application on our PC. The Android emulator provides almost all the functionality of a real device. We
can get the incoming phone calls and text messages. It also gives the location of the device and
simulates different network speeds. Android emulator simulates rotation and other hardware
sensors. It accesses the Google Play store, and much more.
Testing Android applications on emulator are sometimes faster and easier than doing on a real
device. For example, we can transfer data faster to the emulator than to a real device connected
through USB.
The Android emulator comes with predefined configurations for several Android phones, Wear OS,
tablet, Android TV devices.

Faculty : Dr. Ashima Mehta Date:


Date:
Branch
Branch &
& Semester
Semester :: CSIT_VI SEM
CSE_IT_CSIT_VI SEM Subject with CodeSubject
: CLOUD COMPUTING(PCC-IT-
with Code : AJAVA(PCC-
1
3

Android Widgets
There are given a lot of android widgets with simplified examples such as Button,
EditText, AutoCompleteTextView, ToggleButton, DatePicker, TimePicker, ProgressBar etc.
Android widgets are easy to learn. The widely used android widgets with examples are
given below:
Android ToastDisplays information for the short duration of time.
Custom ToastWe are able to customize the toast, such as we can display image on the
toast
ToggleButtonIt has two states ON/OFF.
CheckBoxLet's see the application of simple food ordering.
AlertDialogAlertDialog displays a alert dialog containing the message with OK and Cancel
buttons.
SpinnerSpinner displays the multiple options, but only one can be selected at a time.
AutoCompleteTextViewLet's see the simple example of AutoCompleteTextView.
RatingBarRatingBar displays the rating bar.
DatePicker
Datepicker displays the datepicker dialog that can be used to pick the date.
TimePickerTimePicker displays the timepicker dialog that can be used to pick the time.
ProgressBarProgressBar displays progress task.
Faculty : Dr. Ashima Mehta Date:
Date:
Branch
Branch &
& Semester
Semester :: CSIT_VI SEM
CSE_IT_CSIT_VI SEM Subject with CodeSubject
: CLOUD COMPUTING(PCC-IT-
with Code : AJAVA(PCC-
1
4

Activity and Intents


Android Activity Lifecycle is controlled by 7 methods of android.app.Activity class. The
android Activity is the subclass of ContextThemeWrapper class.
An activity is the single screen in android. It is like window or frame of Java.
By the help of activity, you can place all your UI components or widgets in a single screen.

Faculty : Dr. Ashima Mehta Date:


Date:
Branch
Branch &
& Semester
Semester :: CSIT_VI SEM
CSE_IT_CSIT_VI SEM Subject with CodeSubject
: CLOUD COMPUTING(PCC-IT-
with Code : AJAVA(PCC-
1
5

Activity and Intents


.
Method Description
Let's see the 7 lifecycle methods of android activity.

onCreate called when activity is first created.


onStart called when activity is becoming
visible to the user.
onResume called when activity will start
interacting with the user.
onPause called when activity is not visible to
the user.
onStop called when activity is no longer
visible to the user.
onRestart called after your activity is stopped,
prior to start.
onDestroy called before the activity is
destroyed.

Faculty : Dr. Ashima Mehta Date:


Date:
Branch
Branch &
& Semester
Semester :: CSIT_VI SEM
CSE_IT_CSIT_VI SEM Subject with CodeSubject
: CLOUD COMPUTING(PCC-IT-
with Code : AJAVA(PCC-
1
6

Activity and Intents

Faculty : Dr. Ashima Mehta Date:


Date:
Branch
Branch &
& Semester
Semester :: CSIT_VI SEM
CSE_IT_CSIT_VI SEM Subject with CodeSubject
: CLOUD COMPUTING(PCC-IT-
with Code : AJAVA(PCC-
• File: activity_main.xml
• <?xml version="1.0" encoding="utf-8"?>  
• <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/
android"  
•     xmlns:app="http://schemas.android.com/apk/res-auto"  
•     xmlns:tools="http://schemas.android.com/tools"  
•     android:layout_width="match_parent"  
•     android:layout_height="match_parent"  
•     tools:context="example.javatpoint.com.activitylifecycle.MainActivity">  
•   
•     <TextView  
•         android:layout_width="wrap_content"  
•         android:layout_height="wrap_content"  
•         android:text="Hello World!"  
•         app:layout_constraintBottom_toBottomOf="parent"  
•         app:layout_constraintLeft_toLeftOf="parent"  
•         app:layout_constraintRight_toRightOf="parent"  
•         app:layout_constraintTop_toTopOf="parent" />  
•   
• </android.support.constraint.ConstraintLayout>  

17
• File: MainActivity.java
• package example.javatpoint.com.activitylifecycle;  
•   
• import android.app.Activity;  
• import android.os.Bundle;  
• import android.util.Log;  
•   
• public class MainActivity extends Activity {  
•   
•     @Override  
•     protected void onCreate(Bundle savedInstanceState) {  
•         super.onCreate(savedInstanceState);  
•         setContentView(R.layout.activity_main);  
•         Log.d("lifecycle","onCreate invoked");  
•     }  
•     @Override  
•     protected void onStart() {  
•         super.onStart();  
•         Log.d("lifecycle","onStart invoked");  
•     }  
•     @Override  
•     protected void onResume() {  
•         super.onResume();  
•         Log.d("lifecycle","onResume invoked");  
•     }  
•     @Override  
•     protected void onPause() {  
•         super.onPause();  
•         Log.d("lifecycle","onPause invoked");  
•     }  
•     @Override  
•     protected void onStop() {  
•         super.onStop();  
•         Log.d("lifecycle","onStop invoked");  
•     }  
•     @Override  
•     protected void onRestart() {  
•         super.onRestart();  
•         Log.d("lifecycle","onRestart invoked");  
•     }  
•     @Override  
•     protected void onDestroy() {  
•         super.onDestroy();  
•         Log.d("lifecycle","onDestroy invoked");  
•     }  
• }  

18
Output:
You will not see any output on the emulator or device.
You need to open logcat.

19
Now see on the logcat: onCreate, onStart and onResume methods are
invoked

20
Now click on the HOME Button. You will see onPause method is invoked.

21
After a while, you will see onStop method is invoked

22
Now see on
the emulator.
It is on the
home. Now
click on the
center button
to launch the
app again.

23
Now click on
the
lifecycleactivity
icon.

24
JSON AND XML
• Both JSON and XML can be used to receive data from a web server.
• The following JSON and XML examples both define an employees object,
with an array of 3 employees:
• JSON Example
• {"employees":[
  { "firstName":"John", "lastName":"Doe" },
  { "firstName":"Anna", "lastName":"Smith" },
  { "firstName":"Peter", "lastName":"Jones" }
]}
• XML Example
• <employees>
  <employee>
    <firstName>John</firstName> <lastName>Doe</lastName>
  </employee>
  <employee>
    <firstName>Anna</firstName> <lastName>Smith</lastName>
  </employee>
  <employee>
    <firstName>Peter</firstName> <lastName>Jones</lastName>
  </employee>
</employees>

25
•  JSON is Like XML Because
• Both JSON and XML are "self describing" (human
readable)
• Both JSON and XML are hierarchical (values
within values)
• Both JSON and XML can be parsed and used by
lots of programming languages
• Both JSON and XML can be fetched with an
JSON AND •
XMLHttpRequest
JSON is Unlike XML Because
XML •

JSON doesn't use end tag
JSON is shorter
• JSON is quicker to read and write
• JSON can use arrays
• The biggest difference is:
•  XML has to be parsed with an XML parser. JSON
can be parsed by a standard JavaScript function.

26
• For multimedia, android speech visit the link
• https://www.javatpoint.com/android-
software-stack

27
JAVA DESIGN PATTERN

Design Patterns are already defined and provides industry


standard approach to solve a recurring problem, so it saves time
if we sensibly use the design pattern. There are many java design
patterns that we can use in our java based projects.

Using design patterns promotes reusability that leads to


more robust and highly maintainable code. It helps in reducing
total cost of ownership (TCO) of the software product.

Since design patterns are already defined, it makes our code easy
to understand and debug. It leads to faster development and new
members of team understand it easily.

28
• Design patterns represent the best practices
used by experienced object-oriented software
developers. Design patterns are solutions to
general problems that software developers
faced during software development. These
solutions were obtained by trial and error by
numerous software developers over quite a
substantial period of time.

29
• A design patterns are well-proved solution for solving the specific
problem/task.
• Now, a question will be arising in your mind what kind of specific
problem? Let me explain by taking an example.
• Problem Given:
Suppose you want to create a class for which only a single instance (or
object) should be created and that single object can be used by all
other classes.
• Solution:
Singleton design pattern is the best solution of above specific
problem. So, every design pattern has some specification or set of
rules for solving the problems. What are those specifications, you will
see later in the types of design patterns.

30
• Categorization of design patterns:
• Basically, design patterns are categorized into two parts:
• Core Java (or JSE) Design Patterns.
• JEE Design Patterns.
• Core Java Design Patterns
• In core java, there are mainly three types of design patterns, which are further divided into their sub-parts:
• 1.Creational Design Pattern
• Factory Pattern
• Abstract Factory Pattern
• Singleton Pattern
• Prototype Pattern
• Builder Pattern.
• 2. Structural Design Pattern
• Adapter Pattern
• Bridge Pattern
• Composite Pattern
• Decorator Pattern
• Facade Pattern
• Flyweight Pattern
• Proxy Pattern
• 3. Behavioral Design Pattern
• Chain Of Responsibility Pattern
• Command Pattern
• Interpreter Pattern
• Iterator Pattern
• Mediator Pattern
• Memento Pattern
• Observer Pattern
• State Pattern
• Strategy Pattern
• Template Pattern
• Visitor Pattern

31
J2EE PATTERN
• J2EE Patterns are concerned about providing
solutions regarding Java EE.
These patterns are widely accepted by other
frameworks and projects. Like, for an example:
Spring. The J2EE Patterns that are covered in
this article are: ... Data Access Object Pattern.

32
33
34

Creational Patterns: These design patterns provide ways to create objects while


hiding the creation logic, instead of instantiating objects directly using the new
operator. .
Behavioral Patterns: These design patterns are specifically concerned with
communication between objects.
For more info visit this link
https://www.javatpoint.com/design-patterns-in-java

Faculty : Dr. Ashima Mehta Date:


Date:
Branch
Branch &
& Semester
Semester :: CSIT_VI SEM
CSE_IT_CSIT_VI SEM Subject with CodeSubject
: CLOUD COMPUTING(PCC-IT-
with Code : AJAVA(PCC-
• THANK YOU

35

You might also like