SlideShare a Scribd company logo
IMPERATIVE PROGRAMMING LANGUAGE
IPL Paradigm
Closely resemble the architectural structure of actual computer
Based on manipulating bits and values and machine states.
Features
Use of abstract programming units like procedures and functions to encapsulate sequence
Statements which are executed in succession.
The way sequence of statements is executed is abstracted through a program or instruction
counter, which executes the series of instructions stored in memory.
Flow of execution can be manipulated or modified using conditional or looping statements
by abstracting the underlying branch instructions within the machine instruction set.
Usage of actual memory storage of the machine is abstracted through the use of variables
and using assignment statements to assign values to the variables.
Examples of IPL
FORTRAN, Algol, COBOL, Pascal, C/C++, BASIC, Ada, Java, PHP, C# and many more.
The Von Neumann Architecture
ALU CU
MEMORY
CPU
Instruction Set Architecture (ISA)
- Actual CPU instructions visible for the programmers can use
-They form the boundary between hardware and software
-Dimensions of ISA: Class, Memory Addressing, Address Modes, Operand types and
sizes, Operations, control flow instructions, encoding (fixed-length or variable)
IPL Characteristics
Variables and Storage
Commands:
Assignments
-Simple assignment : x = y + 1;
-Multiple assignments: v1 = v2 = v3 = v4 = 200;
-Simultaneous assignment: n1, n2, n3, n4 = m1, m2, m3, m4
-Operator-assignment : m += n
Procedure Calls
Sequential commands
-Control flow mechanism for executing commands in specific order,
Given C1; C2; C2 is executed after C1 is done
Collateral commands
Set of nondeterministic commands, where commands are executed in no particular order.
Conditional commands
-Given a set of subcommands, one is executed if a certain condition is met.
- Example: if-then and switch statements
Iterative commands
-Repeats execution of commands based on defined conditions.
-Uses control variables
-Example: for and while statements
IPL Side effects
Sequential execution can cause side-effects such as values of global variables are changed
inside procedure calls, which may make the program unreadable because some parts of
the program depend on what happens inside other parts.
imperative programming language, java, android
JAVA PROGRAMMING LANGUAGE
What is Java?
A general purpose, imperative, strongly-typed high-level, purely OOP language
Language by programmers for programmers.
Java Design
Platform-independent or architectural-neutral
Let developers create "write once, run anywhere“ applications
Origins
Created by James Gosling, Patrick Naughton, Chris Warth, Ed Frank, and Mike Sheridan in
1991 while at Sun Microsystems.
Initially called “Oak,” but was renamed “Java” in 1995.
Originally intended for embedded systems in consumer electronics, but eventually found
popularity in use for the world wide
Java remains a de facto standard, controlled through the Java Community Process.
9 million developers.
Java today
Java Platform
• Java Card for smartcards.
• Java Platform, Micro Edition (Java ME) – targeting environments with limited
resources.
• Java Platform, Standard Edition (Java SE) – targeting workstation environments.
• Java Platform, Enterprise Edition (Java EE) – targeting large distributed enterprise or
Internet environments.
Java development tools
Eclipse
Netbeans
Java Runtime Environment (JRE)
JVM, class libraries, and launcher
Java Development Kit (JDK)
Environment for building applications, applets, and components. Includes tools for
developing and testing and running Java programs.
Java resources
Java Native Interface (JNI)
Enables programmers to write native methods
The JNI framework lets a native method use Java objects
Java compilation
Source code
Java compiler
Byte code
JVM
(Architecture-
specific)
Target Instruction Set
C++: Compiles to a low-level instruction set that operates
on raw binary data and is specific to the target hardware,
such as x86, ARM, or PowerPC.
Java: Compiles to a higher-level portable bytecode that
operates on typed values: objects, primitive types, and
arrays thereof.
Compiler Optimizations
C++: Numerous code optimizations are performed at
compile time. Inline substitution results in copies of the
given (member) function being scattered around the
binary image; use of the preprocessor combined with
compile-time evaluation of expressions may leave no
trace of the constants defined in the source code; and so
on.
Java: Relies on dynamic (Just-In-Time) compilation for
performance improvement. The standard javac compiler
is straightforward, it does no compile time optimizations
commonly found in C++ compilers. The idea is to enable
the JIT compiler to perform all optimizations at run time,
taking the execution profile into account.
Linkage
C++: Programs are statically linked, and
metaprogramming facilities (reflection) are absent in the
core language. So the names of classes, members, and
variables need not be present in the compiled and linked
program, except for names exported from dynamic
libraries (DLLs/shared objects.)
Java: Dependencies are resolved at run time, when
classes are loaded. So the name of the class and names of
its methods and fields must be present in a class file, as
well as names of all imported classes, called methods,
and accessed fields.
Delivery Format
C++: An application is delivered as a monolithic
executable (maybe with a few dynamic libraries), so it is
not easy to identify all member functions of a given class
or reconstruct the class hierarchy.
Java: An application is typically delivered as a set of jar
files, which are just non-encrypted archives containing
individual class files.
Java vs. C/C++ Compilation
Java Virtual Machine
abstract
assert
boolean
break
byte
case
catch
char
class
Java language
const
continue
default
do
double
else
enum
extends
final
finally
Float
for
goto
if
implements
import
instanceof
int
interface
long
native
new
package
private
protected
public
return
short
static
strictfp
super
switch
synchronized
this
throw
throws
transient
try
void
volatile
while
Java primitive data types
Integers (byte, short, int long)
Floating point (float, double)
Others (char, boolean, arrays)
Java operators
Arithmetic: + * / % ++ += -= *= *= /= %= --
Bitwise : ~ & | ^ >> >>> << &= |= ^= >>= >>>= <<=
Relational : == != > < >= <=
Logical: && ! || != ?:
Java Arrays
type var-name[ ];
array-var = new type [size];
Java separators
“()” , “[]”, “{}”, “;” , “,” , “.”
Java control statements
if-else-statement
if (condition) statement1;
else statement2;
if(condition)
statement;
else if(condition)
statement;
else if(condition)
statement;
...
else
statement;
switch statement
switch (expression) {
case <value1>:
statement-list
break;
…
default: statement-list
}
while(condition) {
// body of loop
}
while statement
do-while statement
do {
// body of loop
} while (condition);
for statement
for(initialization;
condition;
iteration) {
// body
}
Polymorphism
Methods can share the same name as long as their parameter declarations are
different.
Java object-oriented paradigm
Encapsulation
Links data with the code that manipulates it.
Access modifers are public, private, and protected (affects inheritance).
Public : member can be accessed by any other code
Private: member can only be accessed by other members of its class.
Inheritance
class subclass-name extends superclass-name {
// body of class
}
A class member that has been declared as private will remain private to its class. It is not
accessible by any code outside its class, including subclasses.
Superclass
Whenever a subclass needs to refer to its immediate superclass, it can do so by use of the
keyword super.
super has two general forms. The first calls the superclass’ constructor. The second is
used to access a member of the superclass that has been hidden by a member of a
subclass
this keyword
this can be used inside any method to refer to the current object. It is always a reference to
the object on which the method was invoked.
Java object-oriented paradigm
A static member be accessed before any objects of its class are created, and without
reference to any object.
Both methods and variables can be declared as static.
Static keyword
Automatically handles the deallocation of objects.
Garbage Collection
Java exceptions
An exception is an object that describes an exceptional (that is, error) condition that has
occurred in a piece of code.
Exceptions thrown by Java relate to fundamental errors that violate the rules of the Java
language or the constraints of the Java execution environment. Manually generated
exceptions are typically used to report some error condition to the caller of a method.
Exception Handling
try
{
// block of code to monitor for errors
}
catch (ExceptionType execeptionObject)
{
//exception handler
}
...
finally
{
//final block of code to be executed
at the end
}
Java classes and objects
class classname
{
variable declarations
...
method declarations
...
}
class definition
Object declaration
classname varname = new classname();
type name(parameter-list) {
// body of method
}
Method declaration
Java program units
Package – used to partition class name space into smaller chunks
Class – fundamental code units in java; consists of functions and variables.
Function – encapsulates 1 or more statements; may also contain local variables
Statement blocks – consists of one or more java statements enclosed in curly brackets
Bindings
Identifiers – Static
Type – static
Address – Dynamic
Value – Dynamic
Storage – Objects are dynamically allocated
Local variable storage lasts until the method returns.
Package Scope Rules
Private No Modifier Protected Public
Same class Yes Yes Yes Yes
Same package
subclass
No Yes Yes Yes
Same package,
non subclass
NO Yes Yes Yes
Different
package,
subclass
No No Yes Yes
Different
package, non
subclass
No No No Yes
Class Scope Rules
All members of a class are visible to any part of the class (depends if the static keyword
Is used on some members, which affects scope visibility)
Local variables within methods is only visible within the method.
Variables declared within blocks is only visible within the block.
Multithreading
In a thread-based multitasking environment, the thread is the smallest unit of
dispatchable code. This means that a single program can perform two or more tasks
simultaneously
Creating a Thread
In the most general sense, you create a thread by instantiating an object of type Thread.
Java denotes two ways in which this can be accomplished:
• You can implement the Runnable interface.
• You can extend the Thread class, itself.
class NewThread implements Runnable {
Thread t;
NewThread() {
t = new Thread(this,"Demo thread");
System.out.println("child thread: " + t);
t.start();
}
public void run() {
try {
//some statements here
Thread.sleep(500);
}
catch(Exception e) {
System.out.println("Exiting child thread.");
}
}
}
class ThreadDemo{
public static void main(String []args) {
new NewThread();
// main thread statements
}
}
Example using Runnable :
class NewThread extends Thread{
NewThread(){
System.out.println("Child thread: " + this);
start();
}
public void run(){
// thread statements
Thread.sleep(500);
}
}
class ExtendThread{
public static void main(String [] args){
new NewThread();
//main thread statement
Thread.sleep(1000);
}
}
Example by extending Thread:
imperative programming language, java, android
ANDROID
Android the OS
Android is a mobile operating system developed by Google, based on the Linux kernel and
designed primarily for mobile devices such as smartphones and tablets.
Android, Inc. was by Andy Rubin in 2003 (Acquired by Google in 2005)
On the Open Handset Alliance, a consortium of technology companies including Google,
device manufacturers such as HTC, Sony and Samsung, wireless carriers such as Sprint
Nextel and T-Mobile, and chipset makers such as Qualcomm and Texas Instruments,
unveiled itself, with a goal to develop open standards for mobile devices.
Dalvik is a process virtual machine (VM) that executes Android applications (Android 4.4
and earlier). Dalvik is open-source software, originally written by Dan Bornstein, who
named it after the fishing village of Dalvík in Eyjafjörður, Iceland.
Android Runtime Environment
Android Runtime (ART) is an application runtime environment replacing Dalvik
ART performs the translation of the application's bytecode into native instructions that
are later executed by the device's runtime environment.
imperative programming language, java, android
Android SDK
For developing applications for the Android operating system.
Applications are usually developed in Java programming language using the Android
software development kit (SDK), but other development environments are also available.
Linux, Mac OS X, and Windows are supported platforms.
Officially supported integrated development environments (IDE) are Eclipse using the
Android Development Tools (ADT) Plugin, NetBeans IDE, and Android Studio, made by
Google and powered by IntelliJ.
Developers may use any text editor to edit Java and XML files, then use command line
tools (Java Development Kit and Apache Ant are required) to create, build and debug
Android applications as well as control attached Android devices.
The SDK includes a debugger, libraries, a handset emulator based on QEMU,
documentation, sample code, and tutorials.
Android Development Platform
Android ADB
A command line tool that for communicating with an emulator or Android-powered device.
Support native development in C/C++.
Android Native Development Kit (NDK)
Extensions for IDEs to support android development, such as Eclipse.
Android Development Toolkit (ADT)
Android Development Platform
Android SDK Manager
Manages download or updating of SDK packages and tools.
Android ADB
Android Application Build Process
Java source
Java
Compiler
Java class
(byte code)
Dx ToolDex file
APK BuilderJar signer
APK file
Library
resources

