0% found this document useful (0 votes)
3 views32 pages

Introduction to Java Programming Basics

The document provides an introduction to Java, covering its design goals, features, and the Java Development Kit (JDK), Java Runtime Environment (JRE), and Java Virtual Machine (JVM). It details the history of Java, its version history, and the concept of garbage collection for memory management. The document aims to equip candidates with a foundational understanding of Java programming and its components within a 4-hour session.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views32 pages

Introduction to Java Programming Basics

The document provides an introduction to Java, covering its design goals, features, and the Java Development Kit (JDK), Java Runtime Environment (JRE), and Java Virtual Machine (JVM). It details the history of Java, its version history, and the concept of garbage collection for memory management. The document aims to equip candidates with a foundational understanding of Java programming and its components within a 4-hour session.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

making intelligent automation

accessible to every enterprise

Introduction to Java
Introduction to Java
Objectives

At the end of this session, the candidates will be able to understand

1. Design Goals of Java


2. Features of java
3. JDK, JRE and JVM
4. Garbage Collection

Duration: 4 Hours
Design Goals of Java
Why Java?

The answer is that Java enables users to develop and deploy


applications on the Internet for servers, desktop computers, and
small hand-held devices. The future of computing is being profoundly
influenced by the Internet, and Java promises to remain a big part of
that future.

 Java is a general purpose programming language.


 Java is an internet programming language.
Design Goals of Java
What is Java?
Java is a programming language and a platform. Java is a high level, robust,
object-oriented and secure programming language.

Java was developed by Sun Microsystems (which is now the subsidiary of


Oracle) in the year 1995. James Gosling is known as the father of Java. Before
Java, its name was Oak. Since Oak was already a registered company, so
James Gosling and his team changed the name from Oak to Java.

Platform: Any hardware or software environment in which a program runs, is


known as a platform. Since Java has a runtime environment (JRE) and API, it is
called a platform.
Design Goals of Java
History of Java?
Java is a programming language and a platform. Java is a high
level, robust, object-oriented and secure programming language.

Java was developed by Sun Microsystems (which is now the


subsidiary of Oracle) in the year 1995. James Gosling is known as
the father of Java. Before Java, its name was Oak. Since Oak was
already a registered company, so James Gosling and his team
changed the name from Oak to Java. Currently, Java is used in
internet programming, mobile devices, games, e-business solutions,
etc.
Design Goals of Java
Java Version History
Many java versions have been released till now. The current stable
release of Java is Java SE 10.
1. JDK Alpha and Beta (1995) 11. Java SE 9 (21st Sep 2017)
2. JDK 1.0 (23rd Jan 1996) 12. Java SE 10 (20th Mar 2018)
3. JDK 1.1 (19th Feb 1997) 13. Java SE 11 (September 2018)
4. J2SE 1.2 (8th Dec 1998) 14. Java SE 12 (March 2019)
5. J2SE 1.3 (8th May 2000) 15. Java SE 13 (September 2019)
6. J2SE 1.4 (6th Feb 2002) 16. Java SE 14 (Mar 2020)
7. J2SE 5.0 (30th Sep 2004) 17. Java SE 15 (September 2020)
8. Java SE 6 (11th Dec 2006) 18. Java SE 16 (Mar 2021)
9. Java SE 7 (28th July 2011) 19. Java SE 17 (September 2021)
10. Java SE 8 (18th Mar 2014) 20. Java SE 18 (March 2022)
Features of Java

The primary objective of Java programming language creation was to make


