SlideShare uma empresa Scribd logo
1 de 64
Introduction
What is Java
• A general purpose Programming Language
• Most Famous Object Oriented Programming
Language.
• Suited for the web and networked services,
applications, platform independent desktops,
robotics, embedded devices.
Java No Longer a
Programming Language
but a Platform
History of Java
• Developed by James Gosling, Mike Sheridan,
Patrick Naughton et. al;
• When working on green project;
• The goal of this project was to control
microprocessor embedded in electronic
devices.
• To perform this task, a platform independent,
reliable, and compact language was needed
History of Java
• Gosling was given task to identify the proper
programming language for the project.
• Gosling decided to develop a new language to
avoid the problems of current programming
languages(C++ especially)
• The new language developed for this purpose
is called “Oak”
History of Java
It consist of –
• Oak Programming Language
• An Operating System
• An User Interface
• A Hardware
Java Versions
• JDK 1.0 1996
• JDK 1.1 1997
• JDk 1.2 1998 (Java 2)
• JDK 1.3 2000 (Java 2)
• JDK 1.4 2002 (Java 2)
• JDK 5.0 2004 (J2SE 5.0)
• JDK 6.0 2006 (Java SE 6)
• JDK 7.0 2010
With the advancement of Java and its
widespread popularity, multiple
configurations were built to suite various
types of platforms.
Ex: J2EE for Enterprise Applications
J2ME for Mobile Applications.
• Sun Microsystems has renamed the new J2
versions as Java SE, Java EE and Java ME
respectively.
• Java is guaranteed to be Write Once, Run
Anywhere.
Object Oriented
• Java, everything is an Object.
• Java can be easily extended since it is based
on the Object model.
Platform independent
• Unlike many other programming languages
including C and C++, when Java is compiled, it
is not compiled into platform specific
machine, rather into platform independent
byte code. This byte code is distributed over
the web and interpreted by virtual Machine
(JVM) on whichever platform it is being run.
Simple
• Java is designed to be easy to learn. If you
understand the basic concept of OOP Java
would be easy to master.
Secure
• With Java's secure feature it enables to
develop virus-free, tamper-free systems.
Authentication techniques are based on
public-key encryption.
Architectural-neutral
• Java compiler generates an architecture-
neutral object file format which makes the
compiled code to be executable on many
processors, with the presence of Java runtime
system.
Portable
• Being architectural-neutral and having no
implementation dependent aspects of the
specification makes Java portable.
• Compiler in Java is written in ANSI C
Robust
• Java makes an effort to eliminate error prone
situations by emphasizing mainly on compile
time error checking and runtime checking.
Multithreaded
• With Java's multithreaded feature it is
possible to write programs that can do many
tasks simultaneously. This design feature
allows developers to construct smoothly
running interactive applications.
Interpreted
• Java byte code is translated on the fly to
native machine instructions and is not stored
anywhere. The development process is more
rapid and analytical since the linking is an
incremental and light weight process.
High Performance
• With the use of Just-In-Time compilers, Java
enables high performance
Distributed
• Java is designed for the distributed
environment of the internet
Dynamic
• Java is considered to be more dynamic than C
or C++ since it is designed to adapt to an
evolving environment. Java programs can
carry extensive amount of run-time
information that can be used to verify and
resolve accesses to objects on run-time.
Java Environment
Java Programming Language
JDK JSL
Java Programming Environment
Java Environment
(Java Development Environment)
A set of Programming Tools
(Java Standard Library)
(A collection of Classes and Methods)
It is also called Java API
Java Development Kit
(JDK)
• A Software Package
• Sun Microsystems made it available free on
the website
• Includes all basic components of Java
Environment
Java Development Kit
(JDK) - Tools
Java Development Kit
File Structure(C:jdk)
jdk
include
bin
lib
jre demo
Src.zip
• A collection of utilities that help u to develop,
execute, debug and document java programs
• Include-
– javac.exe
– java.exe
– javadoc.exe
– appletviewer.exe
Java Development Kit
bin
• Contains files that support native code
programming
• integrate java with other programming
languages.
• Include-
– jawet.h
– jni.h
Java Development Kit
include
Un T
• Root directory of Java Run Time Environment
• Includes
– JVM(Java Virtual Machine)
– runtime class libraries
– java application launcher
Java Development Kit
jre
• Includes additional class libraries and support
files required by the development tools
– htmlconvertor
– jconsole
Java Development Kit
lib
• Consist of sample programs with source code
Java Development Kit
demo
• Compressed files contain source code for java
API classes(that are included in JDK)
• We can unpack these files.
• The source code in these files helps
developers to learn and use the java
programming language
Java Development Kit
src.zip
• A command line tool that reads java source
code files and compiles it into executable byte
code classes.
Hello.java Hello.class
javac [Options] [File Name]
Example- Javac Hello.java
Syntax
• Java programs are compiled to byte code and
not in native code.
• Hence it can not be run on the machine
directly.
• Java Runtime Interpreter implements Java
Virtual Machine(JVM) and runs java
applications.
• It is used to run java .class file by doing
following two things-
– Starting Java Runtime Environment(JRE)
– Loading the specified class
– Invoking the main() method
Hello.class
java [ Options ] [ Class Name ] [ Arguments ]
Example- Java Hello
Syntax
OUTPUT
• A command line tool
• Used to run applet without the need of a web
browser
• Command line tool helps
• Used to find out and fixes bugs in java
programs
jdb [Options] [Class Name] [Arguments]
• A command line tool
• Reads java bytecode class files
• Print human readable version of API defined
by those classes.
• A command line tool
• Produces two c files
– C Header file
– C stub file
• These C files are used to implement native
methods
• The header file contains the declaration for
the C implementation function and structure
definition
• Stub file provide the glue that binds the java
method invocations and object references to
the C code
• The header file name is appended with .h
• The stub file name is appended with .c
• A command line tool
• Used to generate documentation in the form
of HTML pages
txt • Text Editor
.java • Java Source Code
Javac • Java Compiler
.class • Java Class File
Java • Java Interpreter
Java • Java Program Output
javadoc HTML Files
javah Header and Stub Files
jdb
Java Virtual Machine (JVM)
• A Component of Java System
• It interprets and executes the instructions in
our class files.
Figure 1: Memory configuration by the JVM.
ea
Class Files
Execution
Engine
Native Method
Interface
Native Method
Libraries
• Each instance of the JVM has one method area,
one heap, and one or more stacks - one for each
thread
• When JVM loads a class file, it puts its information
in the method area
• As the program runs, all objects instantiated are
stored in the heap
• The stack area is used to store activation records as
a program runs
Stack
Frame
Stack
Frame
Stack
Frame
Stack
Frame
Stack
Frame
Stack
Frame
Object Object
Object Object
Object Object
Class
Data
Class
Data
Class
Data
Class
Data
Class
Data
Class
Data
Method Area Heap Stack Area
Thread 1 Thread 2
• The class loader performs three main functions of
JVM, namely:
• The linking process consists of three sub-tasks,
namely,
Load
Link
Initialize
Verify
Prepare
Resolve
• Loading means reading the class file for a type, parsing it to get its
information, and storing the information in the method area.
• For each type it loads, the JVM must store the following information
in the method area:
– The fully qualified name of the type
– The fully qualified name of the type's direct superclass or if the type is an
interface, a list of its direct super interfaces .
– Whether the type is a class or an interface
– The type's modifiers ( public, abstract, final, etc)
– Constant pool for the type: constants and symbolic references.
– Field info : name, type and modifiers of variables (not constants)
– Method info: name, return type, number & types of parameters, modifiers,
bytecodes, size of stack frame and exception table.
• The end of the loading process is the creation of an instance of java.lang.Class for the loaded
type.
• The purpose is to give access to some of the information captured in the method area for
the type, to the programmer.
• Some of the methods of the class java.lang.Class are:
• Note that for any loaded type T, only one instance of java.lang.Class is created even if T is
used several times in an application.
• To use the above methods, we need to first call the getClass() method on any instance of T
to get the reference to the Class instance for T.
public String getName()
public Class getSupClass()
public boolean isInterface()
public Class[] getInterfaces()
public Method[] getMethods()
public Fields[] getFields()
public Constructor[] getConstructors()
Instances of Class objects created in the heap at runtime
import java.lang.reflect.Method; // Required!
//you must import your Circle class
public class TestClassClass{
public static void main(String[] args) {
String name = new String(“Ahmed”);
Class nameClassInfo = name.getClass();
System.out.println("Class name is : “ + nameClassInfo.getName());
System.out.println("Parent is : “ + nameClassInfo.getSuperclass());
Method[] methods = nameClassInfo.getMethods();
System.out.println("nMethods are: ");
for(int i = 0; i < methods.length; i++)
System.out.println(methods[i]);
}
}
Verify
Prepare
Resolve
• The next process handled by the class loader is Linking. This involves three sub-
processes: Verification, Preparation and Resolution
• Verification is the process of ensuring that binary representation of a class is
structurally correct
• The JVM has to make sure that a file it is asked to load was generated by a valid
compiler and it is well formed
• Class B may be a valid sub-class of A at the time A and B were compiled, but class A
may have been changed and re-compiled
• Example of some of the things that are checked at verification are:
– Every method is provided with a structurally correct signature
– Every instruction obeys the type discipline of the Java language
– Every branch instruction branches to the start not middle of another
instruction
• In this phase, the JVM allocates memory for the class (i.e static) variables
and sets them to default initial values.
• Note that class variables are not initialized to their proper initial values until the
initialization phase - no java code is executed until initialization.
• The default values for the various types are shown below:
• Resolution is the process of replacing symbolic names for types, fields and methods used
by a loaded type with their actual references.
• Symbolic references are resolved into a direct references by searching through the method
area to locate the referenced entity.
• For the class below, at the loading phase, the class loader would have loaded the classes:
TestClassClass, String, System and Object.
• The names of these classes would have been stored in the constant pool for TestClassClass.
• In this phase, the names are replaced with their actual references.
public class TestClassClass{
public static void main(String[] args){
String name = new String(“Ahmed”);
Class nameClassInfo = name.getClass();
System.out.println("Parent is: “ + nameClassInfo.getSuperclass());
}
}
• This is the process of setting class variables to their proper initial values - initial values desired by
the programmer.
• Initialization of a class consists of two steps:
– Initializing its direct superclass (if any and if not already initialized)
– Executing its own initialization statements
• The above imply that, the first class that gets initialized is Object.
• Note that static final variables are not treated as class variables but as constants and are
assigned their values at compilation.
class Example1 {
static double rate = 3.5;
static int size = 3*(int)(Math.random()*5);
...
}
class Example2 {
static final int angle = 35;
static final int length = angle * 2;
...
}
• After a class is loaded, linked, and initialized, it is ready for use. Its
static fields and static methods can be used and it can be instantiated.
• When a new class instance is created, memory is allocated for all its instance
variables in the heap.
• Memory is also allocated recursively for all the instance variables declared in its
super class and all classes up is inheritance hierarchy.
• All instance variables in the new object and those of its superclasses are then
initialized to their default values.
• The constructor invoked in the instantiation is then processed according to the
rules shown on the next page.
• Finally, the reference to the newly created object is returned as the result.
Rules for processing a constructor:
1. Assign the arguments for the constructor to its parameter variables.
2. If this constructor begins with an explicit invocation of another constructor in the
same class (using this), then evaluate the arguments and process that constructor
invocation recursively.
3. If this constructor is for a class other than Object, then it will begin with an explicit
or implicit invocation of a superclass constructor (using super). Evaluate the
arguments and process that superclass constructor invocation recursively.
4. Initialize the instance variables for this class with their proper values.
5. Execute the rest of the body of this constructor.
class GrandFather {
int grandy = 70;
public GrandFather(int grandy) {
this.grandy = grandy;
System.out.println("Grandy: "+grandy);
}
}
class Father extends GrandFather {
int father = 40;
public Father(int grandy, int father) {
super(grandy);
this.father = father;
System.out.println("Grandy: "+grandy+" Father: "+father);
}
}
class Son extends Father {
int son = 10;
public Son(int grandy, int father, int son) {
super(grandy, father);
this.son = son;
System.out.println("Grandy: "+grandy+" Father: "+father+" Son: "+son);
}
}
public class Instantiation {
public static void main(String[] args) {
Son s = new Son(65, 35, 5);
}
}

Mais conteĂşdo relacionado

Mais procurados

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...Mr. Akaash
 
Basics of JAVA programming
Basics of JAVA programmingBasics of JAVA programming
Basics of JAVA programmingElizabeth Thomas
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Languagejaimefrozr
 
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 JAVAMehak Tawakley
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java ProgrammingMath-Circle
 
Java Presentation
Java PresentationJava Presentation
Java Presentationaitrichtech
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language Hitesh-Java
 
JDK,JRE,JVM
JDK,JRE,JVMJDK,JRE,JVM
JDK,JRE,JVMCognizant
 
Core java slides
Core java slidesCore java slides
Core java slidesAbhilash Nair
 
Core java concepts
Core java  conceptsCore java  concepts
Core java conceptsRam132
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java ProgrammingRavi Kant Sahu
 
Introduction to Java
Introduction to Java Introduction to Java
Introduction to Java Hitesh-Java
 
Java Presentation
Java PresentationJava Presentation
Java Presentationpm2214
 
Core Java
Core JavaCore Java
Core JavaNA
 
Industrial Training Report on Java Technology.
Industrial Training Report on Java Technology.Industrial Training Report on Java Technology.
Industrial Training Report on Java Technology.Ritesh Kumar Bhanu
 

Mais procurados (20)

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...
 
Basics of JAVA programming
Basics of JAVA programmingBasics of JAVA programming
Basics of JAVA programming
 
Java
JavaJava
Java
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Language
 
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
 
core java
core javacore java
core java
 
Java seminar
Java seminarJava seminar
Java seminar
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
 
JDK,JRE,JVM
JDK,JRE,JVMJDK,JRE,JVM
JDK,JRE,JVM
 
Core java slides
Core java slidesCore java slides
Core java slides
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Introduction to Java
Introduction to Java Introduction to Java
Introduction to Java
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
 
Core Java
Core JavaCore Java
Core Java
 
Industrial Training Report on Java Technology.
Industrial Training Report on Java Technology.Industrial Training Report on Java Technology.
Industrial Training Report on Java Technology.
 

Destaque

Introduction to java
Introduction to javaIntroduction to java
Introduction to javaVeerabadra Badra
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javaASU Online
 
Introduction to java Programming
Introduction to java ProgrammingIntroduction to java Programming
Introduction to java ProgrammingAhmed Ayman
 
Griffon: Re-imaging Desktop Java Technology
Griffon: Re-imaging Desktop Java TechnologyGriffon: Re-imaging Desktop Java Technology
Griffon: Re-imaging Desktop Java TechnologyJames Williams
 
An introduction to java programming language forbeginners(java programming tu...
An introduction to java programming language forbeginners(java programming tu...An introduction to java programming language forbeginners(java programming tu...
An introduction to java programming language forbeginners(java programming tu...Daroko blog(www.professionalbloggertricks.com)
 
1 introduction to java technology
1 introduction to java technology1 introduction to java technology
1 introduction to java technologyrendezvous07
 
Android - 04 - Internship project introduction
Android - 04 - Internship project introductionAndroid - 04 - Internship project introduction
Android - 04 - Internship project introductionNoveo
 
Chapter 1 introduction to java technology
Chapter 1 introduction to java technologyChapter 1 introduction to java technology
Chapter 1 introduction to java technologysshhzap
 
Java 7 - State of the Enterprise
Java 7 - State of the EnterpriseJava 7 - State of the Enterprise
Java 7 - State of the EnterpriseMarkus Eisele
 
Whitep paper on Emerging java and .net technology and critical trends
Whitep paper on Emerging java and .net technology and critical trendsWhitep paper on Emerging java and .net technology and critical trends
Whitep paper on Emerging java and .net technology and critical trendsRakesh Jha
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101kankemwa Ishaku
 
1 Introduction To Java Technology
1 Introduction To Java Technology 1 Introduction To Java Technology
1 Introduction To Java Technology dM Technologies
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java ProgrammingPokequesthero
 

Destaque (20)

Introduction to java technology
Introduction to java technologyIntroduction to java technology
Introduction to java technology
 
Java basic
Java basicJava basic
Java basic
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Oops in c
Oops in cOops in c
Oops in c
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Java training in delhi
Java training in delhiJava training in delhi
Java training in delhi
 
Introduction to java Programming
Introduction to java ProgrammingIntroduction to java Programming
Introduction to java Programming
 
Introduction to JAVA
Introduction to JAVAIntroduction to JAVA
Introduction to JAVA
 
Griffon: Re-imaging Desktop Java Technology
Griffon: Re-imaging Desktop Java TechnologyGriffon: Re-imaging Desktop Java Technology
Griffon: Re-imaging Desktop Java Technology
 
An introduction to java programming language forbeginners(java programming tu...
An introduction to java programming language forbeginners(java programming tu...An introduction to java programming language forbeginners(java programming tu...
An introduction to java programming language forbeginners(java programming tu...
 
Ozis Pre
Ozis PreOzis Pre
Ozis Pre
 
1 introduction to java technology
1 introduction to java technology1 introduction to java technology
1 introduction to java technology
 
Android - 04 - Internship project introduction
Android - 04 - Internship project introductionAndroid - 04 - Internship project introduction
Android - 04 - Internship project introduction
 
Chapter 1 introduction to java technology
Chapter 1 introduction to java technologyChapter 1 introduction to java technology
Chapter 1 introduction to java technology
 
Java 7 - State of the Enterprise
Java 7 - State of the EnterpriseJava 7 - State of the Enterprise
Java 7 - State of the Enterprise
 
Whitep paper on Emerging java and .net technology and critical trends
Whitep paper on Emerging java and .net technology and critical trendsWhitep paper on Emerging java and .net technology and critical trends
Whitep paper on Emerging java and .net technology and critical trends
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101
 
1 Introduction To Java Technology
1 Introduction To Java Technology 1 Introduction To Java Technology
1 Introduction To Java Technology
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Java Basics
Java BasicsJava Basics
Java Basics
 

Semelhante a 1 java programming- introduction

j-chap1-Basics.ppt
j-chap1-Basics.pptj-chap1-Basics.ppt
j-chap1-Basics.pptSmitaBorkar9
 
Comp102 lec 3
Comp102   lec 3Comp102   lec 3
Comp102 lec 3Fraz Bakhsh
 
JavaClassPresentation
JavaClassPresentationJavaClassPresentation
JavaClassPresentationjuliasceasor
 
JAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxJAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxMurugesh33
 
JAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxJAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxMurugesh33
 
Presentation on java
Presentation  on  javaPresentation  on  java
Presentation on javashashi shekhar
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptRajeshSukte1
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptCDSukte
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operatorkamal kotecha
 
Skillwise Elementary Java Programming
Skillwise Elementary Java ProgrammingSkillwise Elementary Java Programming
Skillwise Elementary Java ProgrammingSkillwise Group
 
OOP with Java
OOP with JavaOOP with Java
OOP with JavaOmegaHub
 
1 Module 1 Introduction.pptx
1 Module 1 Introduction.pptx1 Module 1 Introduction.pptx
1 Module 1 Introduction.pptxBhargaviDalal3
 
java full 1 (Recovered).docx
java full 1 (Recovered).docxjava full 1 (Recovered).docx
java full 1 (Recovered).docxSATHYAKALAKSKPRCASBS
 

Semelhante a 1 java programming- introduction (20)

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
 
CS8392 OOP
CS8392 OOPCS8392 OOP
CS8392 OOP
 
oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
 
Java Introduction
Java IntroductionJava Introduction
Java Introduction
 
j-chap1-Basics.ppt
j-chap1-Basics.pptj-chap1-Basics.ppt
j-chap1-Basics.ppt
 
Comp102 lec 3
Comp102   lec 3Comp102   lec 3
Comp102 lec 3
 
JavaClassPresentation
JavaClassPresentationJavaClassPresentation
JavaClassPresentation
 
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
 
Presentation on java
Presentation  on  javaPresentation  on  java
Presentation on java
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.ppt
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.ppt
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operator
 
Skillwise Elementary Java Programming
Skillwise Elementary Java ProgrammingSkillwise Elementary Java Programming
Skillwise Elementary Java Programming
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
OOP with Java
OOP with JavaOOP with Java
OOP with Java
 
1 Module 1 Introduction.pptx
1 Module 1 Introduction.pptx1 Module 1 Introduction.pptx
1 Module 1 Introduction.pptx
 
Introduction to JAVA
Introduction to JAVAIntroduction to JAVA
Introduction to JAVA
 
java slides
java slidesjava slides
java slides
 
java full 1 (Recovered).docx
java full 1 (Recovered).docxjava full 1 (Recovered).docx
java full 1 (Recovered).docx
 

Mais de jyoti_lakhani

CG02 Computer Graphic Systems.ppsx
CG02 Computer Graphic Systems.ppsxCG02 Computer Graphic Systems.ppsx
CG02 Computer Graphic Systems.ppsxjyoti_lakhani
 
Projections.pptx
Projections.pptxProjections.pptx
Projections.pptxjyoti_lakhani
 
CG04 Color Models.ppsx
CG04 Color Models.ppsxCG04 Color Models.ppsx
CG04 Color Models.ppsxjyoti_lakhani
 
CG03 Random Raster Scan displays and Color CRTs.ppsx
CG03 Random Raster Scan displays and Color CRTs.ppsxCG03 Random Raster Scan displays and Color CRTs.ppsx
CG03 Random Raster Scan displays and Color CRTs.ppsxjyoti_lakhani
 
CG02 Computer Graphic Systems.pptx
CG02 Computer Graphic Systems.pptxCG02 Computer Graphic Systems.pptx
CG02 Computer Graphic Systems.pptxjyoti_lakhani
 
CG01 introduction.ppsx
CG01 introduction.ppsxCG01 introduction.ppsx
CG01 introduction.ppsxjyoti_lakhani
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked listjyoti_lakhani
 
Double ended queue
Double ended queueDouble ended queue
Double ended queuejyoti_lakhani
 
Tree terminology and introduction to binary tree
Tree terminology and introduction to binary treeTree terminology and introduction to binary tree
Tree terminology and introduction to binary treejyoti_lakhani
 
Priority queue
Priority queuePriority queue
Priority queuejyoti_lakhani
 
Ds006 linked list- delete from front
Ds006   linked list- delete from frontDs006   linked list- delete from front
Ds006 linked list- delete from frontjyoti_lakhani
 
Ds06 linked list- insert a node after a given node
Ds06   linked list-  insert a node after a given nodeDs06   linked list-  insert a node after a given node
Ds06 linked list- insert a node after a given nodejyoti_lakhani
 
Ds06 linked list- insert a node at end
Ds06   linked list- insert a node at endDs06   linked list- insert a node at end
Ds06 linked list- insert a node at endjyoti_lakhani
 
Ds06 linked list- insert a node at beginning
Ds06   linked list- insert a node at beginningDs06   linked list- insert a node at beginning
Ds06 linked list- insert a node at beginningjyoti_lakhani
 
Ds06 linked list- intro and create a node
Ds06   linked list- intro and create a nodeDs06   linked list- intro and create a node
Ds06 linked list- intro and create a nodejyoti_lakhani
 
Ds04 abstract data types (adt) jyoti lakhani
Ds04 abstract data types (adt) jyoti lakhaniDs04 abstract data types (adt) jyoti lakhani
Ds04 abstract data types (adt) jyoti lakhanijyoti_lakhani
 
Ds03 part i algorithms by jyoti lakhani
Ds03 part i algorithms   by jyoti lakhaniDs03 part i algorithms   by jyoti lakhani
Ds03 part i algorithms by jyoti lakhanijyoti_lakhani
 
Ds03 algorithms jyoti lakhani
Ds03 algorithms jyoti lakhaniDs03 algorithms jyoti lakhani
Ds03 algorithms jyoti lakhanijyoti_lakhani
 
Ds02 flow chart and pseudo code
Ds02 flow chart and pseudo codeDs02 flow chart and pseudo code
Ds02 flow chart and pseudo codejyoti_lakhani
 
Ds01 data structure introduction - by jyoti lakhani
Ds01 data structure  introduction - by jyoti lakhaniDs01 data structure  introduction - by jyoti lakhani
Ds01 data structure introduction - by jyoti lakhanijyoti_lakhani
 

Mais de jyoti_lakhani (20)

CG02 Computer Graphic Systems.ppsx
CG02 Computer Graphic Systems.ppsxCG02 Computer Graphic Systems.ppsx
CG02 Computer Graphic Systems.ppsx
 
Projections.pptx
Projections.pptxProjections.pptx
Projections.pptx
 
CG04 Color Models.ppsx
CG04 Color Models.ppsxCG04 Color Models.ppsx
CG04 Color Models.ppsx
 
CG03 Random Raster Scan displays and Color CRTs.ppsx
CG03 Random Raster Scan displays and Color CRTs.ppsxCG03 Random Raster Scan displays and Color CRTs.ppsx
CG03 Random Raster Scan displays and Color CRTs.ppsx
 
CG02 Computer Graphic Systems.pptx
CG02 Computer Graphic Systems.pptxCG02 Computer Graphic Systems.pptx
CG02 Computer Graphic Systems.pptx
 
CG01 introduction.ppsx
CG01 introduction.ppsxCG01 introduction.ppsx
CG01 introduction.ppsx
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 
Double ended queue
Double ended queueDouble ended queue
Double ended queue
 
Tree terminology and introduction to binary tree
Tree terminology and introduction to binary treeTree terminology and introduction to binary tree
Tree terminology and introduction to binary tree
 
Priority queue
Priority queuePriority queue
Priority queue
 
Ds006 linked list- delete from front
Ds006   linked list- delete from frontDs006   linked list- delete from front
Ds006 linked list- delete from front
 
Ds06 linked list- insert a node after a given node
Ds06   linked list-  insert a node after a given nodeDs06   linked list-  insert a node after a given node
Ds06 linked list- insert a node after a given node
 
Ds06 linked list- insert a node at end
Ds06   linked list- insert a node at endDs06   linked list- insert a node at end
Ds06 linked list- insert a node at end
 
Ds06 linked list- insert a node at beginning
Ds06   linked list- insert a node at beginningDs06   linked list- insert a node at beginning
Ds06 linked list- insert a node at beginning
 
Ds06 linked list- intro and create a node
Ds06   linked list- intro and create a nodeDs06   linked list- intro and create a node
Ds06 linked list- intro and create a node
 
Ds04 abstract data types (adt) jyoti lakhani
Ds04 abstract data types (adt) jyoti lakhaniDs04 abstract data types (adt) jyoti lakhani
Ds04 abstract data types (adt) jyoti lakhani
 
Ds03 part i algorithms by jyoti lakhani
Ds03 part i algorithms   by jyoti lakhaniDs03 part i algorithms   by jyoti lakhani
Ds03 part i algorithms by jyoti lakhani
 
Ds03 algorithms jyoti lakhani
Ds03 algorithms jyoti lakhaniDs03 algorithms jyoti lakhani
Ds03 algorithms jyoti lakhani
 
Ds02 flow chart and pseudo code
Ds02 flow chart and pseudo codeDs02 flow chart and pseudo code
Ds02 flow chart and pseudo code
 
Ds01 data structure introduction - by jyoti lakhani
Ds01 data structure  introduction - by jyoti lakhaniDs01 data structure  introduction - by jyoti lakhani
Ds01 data structure introduction - by jyoti lakhani
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Último (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

1 java programming- introduction

  • 2. What is Java • A general purpose Programming Language • Most Famous Object Oriented Programming Language. • Suited for the web and networked services, applications, platform independent desktops, robotics, embedded devices.
  • 3. Java No Longer a Programming Language but a Platform
  • 4. History of Java • Developed by James Gosling, Mike Sheridan, Patrick Naughton et. al; • When working on green project; • The goal of this project was to control microprocessor embedded in electronic devices. • To perform this task, a platform independent, reliable, and compact language was needed
  • 5. History of Java • Gosling was given task to identify the proper programming language for the project. • Gosling decided to develop a new language to avoid the problems of current programming languages(C++ especially) • The new language developed for this purpose is called “Oak”
  • 6. History of Java It consist of – • Oak Programming Language • An Operating System • An User Interface • A Hardware
  • 7. Java Versions • JDK 1.0 1996 • JDK 1.1 1997 • JDk 1.2 1998 (Java 2) • JDK 1.3 2000 (Java 2) • JDK 1.4 2002 (Java 2) • JDK 5.0 2004 (J2SE 5.0) • JDK 6.0 2006 (Java SE 6) • JDK 7.0 2010
  • 8. With the advancement of Java and its widespread popularity, multiple configurations were built to suite various types of platforms. Ex: J2EE for Enterprise Applications J2ME for Mobile Applications.
  • 9. • Sun Microsystems has renamed the new J2 versions as Java SE, Java EE and Java ME respectively. • Java is guaranteed to be Write Once, Run Anywhere.
  • 10.
  • 11. Object Oriented • Java, everything is an Object. • Java can be easily extended since it is based on the Object model.
  • 12. Platform independent • Unlike many other programming languages including C and C++, when Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by virtual Machine (JVM) on whichever platform it is being run.
  • 13. Simple • Java is designed to be easy to learn. If you understand the basic concept of OOP Java would be easy to master.
  • 14. Secure • With Java's secure feature it enables to develop virus-free, tamper-free systems. Authentication techniques are based on public-key encryption.
  • 15. Architectural-neutral • Java compiler generates an architecture- neutral object file format which makes the compiled code to be executable on many processors, with the presence of Java runtime system.
  • 16. Portable • Being architectural-neutral and having no implementation dependent aspects of the specification makes Java portable. • Compiler in Java is written in ANSI C
  • 17. Robust • Java makes an effort to eliminate error prone situations by emphasizing mainly on compile time error checking and runtime checking.
  • 18. Multithreaded • With Java's multithreaded feature it is possible to write programs that can do many tasks simultaneously. This design feature allows developers to construct smoothly running interactive applications.
  • 19. Interpreted • Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The development process is more rapid and analytical since the linking is an incremental and light weight process.
  • 20. High Performance • With the use of Just-In-Time compilers, Java enables high performance
  • 21. Distributed • Java is designed for the distributed environment of the internet
  • 22. Dynamic • Java is considered to be more dynamic than C or C++ since it is designed to adapt to an evolving environment. Java programs can carry extensive amount of run-time information that can be used to verify and resolve accesses to objects on run-time.
  • 23. Java Environment Java Programming Language JDK JSL Java Programming Environment
  • 24. Java Environment (Java Development Environment) A set of Programming Tools (Java Standard Library) (A collection of Classes and Methods) It is also called Java API
  • 25. Java Development Kit (JDK) • A Software Package • Sun Microsystems made it available free on the website • Includes all basic components of Java Environment
  • 27. Java Development Kit File Structure(C:jdk) jdk include bin lib jre demo Src.zip
  • 28. • A collection of utilities that help u to develop, execute, debug and document java programs • Include- – javac.exe – java.exe – javadoc.exe – appletviewer.exe Java Development Kit bin
  • 29. • Contains files that support native code programming • integrate java with other programming languages. • Include- – jawet.h – jni.h Java Development Kit include
  • 30. Un T • Root directory of Java Run Time Environment • Includes – JVM(Java Virtual Machine) – runtime class libraries – java application launcher Java Development Kit jre
  • 31. • Includes additional class libraries and support files required by the development tools – htmlconvertor – jconsole Java Development Kit lib
  • 32. • Consist of sample programs with source code Java Development Kit demo
  • 33. • Compressed files contain source code for java API classes(that are included in JDK) • We can unpack these files. • The source code in these files helps developers to learn and use the java programming language Java Development Kit src.zip
  • 34.
  • 35. • A command line tool that reads java source code files and compiles it into executable byte code classes. Hello.java Hello.class javac [Options] [File Name] Example- Javac Hello.java Syntax
  • 36. • Java programs are compiled to byte code and not in native code. • Hence it can not be run on the machine directly. • Java Runtime Interpreter implements Java Virtual Machine(JVM) and runs java applications.
  • 37. • It is used to run java .class file by doing following two things- – Starting Java Runtime Environment(JRE) – Loading the specified class – Invoking the main() method
  • 38. Hello.class java [ Options ] [ Class Name ] [ Arguments ] Example- Java Hello Syntax OUTPUT
  • 39. • A command line tool • Used to run applet without the need of a web browser
  • 40. • Command line tool helps • Used to find out and fixes bugs in java programs jdb [Options] [Class Name] [Arguments]
  • 41. • A command line tool • Reads java bytecode class files • Print human readable version of API defined by those classes.
  • 42. • A command line tool • Produces two c files – C Header file – C stub file • These C files are used to implement native methods
  • 43. • The header file contains the declaration for the C implementation function and structure definition • Stub file provide the glue that binds the java method invocations and object references to the C code • The header file name is appended with .h • The stub file name is appended with .c
  • 44. • A command line tool • Used to generate documentation in the form of HTML pages
  • 45. txt • Text Editor .java • Java Source Code Javac • Java Compiler .class • Java Class File Java • Java Interpreter Java • Java Program Output javadoc HTML Files javah Header and Stub Files jdb
  • 47. • A Component of Java System • It interprets and executes the instructions in our class files.
  • 48. Figure 1: Memory configuration by the JVM. ea Class Files Execution Engine Native Method Interface Native Method Libraries
  • 49. • Each instance of the JVM has one method area, one heap, and one or more stacks - one for each thread • When JVM loads a class file, it puts its information in the method area • As the program runs, all objects instantiated are stored in the heap • The stack area is used to store activation records as a program runs
  • 50. Stack Frame Stack Frame Stack Frame Stack Frame Stack Frame Stack Frame Object Object Object Object Object Object Class Data Class Data Class Data Class Data Class Data Class Data Method Area Heap Stack Area Thread 1 Thread 2
  • 51. • The class loader performs three main functions of JVM, namely: • The linking process consists of three sub-tasks, namely,
  • 53. • Loading means reading the class file for a type, parsing it to get its information, and storing the information in the method area. • For each type it loads, the JVM must store the following information in the method area: – The fully qualified name of the type – The fully qualified name of the type's direct superclass or if the type is an interface, a list of its direct super interfaces . – Whether the type is a class or an interface – The type's modifiers ( public, abstract, final, etc) – Constant pool for the type: constants and symbolic references. – Field info : name, type and modifiers of variables (not constants) – Method info: name, return type, number & types of parameters, modifiers, bytecodes, size of stack frame and exception table.
  • 54. • The end of the loading process is the creation of an instance of java.lang.Class for the loaded type. • The purpose is to give access to some of the information captured in the method area for the type, to the programmer. • Some of the methods of the class java.lang.Class are: • Note that for any loaded type T, only one instance of java.lang.Class is created even if T is used several times in an application. • To use the above methods, we need to first call the getClass() method on any instance of T to get the reference to the Class instance for T. public String getName() public Class getSupClass() public boolean isInterface() public Class[] getInterfaces() public Method[] getMethods() public Fields[] getFields() public Constructor[] getConstructors()
  • 55. Instances of Class objects created in the heap at runtime
  • 56. import java.lang.reflect.Method; // Required! //you must import your Circle class public class TestClassClass{ public static void main(String[] args) { String name = new String(“Ahmed”); Class nameClassInfo = name.getClass(); System.out.println("Class name is : “ + nameClassInfo.getName()); System.out.println("Parent is : “ + nameClassInfo.getSuperclass()); Method[] methods = nameClassInfo.getMethods(); System.out.println("nMethods are: "); for(int i = 0; i < methods.length; i++) System.out.println(methods[i]); } }
  • 58. • The next process handled by the class loader is Linking. This involves three sub- processes: Verification, Preparation and Resolution • Verification is the process of ensuring that binary representation of a class is structurally correct • The JVM has to make sure that a file it is asked to load was generated by a valid compiler and it is well formed • Class B may be a valid sub-class of A at the time A and B were compiled, but class A may have been changed and re-compiled • Example of some of the things that are checked at verification are: – Every method is provided with a structurally correct signature – Every instruction obeys the type discipline of the Java language – Every branch instruction branches to the start not middle of another instruction
  • 59. • In this phase, the JVM allocates memory for the class (i.e static) variables and sets them to default initial values. • Note that class variables are not initialized to their proper initial values until the initialization phase - no java code is executed until initialization. • The default values for the various types are shown below:
  • 60. • Resolution is the process of replacing symbolic names for types, fields and methods used by a loaded type with their actual references. • Symbolic references are resolved into a direct references by searching through the method area to locate the referenced entity. • For the class below, at the loading phase, the class loader would have loaded the classes: TestClassClass, String, System and Object. • The names of these classes would have been stored in the constant pool for TestClassClass. • In this phase, the names are replaced with their actual references. public class TestClassClass{ public static void main(String[] args){ String name = new String(“Ahmed”); Class nameClassInfo = name.getClass(); System.out.println("Parent is: “ + nameClassInfo.getSuperclass()); } }
  • 61. • This is the process of setting class variables to their proper initial values - initial values desired by the programmer. • Initialization of a class consists of two steps: – Initializing its direct superclass (if any and if not already initialized) – Executing its own initialization statements • The above imply that, the first class that gets initialized is Object. • Note that static final variables are not treated as class variables but as constants and are assigned their values at compilation. class Example1 { static double rate = 3.5; static int size = 3*(int)(Math.random()*5); ... } class Example2 { static final int angle = 35; static final int length = angle * 2; ... }
  • 62. • After a class is loaded, linked, and initialized, it is ready for use. Its static fields and static methods can be used and it can be instantiated. • When a new class instance is created, memory is allocated for all its instance variables in the heap. • Memory is also allocated recursively for all the instance variables declared in its super class and all classes up is inheritance hierarchy. • All instance variables in the new object and those of its superclasses are then initialized to their default values. • The constructor invoked in the instantiation is then processed according to the rules shown on the next page. • Finally, the reference to the newly created object is returned as the result.
  • 63. Rules for processing a constructor: 1. Assign the arguments for the constructor to its parameter variables. 2. If this constructor begins with an explicit invocation of another constructor in the same class (using this), then evaluate the arguments and process that constructor invocation recursively. 3. If this constructor is for a class other than Object, then it will begin with an explicit or implicit invocation of a superclass constructor (using super). Evaluate the arguments and process that superclass constructor invocation recursively. 4. Initialize the instance variables for this class with their proper values. 5. Execute the rest of the body of this constructor.
  • 64. class GrandFather { int grandy = 70; public GrandFather(int grandy) { this.grandy = grandy; System.out.println("Grandy: "+grandy); } } class Father extends GrandFather { int father = 40; public Father(int grandy, int father) { super(grandy); this.father = father; System.out.println("Grandy: "+grandy+" Father: "+father); } } class Son extends Father { int son = 10; public Son(int grandy, int father, int son) { super(grandy, father); this.son = son; System.out.println("Grandy: "+grandy+" Father: "+father+" Son: "+son); } } public class Instantiation { public static void main(String[] args) { Son s = new Son(65, 35, 5); } }