More Related Content

What's hot (20)

PDF
Java basics notes
poonguzhali1826
 
PPSX
Introduction to java
Ajay Sharma
 
PPT
SMI - Introduction to Java
SMIJava
 
PPT
Lecture 3 java basics
the_wumberlog
 
PDF
Core Java
Prakash Dimmita
 
PDF
C progrmming
Shivam Singhal
 
PPTX
Core java online training
Glory IT Technologies Pvt. Ltd.
 
PPTX
Object oriented programming-with_java
Hoang Nguyen
 
PDF
Java Presentation For Syntax
PravinYalameli
 
PPSX
Java &amp; advanced java
BASAVARAJ HUNSHAL
 
PPTX
Introduction to java
Sandeep Rawat
 
PDF
JAVA Program Examples
Prof Chethan Raj C
 
PPT
Java tutorial PPT
Intelligo Technologies
 
PPTX
java tutorial for beginner - Free Download
TIB Academy
 
PPT
Java Tutorial
Vijay A Raj
 
PPTX
Introduction to Java programming - Java tutorial for beginners to teach Java ...
Duckademy IT courses
 
PDF
Java notes
Debasish Biswas
 
PPTX
Java introduction
The icfai university jaipur
 
PPT
Core java
kasaragaddaslide
 
PPTX
Core java
Shivaraj R
 