it portable, simple and secure programming language. Apart from this, there
are also some excellent features which play an important role in the
popularity of this language. The features of Java are also known as Java
buzzwords.
Features of Java
Java Is Simple Java is partially modeled on C++, but
greatly simplified and improved. Some
Java Is Object-Oriented people refer to Java as "C++--" because it
Java Is Distributed is like C++ but with more functionality and
fewer negative aspects.
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic
Features of Java
Java is inherently object-oriented.
Java Is Simple Although many object-oriented languages
Java Is Object-Oriented began strictly as procedural languages,
Java was designed from the start to be
Java Is Distributed object-oriented. Object-oriented
Java Is Interpreted programming (OOP) is a popular
programming approach that is replacing
Java Is Robust traditional procedural programming
Java Is Secure techniques.
Java Is Architecture-Neutral
One of the central issues in software
Java Is Portable development is how to reuse code.
Java's Performance Object-oriented programming provides
great flexibility, modularity, clarity, and
Java Is Multithreaded reusability through encapsulation,
Java Is Dynamic inheritance, and polymorphism.
Features of Java
Java Is Simple Distributed computing involves several
computers working together on a network.
Java Is Object-Oriented Java is designed to make distributed
Java Is Distributed computing easy. Since networking
capability is inherently integrated into
Java Is Interpreted Java, writing network programs is like
Java Is Robust sending and receiving data to and from a
Java Is Secure file..

Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic
Features of Java
Java Is Simple You need an interpreter to run Java
programs. The programs are compiled
Java Is Object-Oriented into the Java Virtual Machine code called
Java Is Distributed bytecode. The bytecode is machine-
independent and can run on any machine
Java Is Interpreted that has a Java interpreter, which is part
Java Is Robust of the Java Virtual Machine (JVM).
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic
Features of Java
Java Is Simple Java compilers can detect many problems
that would first show up at execution time
Java Is Object-Oriented in other languages.
Java Is Distributed
Java has eliminated certain types of error-
Java Is Interpreted prone programming constructs found in
Java Is Robust other languages.
Java Is Secure
Java has a runtime exception-handling
Java Is Architecture-Neutral feature to provide programming support
Java Is Portable for robustness.
Java's Performance
Java Is Multithreaded
Java Is Dynamic
Features of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java implements several security
Java Is Robust mechanisms to protect your system
Java Is Secure against harm caused by stray programs.
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic
Features of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Architecture-Neutral Write once, run anywhere
Java Is Portable With a Java Virtual Machine (JVM), you
Java's Performance can write one program that will run on any
Java Is Multithreaded platform.

Java Is Dynamic
Features of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Architecture-Neutral
Because Java is architecture neutral,
Java Is Portable Java programs are portable. They can be
Java's Performance run on any platform without being
Java Is Multithreaded recompiled.

Java Is Dynamic
Features of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Architecture-Neutral
Java is faster than other traditional
Java Is Portable interpreted programming languages
Java’s Performance because Java bytecode is "close" to
native code. It is still a little bit slower than
Java Is Multithreaded a compiled language (e.g., C++). Java is
Java Is Dynamic an interpreted language that is why it is
slower than compiled languages, e.g., C,
C++, etc.
Features of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java's Performance Multithread programming is smoothly
integrated in Java, whereas in other
Java Is Multithreaded languages you have to call procedures
Java Is Dynamic specific to the operating system to enable
multithreading.
Features of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Architecture-Neutral
Java was designed to adapt to an
Java Is Portable evolving environment. New code can be
Java's Performance loaded on the fly without recompilation.
Java Is Multithreaded There is no need for developers to create,
and for users to install, major new
Java Is Dynamic software versions. New features can be
incorporated transparently as needed.
JDK, JRE and JVM
JVM

JVM (Java Virtual Machine) is an abstract machine. It is called a virtual


machine because it doesn't physically exist. It is a specification that provides
a runtime environment in which Java bytecode can be executed. It can also
run those programs which are written in other languages and compiled to
Java bytecode.

JVMs are available for many hardware and software platforms. JVM, JRE,
and JDK are platform dependent because the configuration of each OS is
different from each other. However, Java is platform independent. There are
three notions of the JVM: specification, implementation, and instance.
JVM
What is JVM
It is:

1. A specification where working of Java Virtual Machine is specified. But


implementation provider is independent to choose the algorithm. Its
implementation has been provided by Oracle and other companies.

2. An implementation: Its implementation is known as JRE (Java Runtime


Environment).

3. Runtime Instance: Whenever you write java command on the command


prompt to run the java class, an instance of JVM is created.
JVM
What it does
The JVM performs following operation:
• Loads code
• Verifies code
• Executes code
• Provides runtime environment

JVM provides definitions for the:


• Memory area
• Class file format
• Register set
• Garbage-collected heap
• Fatal error reporting etc.
JVM
JVM Architecture

Let's understand the internal architecture of JVM. It contains classloader,


memory area, execution engine etc..
JVM - Architecture
1. Classloader
Classloader is a subsystem of JVM which is used to load class
files. Whenever we run the java program, it is loaded first by the
classloader. There are three built-in classloaders in Java.
a. Bootstrap ClassLoader: This is the first classloader which
is the super class of Extension classloader. It loads
the [Link] file which contains all class files of Java Standard
Edition like [Link] package classes, [Link] package
classes, [Link] package classes, [Link] package classes,
[Link] package classes etc.
b. Extension ClassLoader: This is the child classloader of
Bootstrap and parent classloader of System classloader. It
loades the jar files located
inside $JAVA_HOME/jre/lib/ext directory.
c. System/Application ClassLoader: This is the child
classloader of Extension classloader. It loads the classfiles
from classpath. By default, classpath is set to current
directory. You can change the classpath using "-cp" or "-
classpath" switch. It is also known as Application
classloader.
JVM - Architecture
2. Class(Method) Area: Class(Method) Area
stores per-class structures such as the runtime
constant pool, field and method data, the code for
methods.

