SlideShare a Scribd company logo
1 of 25
Download to read offline
Introduction to Java
Lecture 3
Naveen Kumar
Characteristics 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
 Java Is Multithreaded
 Java Is Dynamic
2 www.cs.armstrong.edu/liang/intro6e/JavaCharacteristics.pdf
Characteristics 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
 Java Is Multithreaded
 Java Is Dynamic
3
Java is partially modeled on C++, but
greatly simplified and improved. It is like
C++ but with more functionality and fewer
negative aspects
Characteristics 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
 Java Is Multithreaded
 Java Is Dynamic
4
Java is inherently object-oriented. Java
was designed from the start to be
object-oriented.
One of the central issues in software
development is how to reuse code.
Object-oriented programming provides
great flexibility, modularity, clarity, and
reusability through encapsulation,
inheritance, and polymorphism.
Characteristics 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
 Java Is Multithreaded
 Java Is Dynamic
5
Distributed computing involves several
computers working together on a
network.
Java is designed to make distributed
computing (e.g. Web Services) easy.
Since networking capability is
inherently integrated into Java, writing
network programs is like sending and
receiving data to and from a file
Characteristics 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
 Java Is Multithreaded
 Java Is Dynamic
6
You need an interpreter to run Java
programs.
The programs are compiled into
bytecode. The bytecode is machine-
independent and can run on any
machine that has a Java interpreter,
which is part of the JVM
Characteristics 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
 Java Is Multithreaded
 Java Is Dynamic
7
Java compiler can detect many
problems that would first show up at
execution time in other languages
Java has eliminated certain types of
error-prone programming constructs
found in other languages (default
value, memory leak)
Java has a runtime exception-handling
feature to provide programming
support for robustness
Characteristics 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
 Java Is Multithreaded
 Java Is Dynamic
8
Java implements several security
mechanisms to protect your system
•enforce array bound check(buffer overflow)
•not allow to perform unsafe operations such
as pointer arithmetic or unchecked type casts
•not allow manual control over memory
allocation and deallocation; users rely on
automatic garbage collection
•Java Library provides APIs related to
security, such as standard cryptographic
algo’s, Auth., and secure comm protocols.
•Exception handling
•Ensure that no viruses are communicated
with an applet
Characteristics 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
 Java Is Multithreaded
 Java Is Dynamic
9
Write once, run anywhere
With a Java Virtual Machine (JVM),
you can write one program that will
run on any platform
Characteristics 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
 Java Is Multithreaded
 Java Is Dynamic
10
The execution of byte code by the JVM
makes java programs portable
Because Java is architecture neutral,
Java programs are portable. They can
be run on any platform without being
recompiled
Characteristics 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
 Java Is Multithreaded
 Java Is Dynamic
11
Because Java is architecture neutral,
Java programs are portable. They can
be run on any platform without being
recompiled
•Java performance is slower than C
•Can sometimes be even faster than
compiled C code!
•Incorporation of multithreading enhance
the overall execution speed
•Just-in-Time (JIT) can compile the byte
code into machine code
JIT compiler turns Java bytecode into instructions that can be sent directly to a
particular hardware platform's processor.
Characteristics 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
 Java Is Multithreaded
 Java Is Dynamic
12
Multithread programming is smoothly
integrated in Java,
whereas in other languages you have to
call procedures specific to the operating
system to enable multithreading
Characteristics 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
 Java Is Multithreaded
 Java Is Dynamic
13
• Capable of dynamically linking a new class
libraries, methods and objects.
• Java can use efficient functions available in
C/C++.
• Installing new version of library
automatically updates all programs
 Java programs normally undergo five phases
– Edit
 Programmer writes program (and stores program on disk)
– Compile
 Compiler creates bytecodes from program
– Load
 Class loader stores bytecodes in primary memory
– Verify
 Verifier ensures bytecodes do not violate security requirements
– Execute
 Interpreter translates bytecodes into machine language