Java basics notes
poonguzhali1826
 
Introduction to java
Ajay Sharma
 
SMI - Introduction to Java
SMIJava
 
Lecture 3 java basics
the_wumberlog
 
Core Java
Prakash Dimmita
 
C progrmming
Shivam Singhal
 
Core java online training
Glory IT Technologies Pvt. Ltd.
 
Object oriented programming-with_java
Hoang Nguyen
 
Java Presentation For Syntax
PravinYalameli
 
Java &amp; advanced java
BASAVARAJ HUNSHAL
 
Introduction to java
Sandeep Rawat
 
JAVA Program Examples
Prof Chethan Raj C
 
Java tutorial PPT
Intelligo Technologies
 
java tutorial for beginner - Free Download
TIB Academy
 
Java Tutorial
Vijay A Raj
 
Introduction to Java programming - Java tutorial for beginners to teach Java ...
Duckademy IT courses
 
Java notes
Debasish Biswas
 
Java introduction
The icfai university jaipur
 
Core java
kasaragaddaslide
 
Core java
Shivaraj R
 

Similar to imperative programming language, java, android (20)

PDF
Introduction to java (revised)
Sujit Majety
 
PDF
java notes.pdf
JitendraYadav351971
 
PDF
Java training materials for computer engineering.pdf
SkvKirupasri
 