3. Heap: It is the runtime data area in which


objects are allocated.

4. Stack: Java Stack stores frames. It holds local


variables and partial results, and plays a part in
method invocation and return.
Each thread has a private JVM stack, created at the same
time as thread.
A new frame is created each time a method is invoked. A
frame is destroyed when its method invocation completes.

5. Program Counter Register: PC (program counter)


register contains the address of the Java virtual machine
instruction currently being executed.
6. Native Method Stack: It contains all the native
methods used in the application.
JVM - Architecture
6. Native Method Stack: It contains all the native
methods used in the application.

7. Execution Engine: It contains:


a. A virtual processor
b. Interpreter: Read bytecode stream then execute the
instructions.
c. Just-In-Time(JIT) compiler: It is used to improve the
performance. JIT compiles parts of the byte code that
have similar functionality at the same time, and hence
reduces the amount of time needed for compilation.
Here, the term "compiler" refers to a translator from the
instruction set of a Java virtual machine (JVM) to the
instruction set of a specific CPU.

8. Java Native Interface: Java Native Interface (JNI) is a


framework which provides an interface to communicate
with another application written in another language like C,
C++, Assembly etc. Java uses JNI framework to send
output to the Console or interact with OS libraries.
JRE
JRE is an acronym for Java Runtime Environment. It is
also written as Java RTE. The Java Runtime Environment
is a set of software tools which are used for developing
Java applications. It is used to provide the runtime
environment. It is the implementation of JVM. It physically
exists. It contains a set of libraries + other files that JVM
uses at runtime.

The implementation of JVM is also actively released by


other companies besides Sun Micro Systems.
JDK
JDK is an acronym for Java Development Kit. The Java
Development Kit (JDK) is a software development
environment which is used to develop Java applications
and applets. It physically exists. It contains JRE +
development tools.

JDK is an implementation of any one of the below given


Java Platforms released by Oracle Corporation:
• Standard Edition Java Platform
• Enterprise Edition Java Platform
• Micro Edition Java Platform

The JDK contains a private Java Virtual Machine (JVM)


and a few other resources such as an interpreter/loader
(java), a compiler (javac), an archiver (jar), a
documentation generator (Javadoc), etc. to complete the
development of a Java Application.

Note: Read about Components of JDK


Garbage Collection
In java, garbage means unreferenced objects.

Garbage Collection is the process of reclaiming the runtime unused memory


automatically. In other words, it is a way to destroy the unused objects.

To do so, we were using free() function in C language and delete() in C++. But, in
java it is performed automatically. So, java provides better memory management.

Advantage of Garbage Collection


• It makes java memory efficient because garbage collector removes the
unreferenced objects from heap memory.

• It is automatically done by the garbage collector(a part of JVM) so we don't


need to make extra efforts.
Garbage Collection
How can an object be unreferenced?
There are many ways:
• By nulling the reference
• By assigning a reference to another
• By anonymous object etc.

1. By nulling a reference: 3. By anonymous object:


Employee e=new Employee(); new Employee();
e=null;

2. By assigning a reference to another:


Employee e1=new Employee();
Employee e2=new Employee();
e1=e2; //now the first object referred by e1 is available for garbage collection
Garbage Collection
finalize() method
The finalize() method is invoked each time before the object is garbage collected.
This method can be used to perform cleanup processing. This method is defined in
Object class as: Note: The Garbage collector of JVM collects only those
protected void finalize(){} objects that are created by new keyword. So if you have
created any object without new, you can use finalize method to
perform cleanup processing (destroying remaining objects).

gc() method
The gc() method is used to invoke the garbage collector to perform cleanup
processing. The gc() is found in System and Runtime classes.
public static void gc(){} Note: Garbage collection is performed by a daemon
thread called Garbage Collector(GC). This thread calls the
finalize() method before object is garbage collected.
Garbage Collection
Simple Example of garbage collection in java

public class TestGarbage1{


public void finalize(){
[Link]("object is garbage collected");
} Expected output:

object is garbage collected


public static void main(String args[]){ object is garbage collected
TestGarbage1 s1=new TestGarbage1();
TestGarbage1 s2=new TestGarbage1();
s1=null;
s2=null; Note:
[Link](); Neither finalization nor garbage
} collection is guaranteed.
}
Thank You

32

You might also like