Basics of Java Environments
Primary
Memory
.
.
.
.
.
.
Disk
Disk
Disk
Editor
Compiler
Class Loader
Program is created in an
editor and stored on disk
in a file ending with
.java.
Compiler creates
bytecodes and stores
them on disk in a file
ending with .class.
Class loader reads
.class files
containing
bytecodes from disk
and puts those
bytecodes in
memory.
Phase 1
Phase 2
Phase 3
Primary
Memory
.
.
.
.
.
.
Bytecode Verifier Bytecode verifier
confirms that all
bytecodes are valid
and do not violate
Java’s security
restrictions.
Phase 4
Primary
Memory
.
.
.
.
.
.
Interpreter
Interpreter reads
bytecodes and
translates them into a
language that the
computer can
understand, possibly
storing data values as
the program executes.
Phase 5
 Development tools-part of java development kit (JDK)
 Classes and methods-part of Java Standard Library (JSL),
also known as Application Programming Interface (API)
1. JDK:
 Appletviewer ( for viewing applets)
 Javac (Compiler)
 Java (Interpreter)
 Javah (for C header files)
 Javadoc ( for creating HTML description)
Java Environment
2. Application Package Interface (API)
Contains hundreds of classes and methods grouped into several
functional packages:
 Language Support Package
 Utility Packages (rand. num. gen., sys. date mani.)
 Input/Output Packages
 Networking Packages (implementing networking app. )
 AWT Package (classes for painting graphics and images)
 Applet Package (web page using java)