PPTX
introduction to object orinted programming through java
Parameshwar Maddela
 
PDF
PJ_M01_C01_PPT_Introduction to Object Oriented Programming Using Java.pdf
projectfora2
 
PPTX
UNIT 1.pptx
EduclentMegasoftel
 
PPTX
Java
Sneha Mudraje
 
PPTX
Java UNITbgbgbfdbv v bbfbf cvbgfbvc gf 1.pptx
hofon47654
 
PPTX
object oriented programming unit one ppt
isiagnel2
 
PPT
Basics-Of-Java
ssuser200038
 
PPTX
Mpl 1
AHHAAH
 
PPT
j-chap1-Basics.ppt
SmitaBorkar9
 
PPTX
Knowledge of Javascript
Samuel Abraham
 
PPTX
Module--fundamentals and operators in java1.pptx
Radhika Venkatesh
 
PPTX
Unit1 introduction to Java
DevaKumari Vijay
 
PPTX
oop unit1.pptx
sureshkumara29
 
PDF
Learning Java Beginning programming with java for dummies First Edition John ...
dionegorra0l
 
PDF
Top 10 Important Core Java Interview questions and answers.pdf
Umesh Kumar
 
ODP
Introduction To Java.
Tushar Chauhan
 
PPTX
CS8392 OOP
DhanalakshmiVelusamy1
 
Introduction to java (revised)
Sujit Majety
 
java notes.pdf
JitendraYadav351971
 
Java training materials for computer engineering.pdf
SkvKirupasri
 
introduction to object orinted programming through java
Parameshwar Maddela
 
PJ_M01_C01_PPT_Introduction to Object Oriented Programming Using Java.pdf
projectfora2
 
UNIT 1.pptx
EduclentMegasoftel
 
Java UNITbgbgbfdbv v bbfbf cvbgfbvc gf 1.pptx
hofon47654
 
object oriented programming unit one ppt
isiagnel2
 
Basics-Of-Java
ssuser200038
 
Mpl 1
AHHAAH
 
j-chap1-Basics.ppt
SmitaBorkar9
 
Knowledge of Javascript
Samuel Abraham
 
Module--fundamentals and operators in java1.pptx
Radhika Venkatesh
 
Unit1 introduction to Java
DevaKumari Vijay
 
oop unit1.pptx
sureshkumara29
 
Learning Java Beginning programming with java for dummies First Edition John ...
dionegorra0l
 
Top 10 Important Core Java Interview questions and answers.pdf
Umesh Kumar
 
