Java/J2EE Programming Training
Introduction to Java
Page 2Classification: Restricted
Agenda
• Understand the advantages of Java
• Understand where Java is used
• Understand how memory management is handled in Java
• Create a Java project in Eclipse and execute it
• Implement if..else construct in Java
• Develop codes using various data types in Java
• Implement various loops
Page 3Classification: Restricted
Meet John
• Mike is a student of Computer Science in
California University.
Page 4Classification: Restricted
John learns about Programming Languages
Page 5Classification: Restricted
John is Confused
Page 6Classification: Restricted
John gets a Bookish Answer
Page 7Classification: Restricted
John is Still Confused
Page 8Classification: Restricted
John heads home with a doub’t
Page 9Classification: Restricted
John meets his Brother
Page 10Classification: Restricted
John expresses his concerns
Page 11Classification: Restricted
John gets an Answer!
Page 12Classification: Restricted
John wants to know more..
Page 13Classification: Restricted
John gets help!
Page 14Classification: Restricted
Use of Java-1
Page 15Classification: Restricted
Use of Java - 2
Page 16Classification: Restricted
Use of Java - 3
1
6
Page 17Classification: Restricted
John is convinced to learn Java
1
7
Page 18Classification: Restricted
A Gift for John
1
8
Page 19Classification: Restricted
An Android Phone
1
9
Page 20Classification: Restricted
John is all set to learn Java
2
0
Page 21Classification: Restricted
What is Java?
• Java is a computer programming language that is
• Concurrent
• class-based
• object-oriented
• specifically designed to have as few implementation dependencies as
possible.
2
1
Page 22Classification: Restricted
Where is Java Used?
• Java is used in various enterprise level application/frameworks all around the
world.
• Java is used:
– In over 850 million PCs as Java Runtime Environment
– To develop Android Applications
– To develop Hadoop Applications
– To develop business process management(BPM) tools.
– To develop webservers,application servers, etc.
• Java has been used to develop below frameworks:
– Hadoop
– Spring
– Hibernate
– Struts
2
2
Page 23Classification: Restricted
Java –Job, Demand and Experience Trends
2
3
Page 24Classification: Restricted
Languages before Java
• Before Java emerged as a programming language, there were many other
programming languages:
– C
– C++ (the dominant player in the trade)
– Visual Basics
– Python
• The primary goal was to replace C++:
– C++ does not provide efficient means for garbage collection
– No built in support for threads
– It gets complex when u want to develop a graphics richapplication
– C++ is not platform independent
– In C++ memory allocation and de-allocation has to be done by the
developer
2
4
Page 25Classification: Restricted
History of Java
• Java was developed by James
Gosling in Sun Microsystems.
• It is a platform independent
programming language.
• This language was initially
named as OAK and later
renamed as JAVA.
2
5
Page 26Classification: Restricted
JavaVersions
2
6
Features of Java
2
7
Page 28Classification: Restricted
Features of JAVA
Page 29Classification: Restricted
C++ : Platform Dependent
2
9
Page 30Classification: Restricted
Java : Platform Independent
3
0
Page 31Classification: Restricted
Features of Java
3
1
Page 32Classification: Restricted
Features of JAVA
3
2
Page 33Classification: Restricted
Features of JAVA
3
3
Page 34Classification: Restricted
Features of JAVA
3
4
Page 35Classification: Restricted
Features of JAVA
3
5
Page 36Classification: Restricted
Features of JAVA
3
6
Page 37Classification: Restricted
Features of JAVA
3
Page 38Classification: Restricted
Features of JAVA
3
8
Page 39Classification: Restricted
Features of Java
3
9
Page 40Classification: Restricted
Questions
4
0
What is byte code?
Page 41Classification: Restricted
Answer
4
1
Bytecode is an intermediate code which gets generated when a Java file is
compiled using a Javac compiler. After compilation .class file is generated
which contains the byte code. This code is platform independent.
Page 42Classification: Restricted
Question
4
2
What is the advantage of executing parallel
threads/tasks at a time?
Page 43Classification: Restricted
Answer
4
3
When many tasks/threads run at the same time, performance of the system
increases.
Page 44Classification: Restricted
Bytecode and Java Virtual Machine (JVM)
• Java bytecode is the form of instructions that the Java Virtual Machine
executes.
• AJavaprogrammer need not understand bytecode at all.
• Java Virtual Machine (JVM)
– Runs the bytecode
– Makes Java platform independent
– Handles memory management
4
4
Page 45Classification: Restricted
Java Memory Management
• C/C++ has pointers. User can
allocate memory to these
pointers.
• If the pointer is accessed
without allocating memory or
invalid pointer is accessed then
program crashes.
• These issues are removed from
Java as Java does not have
pointers. Complete memory
management ishandled by Java
itself.
4
5
Page 46Classification: Restricted
Heap and Garbage Collector
• The memory area in JVM where objects are created is called Heap.
• Heap is divided into two parts. Young space and old space.
• The memory is freed during runtime by a special thread called Garbage
Collector.
• The Garbage Collector looks for objects which are no longer needed by
the program and destroysthem.
• All the newly allocated objects are created in young space. Once the
young space is full then garbage collector is called so that memory can
be released.
• If the object has lived for long in young space then they will be moved to
old space. Once the old space is full, garbage collector is called to
release the space in heap.
4
6
Page 47Classification: Restricted
Heap In side JVM
4
7
Page 48Classification: Restricted
Inside Heap
4
8
Page 49Classification: Restricted
Objects and References
4
9
Page 50Classification: Restricted
Garbage Collector
5
0
Page 51Classification: Restricted
How Java Works?
5
1
Page 52Classification: Restricted
Data Types
5
2
Page 53Classification: Restricted
Question
5
3
Why do you think we need byte, short and long datatypes when
int can be used?
Page 54Classification: Restricted
Answer
5
4
‘byte’ takes 1 byte, ‘short’ takes 2 bytes and ‘int’ takes 4 bytes in
memory. If we know that the variable need not be very big then
‘short’ is fine as it reduces the memory consumption which inturn
increases the performance of the project.
Page 55Classification: Restricted
Data Operations
5
5
Page 56Classification: Restricted
Required Software
• Required software for Java Programming
– »JDK 1.7 64 bit or 32 bit according to your machine.
• http://www.oracle.com/technetwork/java/javase/downloads/jd
k7-downloads-1880260.html
5
6
Page 57Classification: Restricted
Required Software
• Required software for Java Programming
– Eclipse J2EE version for 64 bit or 32 bit
according to your machine.
• https://www.eclipse.org/downloads/
5
7
Page 58Classification: Restricted
Select a workspace
5
Page 59Classification: Restricted
Create a Project
5
9
Page 60Classification: Restricted
Create Class
6
Page 61Classification: Restricted
My First Program
6
1
Page 62Classification: Restricted
Execute Java Program
6
2
Page 63Classification: Restricted
Main Method
6
3
Page 64Classification: Restricted
Programs for Data Types and Operations
6
4
Page 65Classification: Restricted
Choices in Real Life
6
5
Page 66Classification: Restricted
If..else Condition
6
6
Page 67Classification: Restricted
‘if’ Conditions
6
7
Page 68Classification: Restricted
If..else in Java
6
8
Page 69Classification: Restricted
if else in Java (Contd..)
6
9
Page 70Classification: Restricted
Program on if condition
7
0
Page 71Classification: Restricted
Repetitive task in Real Life
7
1
Page 72Classification: Restricted
Repetitive Tasks in Real life (contd..)
7
2
Page 73Classification: Restricted
Loops
7
Page 74Classification: Restricted
Question
7
4
What could be the advantage of using loops?
Page 75Classification: Restricted
Answer
7
5
The advantage of using loops is that, we can reduce code
repetition by placing the statements to be repeated within a loop.
As a result developer's effort will be very less.
Page 76Classification: Restricted
for…Loop
7
6
Page 77Classification: Restricted
for…Loop Program
7
7
Page 78Classification: Restricted
while… Loop
7
8
Page 79Classification: Restricted
while…Loop Program
7
9
Page 80Classification: Restricted
do…while Loop
8
Page 81Classification: Restricted
while ..Loop Program
8
1
Page 82Classification: Restricted
Assignment – Data Type and Operation
8
2
Page 83Classification: Restricted
Assignment if..Condition
8
3
Page 84Classification: Restricted
Assignment for…Loop
8
4
Page 85Classification: Restricted
Assignment – while…loop
8
5
Page 86Classification: Restricted
Assignment do..while Loop
8
6
Page 87Classification: Restricted
Pre-work
8
7
Page 88Classification: Restricted
Thank You

Introduction to Java