Java Environment
1. Java 1.0 (96)
2. Java 1.1 (97)(Add new library, redefine applet handling and
reconfigured many features.)
3. Java 2 (98)(Second generation). Version no:1.2 (Internal
version number of java library). Also known as J2SE [ Java
2 Platform Standard Edition].
- Add swing, the collection framework, enhanced JVM etc.
4. J2SE 1.3 (2000)
5. J2SE 1.4 (2002)
6. J2SE 1.5 (2004)
7. J2SE 1.6 (2006) [1.7-(2011), in queue 1.8, 1.9]
The Evolution of Java
Comments
In Java, comments are preceded by two slashes (//) in a
line, or
enclosed between /* and */ in one or multiple lines
When the compiler sees //, it ignores all text after // in the
same line
When it sees /*, it scans for the next */ and ignores any text
between /* and */
Example
/* Traditional "Hello World!" program. */
// package pack1;
// import java.lang.System;
class a
{
public static void main (String args[])
{
System.out.println("Hello World!");
}
}
Save program as a.java
Java Program Structure
Package Statement
 Javac command compiles the source code a.java then,
generates a.class and store it under a directory which is
called as name of the package
 package statement if used must be the first statement in
a compilation unit. Its syntax is:
package packageName;
 For example:
package pack1;
Import Statement
 The import statements are similar to #include
statements in C and C++
 In the above program, System class of java.lang package
is imported into all Java programs by default. The
syntax of import statement is as:
import fullClassName;
 For example, the following import statement imports the
System class from java.lang:
import java.lang.System;
import java.lang.*;
Classes and Methods
 Class declarations contain a keyword class and an identifier
 Class members are enclosed within braces. The syntax of defining a
class is shown below:
class HelloWorldApp
{
// program code
}
 To execute a class, it must contain a valid main method
 It is the first method that automatically gets invoked when the program
executed
public static void main (String args[])
{
//instructions
}
Main method
public static void main (String args[])
{
//instructions
}
 The main method must always be defined as public:
to make it publicly accessible,
 static: to declare it as a class member and
 void: returns no value
 args[]: parameter is an array of class String. It
provides access to command line parameters
System class
System.out.println("Hello World!");
 invokes println method on object
named out variable (of type
java.io.PrintStream), which is a member
of System class. The println method takes
a String parameter and displays it on the
console

More Related Content

What's hot

Chapter 1. java programming language overview
Chapter 1. java programming language overviewChapter 1. java programming language overview
Chapter 1. java programming language overview
Jong Soon Bok
 
Chapter 1 introduction to java technology
Chapter 1 introduction to java technologyChapter 1 introduction to java technology
Chapter 1 introduction to java technology
sshhzap
 

What's hot (20)

J2EE Struts with Hibernate Framework
J2EE Struts with Hibernate FrameworkJ2EE Struts with Hibernate Framework
J2EE Struts with Hibernate Framework
 
Java unit 1
Java unit 1Java unit 1
Java unit 1
 
Introduction to Java Programming
Introduction to Java Programming Introduction to Java Programming
Introduction to Java Programming
 
Java introduction
Java introductionJava introduction
Java introduction
 
Evolution Of Java
Evolution Of JavaEvolution Of Java
Evolution Of Java
 
Java features
Java featuresJava features
Java features
 
JRE , JDK and platform independent nature of JAVA
JRE , JDK and platform independent nature of JAVAJRE , JDK and platform independent nature of JAVA
JRE , JDK and platform independent nature of JAVA
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
 
History of java
History of javaHistory of java
History of java
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...
 
Java history 01
Java history 01Java history 01
Java history 01
 
Core java environment setup and details
Core java environment setup and detailsCore java environment setup and details
Core java environment setup and details
 
Introduction to java technology
Introduction to java technologyIntroduction to java technology
Introduction to java technology
 
The Java Story
The Java StoryThe Java Story
The Java Story
 
Chapter 1. java programming language overview
Chapter 1. java programming language overviewChapter 1. java programming language overview
Chapter 1. java programming language overview
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Chapter 1 introduction to java technology
Chapter 1 introduction to java technologyChapter 1 introduction to java technology
Chapter 1 introduction to java technology
 
1 Introduction To Java Technology
1 Introduction To Java Technology 1 Introduction To Java Technology
1 Introduction To Java Technology
 
Basics of JAVA programming
Basics of JAVA programmingBasics of JAVA programming
Basics of JAVA programming
 
Java & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate FrameworkJava & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate Framework
 

Similar to Lec 3 01_aug13

JAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxJAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptx
Murugesh33
 
Java chapter 1 basic introduction Unit-1.pptx
Java chapter  1 basic introduction Unit-1.pptxJava chapter  1 basic introduction Unit-1.pptx
Java chapter 1 basic introduction Unit-1.pptx
noosdysharma
 
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
10322210023
 

Similar to Lec 3 01_aug13 (20)

JAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxJAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptx
 
JAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxJAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptx
 
Unit-IV_Introduction to Java.pdf
Unit-IV_Introduction to Java.pdfUnit-IV_Introduction to Java.pdf
Unit-IV_Introduction to Java.pdf
 
Java chapter 1 basic introduction Unit-1.pptx
Java chapter  1 basic introduction Unit-1.pptxJava chapter  1 basic introduction Unit-1.pptx
Java chapter 1 basic introduction Unit-1.pptx
 
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptxJAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
 
Java chapter 1
Java   chapter 1Java   chapter 1
Java chapter 1
 
1 java introduction
1 java introduction1 java introduction
1 java introduction
 
1 java intro
1 java intro1 java intro
1 java intro
 
Java Introduction | PDF
Java Introduction |  PDFJava Introduction |  PDF
Java Introduction | PDF
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operator
 
Unit1 JAVA.pptx
Unit1 JAVA.pptxUnit1 JAVA.pptx
Unit1 JAVA.pptx
 
Java ms harsha
Java ms harshaJava ms harsha
Java ms harsha
 
Java programming material for beginners by Nithin, VVCE, Mysuru
Java programming material for beginners by Nithin, VVCE, MysuruJava programming material for beginners by Nithin, VVCE, Mysuru
Java programming material for beginners by Nithin, VVCE, Mysuru
 
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
 
unit1.pptx
unit1.pptxunit1.pptx
unit1.pptx
 
JAVA ALL 5 MODULE NOTES.pptx
JAVA ALL 5 MODULE NOTES.pptxJAVA ALL 5 MODULE NOTES.pptx
JAVA ALL 5 MODULE NOTES.pptx
 
Presentation on java
Presentation on javaPresentation on java
Presentation on java
 
java intro.pptx
java intro.pptxjava intro.pptx
java intro.pptx
 
Getting Started with JAVA
Getting Started with JAVAGetting Started with JAVA
Getting Started with JAVA
 
Features of java Part - 3
Features of java Part - 3Features of java Part - 3
Features of java Part - 3
 

More from Palak Sanghani

More from Palak Sanghani (20)

Survey form
Survey formSurvey form
Survey form
 
Survey
SurveySurvey
Survey
 
Nature2
Nature2Nature2
Nature2
 
Texture
TextureTexture
Texture
 
Lec 11 12_sept [compatibility mode]
Lec 11 12_sept [compatibility mode]Lec 11 12_sept [compatibility mode]
Lec 11 12_sept [compatibility mode]
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]
 
Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]
 
Lec 7 28_aug [compatibility mode]
Lec 7 28_aug [compatibility mode]Lec 7 28_aug [compatibility mode]
Lec 7 28_aug [compatibility mode]
 