Introduction To Java.
Tushar Chauhan
 
Ad

More from i i (15)

DOCX
Bouncing circle
i i
 
DOCX
0-1 KNAPSACK PROBLEM
i i
 
DOCX
sequential and combinational circuits exam
i i
 
PPTX
hypothesis testing overview
i i
 
PPTX
x86 architecture
i i
 
PDF
boolean algebra exercises
i i
 
PPTX
database normalization case study
i i
 
DOC
cpbricks context diagram
i i
 
DOC
cpbricks project document
i i
 
DOC
cpbricks manual
i i
 
PPTX
shortest job first
i i
 
PPTX
designing reports
i i
 
DOCX
bnf of c switch statement
i i
 
PPTX
shell and merge sort
i i
 
PPTX
adders/subtractors, multiplexers, intro to ISA
i i
 
Bouncing circle
i i
 
0-1 KNAPSACK PROBLEM
i i
 
sequential and combinational circuits exam
i i
 
hypothesis testing overview
i i
 
x86 architecture
i i
 
boolean algebra exercises
i i
 
database normalization case study
i i
 
cpbricks context diagram
i i
 
cpbricks project document
i i
 
cpbricks manual
i i
 
shortest job first
i i
 
designing reports
i i
 
bnf of c switch statement
i i
 
shell and merge sort
i i
 
adders/subtractors, multiplexers, intro to ISA
i i
 
Ad

Recently uploaded (20)

PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
Letasoft Sound Booster 1.12.0.538 Crack Download+ Product Key [Latest]
HyperPc soft
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Import Data Form Excel to Tally Services
Tally xperts
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Letasoft Sound Booster 1.12.0.538 Crack Download+ Product Key [Latest]
HyperPc soft
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 