Lec 10 10_sept [compatibility mode]
Lec 10 10_sept [compatibility mode]Lec 10 10_sept [compatibility mode]
Lec 10 10_sept [compatibility mode]
 
Lec 6 14_aug [compatibility mode]
Lec 6 14_aug [compatibility mode]Lec 6 14_aug [compatibility mode]
Lec 6 14_aug [compatibility mode]
 
Lec 4 06_aug [compatibility mode]
Lec 4 06_aug [compatibility mode]Lec 4 06_aug [compatibility mode]
Lec 4 06_aug [compatibility mode]
 
Lec 2 30_jul13
Lec 2 30_jul13Lec 2 30_jul13
Lec 2 30_jul13
 
Lec 1 25_jul13
Lec 1 25_jul13Lec 1 25_jul13
Lec 1 25_jul13
 
Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]
 
Nature
NatureNature
Nature
 
Comparisionof trees
Comparisionof treesComparisionof trees
Comparisionof trees
 
My Structure Patterns
My Structure PatternsMy Structure Patterns
My Structure Patterns
 
My Similarity Patterns
My Similarity PatternsMy Similarity Patterns
My Similarity Patterns
 
My Radiation Patterns
My Radiation PatternsMy Radiation Patterns
My Radiation Patterns
 
My Gradation Patterns
My Gradation PatternsMy Gradation Patterns
My Gradation Patterns
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 