imperative programming language, java, android

  • 2. IPL Paradigm Closely resemble the architectural structure of actual computer Based on manipulating bits and values and machine states. Features Use of abstract programming units like procedures and functions to encapsulate sequence Statements which are executed in succession. The way sequence of statements is executed is abstracted through a program or instruction counter, which executes the series of instructions stored in memory. Flow of execution can be manipulated or modified using conditional or looping statements by abstracting the underlying branch instructions within the machine instruction set. Usage of actual memory storage of the machine is abstracted through the use of variables and using assignment statements to assign values to the variables. Examples of IPL FORTRAN, Algol, COBOL, Pascal, C/C++, BASIC, Ada, Java, PHP, C# and many more.
  • 3. The Von Neumann Architecture ALU CU MEMORY CPU Instruction Set Architecture (ISA) - Actual CPU instructions visible for the programmers can use -They form the boundary between hardware and software -Dimensions of ISA: Class, Memory Addressing, Address Modes, Operand types and sizes, Operations, control flow instructions, encoding (fixed-length or variable)
  • 4. IPL Characteristics Variables and Storage Commands: Assignments -Simple assignment : x = y + 1; -Multiple assignments: v1 = v2 = v3 = v4 = 200; -Simultaneous assignment: n1, n2, n3, n4 = m1, m2, m3, m4 -Operator-assignment : m += n Procedure Calls Sequential commands -Control flow mechanism for executing commands in specific order, Given C1; C2; C2 is executed after C1 is done Collateral commands Set of nondeterministic commands, where commands are executed in no particular order. Conditional commands -Given a set of subcommands, one is executed if a certain condition is met. - Example: if-then and switch statements Iterative commands -Repeats execution of commands based on defined conditions. -Uses control variables -Example: for and while statements
  • 5. IPL Side effects Sequential execution can cause side-effects such as values of global variables are changed inside procedure calls, which may make the program unreadable because some parts of the program depend on what happens inside other parts.
  • 8. What is Java? A general purpose, imperative, strongly-typed high-level, purely OOP language Language by programmers for programmers. Java Design Platform-independent or architectural-neutral Let developers create "write once, run anywhere“ applications Origins Created by James Gosling, Patrick Naughton, Chris Warth, Ed Frank, and Mike Sheridan in 1991 while at Sun Microsystems. Initially called “Oak,” but was renamed “Java” in 1995. Originally intended for embedded systems in consumer electronics, but eventually found popularity in use for the world wide Java remains a de facto standard, controlled through the Java Community Process. 9 million developers. Java today
  • 9. Java Platform • Java Card for smartcards. • Java Platform, Micro Edition (Java ME) – targeting environments with limited resources. • Java Platform, Standard Edition (Java SE) – targeting workstation environments. • Java Platform, Enterprise Edition (Java EE) – targeting large distributed enterprise or Internet environments. Java development tools Eclipse Netbeans Java Runtime Environment (JRE) JVM, class libraries, and launcher Java Development Kit (JDK) Environment for building applications, applets, and components. Includes tools for developing and testing and running Java programs. Java resources Java Native Interface (JNI) Enables programmers to write native methods The JNI framework lets a native method use Java objects
  • 10. Java compilation Source code Java compiler Byte code JVM (Architecture- specific)
  • 11. Target Instruction Set C++: Compiles to a low-level instruction set that operates on raw binary data and is specific to the target hardware, such as x86, ARM, or PowerPC. Java: Compiles to a higher-level portable bytecode that operates on typed values: objects, primitive types, and arrays thereof. Compiler Optimizations C++: Numerous code optimizations are performed at compile time. Inline substitution results in copies of the given (member) function being scattered around the binary image; use of the preprocessor combined with compile-time evaluation of expressions may leave no trace of the constants defined in the source code; and so on. Java: Relies on dynamic (Just-In-Time) compilation for performance improvement. The standard javac compiler is straightforward, it does no compile time optimizations commonly found in C++ compilers. The idea is to enable the JIT compiler to perform all optimizations at run time, taking the execution profile into account. Linkage C++: Programs are statically linked, and metaprogramming facilities (reflection) are absent in the core language. So the names of classes, members, and variables need not be present in the compiled and linked program, except for names exported from dynamic libraries (DLLs/shared objects.) Java: Dependencies are resolved at run time, when classes are loaded. So the name of the class and names of its methods and fields must be present in a class file, as well as names of all imported classes, called methods, and accessed fields. Delivery Format C++: An application is delivered as a monolithic executable (maybe with a few dynamic libraries), so it is not easy to identify all member functions of a given class or reconstruct the class hierarchy. Java: An application is typically delivered as a set of jar files, which are just non-encrypted archives containing individual class files. Java vs. C/C++ Compilation
  • 13. abstract assert boolean break byte case catch char class Java language const continue default do double else enum extends final finally Float for goto if implements import instanceof int interface long native new package private protected public return short static strictfp super switch synchronized this throw throws transient try void volatile while Java primitive data types Integers (byte, short, int long) Floating point (float, double) Others (char, boolean, arrays) Java operators Arithmetic: + * / % ++ += -= *= *= /= %= -- Bitwise : ~ & | ^ >> >>> << &= |= ^= >>= >>>= <<= Relational : == != > < >= <= Logical: && ! || != ?: Java Arrays type var-name[ ]; array-var = new type [size]; Java separators “()” , “[]”, “{}”, “;” , “,” , “.”
  • 14. Java control statements if-else-statement if (condition) statement1; else statement2; if(condition) statement; else if(condition) statement; else if(condition) statement; ... else statement; switch statement switch (expression) { case <value1>: statement-list break; … default: statement-list } while(condition) { // body of loop } while statement do-while statement do { // body of loop } while (condition); for statement for(initialization; condition; iteration) { // body }
  • 15. Polymorphism Methods can share the same name as long as their parameter declarations are different. Java object-oriented paradigm Encapsulation Links data with the code that manipulates it. Access modifers are public, private, and protected (affects inheritance). Public : member can be accessed by any other code Private: member can only be accessed by other members of its class. Inheritance class subclass-name extends superclass-name { // body of class } A class member that has been declared as private will remain private to its class. It is not accessible by any code outside its class, including subclasses.
  • 16. Superclass Whenever a subclass needs to refer to its immediate superclass, it can do so by use of the keyword super. super has two general forms. The first calls the superclass’ constructor. The second is used to access a member of the superclass that has been hidden by a member of a subclass this keyword this can be used inside any method to refer to the current object. It is always a reference to the object on which the method was invoked. Java object-oriented paradigm A static member be accessed before any objects of its class are created, and without reference to any object. Both methods and variables can be declared as static. Static keyword Automatically handles the deallocation of objects. Garbage Collection
  • 17. Java exceptions An exception is an object that describes an exceptional (that is, error) condition that has occurred in a piece of code. Exceptions thrown by Java relate to fundamental errors that violate the rules of the Java language or the constraints of the Java execution environment. Manually generated exceptions are typically used to report some error condition to the caller of a method. Exception Handling try { // block of code to monitor for errors } catch (ExceptionType execeptionObject) { //exception handler } ... finally { //final block of code to be executed at the end }
  • 18. Java classes and objects class classname { variable declarations ... method declarations ... } class definition Object declaration classname varname = new classname(); type name(parameter-list) { // body of method } Method declaration
  • 19. Java program units Package – used to partition class name space into smaller chunks Class – fundamental code units in java; consists of functions and variables. Function – encapsulates 1 or more statements; may also contain local variables Statement blocks – consists of one or more java statements enclosed in curly brackets Bindings Identifiers – Static Type – static Address – Dynamic Value – Dynamic Storage – Objects are dynamically allocated Local variable storage lasts until the method returns.
  • 20. Package Scope Rules Private No Modifier Protected Public Same class Yes Yes Yes Yes Same package subclass No Yes Yes Yes Same package, non subclass NO Yes Yes Yes Different package, subclass No No Yes Yes Different package, non subclass No No No Yes
  • 21. Class Scope Rules All members of a class are visible to any part of the class (depends if the static keyword Is used on some members, which affects scope visibility) Local variables within methods is only visible within the method. Variables declared within blocks is only visible within the block.
  • 22. Multithreading In a thread-based multitasking environment, the thread is the smallest unit of dispatchable code. This means that a single program can perform two or more tasks simultaneously Creating a Thread In the most general sense, you create a thread by instantiating an object of type Thread. Java denotes two ways in which this can be accomplished: • You can implement the Runnable interface. • You can extend the Thread class, itself.
  • 23. class NewThread implements Runnable { Thread t; NewThread() { t = new Thread(this,"Demo thread"); System.out.println("child thread: " + t); t.start(); } public void run() { try { //some statements here Thread.sleep(500); } catch(Exception e) { System.out.println("Exiting child thread."); } } } class ThreadDemo{ public static void main(String []args) { new NewThread(); // main thread statements } } Example using Runnable :
  • 24. class NewThread extends Thread{ NewThread(){ System.out.println("Child thread: " + this); start(); } public void run(){ // thread statements Thread.sleep(500); } } class ExtendThread{ public static void main(String [] args){ new NewThread(); //main thread statement Thread.sleep(1000); } } Example by extending Thread:
  • 27. Android the OS Android is a mobile operating system developed by Google, based on the Linux kernel and designed primarily for mobile devices such as smartphones and tablets. Android, Inc. was by Andy Rubin in 2003 (Acquired by Google in 2005) On the Open Handset Alliance, a consortium of technology companies including Google, device manufacturers such as HTC, Sony and Samsung, wireless carriers such as Sprint Nextel and T-Mobile, and chipset makers such as Qualcomm and Texas Instruments, unveiled itself, with a goal to develop open standards for mobile devices.
  • 28. Dalvik is a process virtual machine (VM) that executes Android applications (Android 4.4 and earlier). Dalvik is open-source software, originally written by Dan Bornstein, who named it after the fishing village of Dalvík in Eyjafjörður, Iceland. Android Runtime Environment Android Runtime (ART) is an application runtime environment replacing Dalvik ART performs the translation of the application's bytecode into native instructions that are later executed by the device's runtime environment.
  • 30. Android SDK For developing applications for the Android operating system. Applications are usually developed in Java programming language using the Android software development kit (SDK), but other development environments are also available. Linux, Mac OS X, and Windows are supported platforms. Officially supported integrated development environments (IDE) are Eclipse using the Android Development Tools (ADT) Plugin, NetBeans IDE, and Android Studio, made by Google and powered by IntelliJ. Developers may use any text editor to edit Java and XML files, then use command line tools (Java Development Kit and Apache Ant are required) to create, build and debug Android applications as well as control attached Android devices. The SDK includes a debugger, libraries, a handset emulator based on QEMU, documentation, sample code, and tutorials. Android Development Platform
  • 31. Android ADB A command line tool that for communicating with an emulator or Android-powered device. Support native development in C/C++. Android Native Development Kit (NDK) Extensions for IDEs to support android development, such as Eclipse. Android Development Toolkit (ADT) Android Development Platform Android SDK Manager Manages download or updating of SDK packages and tools.
  • 33. Android Application Build Process Java source Java Compiler Java class (byte code) Dx ToolDex file APK BuilderJar signer APK file Library resources