Lec 3 01_aug13

  • 2. Characteristics 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  Java Is Multithreaded  Java Is Dynamic 2 www.cs.armstrong.edu/liang/intro6e/JavaCharacteristics.pdf
  • 3. Characteristics 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  Java Is Multithreaded  Java Is Dynamic 3 Java is partially modeled on C++, but greatly simplified and improved. It is like C++ but with more functionality and fewer negative aspects
  • 4. Characteristics 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  Java Is Multithreaded  Java Is Dynamic 4 Java is inherently object-oriented. Java was designed from the start to be object-oriented. One of the central issues in software development is how to reuse code. Object-oriented programming provides great flexibility, modularity, clarity, and reusability through encapsulation, inheritance, and polymorphism.
  • 5. Characteristics 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  Java Is Multithreaded  Java Is Dynamic 5 Distributed computing involves several computers working together on a network. Java is designed to make distributed computing (e.g. Web Services) easy. Since networking capability is inherently integrated into Java, writing network programs is like sending and receiving data to and from a file
  • 6. Characteristics 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  Java Is Multithreaded  Java Is Dynamic 6 You need an interpreter to run Java programs. The programs are compiled into bytecode. The bytecode is machine- independent and can run on any machine that has a Java interpreter, which is part of the JVM
  • 7. Characteristics 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  Java Is Multithreaded  Java Is Dynamic 7 Java compiler can detect many problems that would first show up at execution time in other languages Java has eliminated certain types of error-prone programming constructs found in other languages (default value, memory leak) Java has a runtime exception-handling feature to provide programming support for robustness
  • 8. Characteristics 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  Java Is Multithreaded  Java Is Dynamic 8 Java implements several security mechanisms to protect your system •enforce array bound check(buffer overflow) •not allow to perform unsafe operations such as pointer arithmetic or unchecked type casts •not allow manual control over memory allocation and deallocation; users rely on automatic garbage collection •Java Library provides APIs related to security, such as standard cryptographic algo’s, Auth., and secure comm protocols. •Exception handling •Ensure that no viruses are communicated with an applet
  • 9. Characteristics 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  Java Is Multithreaded  Java Is Dynamic 9 Write once, run anywhere With a Java Virtual Machine (JVM), you can write one program that will run on any platform
  • 10. Characteristics 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  Java Is Multithreaded  Java Is Dynamic 10 The execution of byte code by the JVM makes java programs portable Because Java is architecture neutral, Java programs are portable. They can be run on any platform without being recompiled
  • 11. Characteristics 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  Java Is Multithreaded  Java Is Dynamic 11 Because Java is architecture neutral, Java programs are portable. They can be run on any platform without being recompiled •Java performance is slower than C •Can sometimes be even faster than compiled C code! •Incorporation of multithreading enhance the overall execution speed •Just-in-Time (JIT) can compile the byte code into machine code JIT compiler turns Java bytecode into instructions that can be sent directly to a particular hardware platform's processor.
  • 12. Characteristics 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  Java Is Multithreaded  Java Is Dynamic 12 Multithread programming is smoothly integrated in Java, whereas in other languages you have to call procedures specific to the operating system to enable multithreading
  • 13. Characteristics 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  Java Is Multithreaded  Java Is Dynamic 13 • Capable of dynamically linking a new class libraries, methods and objects. • Java can use efficient functions available in C/C++. • Installing new version of library automatically updates all programs
  • 14.  Java programs normally undergo five phases – Edit  Programmer writes program (and stores program on disk) – Compile  Compiler creates bytecodes from program – Load  Class loader stores bytecodes in primary memory – Verify  Verifier ensures bytecodes do not violate security requirements – Execute  Interpreter translates bytecodes into machine language Basics of Java Environments
  • 15. Primary Memory . . . . . . Disk Disk Disk Editor Compiler Class Loader Program is created in an editor and stored on disk in a file ending with .java. Compiler creates bytecodes and stores them on disk in a file ending with .class. Class loader reads .class files containing bytecodes from disk and puts those bytecodes in memory. Phase 1 Phase 2 Phase 3 Primary Memory . . . . . . Bytecode Verifier Bytecode verifier confirms that all bytecodes are valid and do not violate Java’s security restrictions. Phase 4 Primary Memory . . . . . . Interpreter Interpreter reads bytecodes and translates them into a language that the computer can understand, possibly storing data values as the program executes. Phase 5
  • 16.  Development tools-part of java development kit (JDK)  Classes and methods-part of Java Standard Library (JSL), also known as Application Programming Interface (API) 1. JDK:  Appletviewer ( for viewing applets)  Javac (Compiler)  Java (Interpreter)  Javah (for C header files)  Javadoc ( for creating HTML description) Java Environment
  • 17. 2. Application Package Interface (API) Contains hundreds of classes and methods grouped into several functional packages:  Language Support Package  Utility Packages (rand. num. gen., sys. date mani.)  Input/Output Packages  Networking Packages (implementing networking app. )  AWT Package (classes for painting graphics and images)  Applet Package (web page using java) Java Environment
  • 18. 1. Java 1.0 (96) 2. Java 1.1 (97)(Add new library, redefine applet handling and reconfigured many features.) 3. Java 2 (98)(Second generation). Version no:1.2 (Internal version number of java library). Also known as J2SE [ Java 2 Platform Standard Edition]. - Add swing, the collection framework, enhanced JVM etc. 4. J2SE 1.3 (2000) 5. J2SE 1.4 (2002) 6. J2SE 1.5 (2004) 7. J2SE 1.6 (2006) [1.7-(2011), in queue 1.8, 1.9] The Evolution of Java
  • 19. Comments In Java, comments are preceded by two slashes (//) in a line, or enclosed between /* and */ in one or multiple lines When the compiler sees //, it ignores all text after // in the same line When it sees /*, it scans for the next */ and ignores any text between /* and */
  • 20. Example /* Traditional "Hello World!" program. */ // package pack1; // import java.lang.System; class a { public static void main (String args[]) { System.out.println("Hello World!"); } } Save program as a.java
  • 21. Java Program Structure Package Statement  Javac command compiles the source code a.java then, generates a.class and store it under a directory which is called as name of the package  package statement if used must be the first statement in a compilation unit. Its syntax is: package packageName;  For example: package pack1;
  • 22. Import Statement  The import statements are similar to #include statements in C and C++  In the above program, System class of java.lang package is imported into all Java programs by default. The syntax of import statement is as: import fullClassName;  For example, the following import statement imports the System class from java.lang: import java.lang.System; import java.lang.*;
  • 23. Classes and Methods  Class declarations contain a keyword class and an identifier  Class members are enclosed within braces. The syntax of defining a class is shown below: class HelloWorldApp { // program code }  To execute a class, it must contain a valid main method  It is the first method that automatically gets invoked when the program executed public static void main (String args[]) { //instructions }
  • 24. Main method public static void main (String args[]) { //instructions }  The main method must always be defined as public: to make it publicly accessible,  static: to declare it as a class member and  void: returns no value  args[]: parameter is an array of class String. It provides access to command line parameters
  • 25. System class System.out.println("Hello World!");  invokes println method on object named out variable (of type java.io.PrintStream), which is a member of System class. The println method takes a String parameter and displays it on the console