SlideShare a Scribd company logo
Java Virtual Machine
(JVM)
By:
Prof. Ansari Aadil S.
1
Prof. Aadil Ansari
Basic Introduction to JVM
• Java Virtual Machine is a set of software & program
components. As name suggests, it is a virtual computer
that resides within real computer.
• Java can achieve platform independent feature due to
JVM.
• When we want to write java program, we write the
source code into notepad & store it in the file having
extension .java
Prof. Aadil Ansari
Continue..
• The .java file is compiled using javac compiler. On
compilation a .class file gets generated. This class file is
actually a byte code.
• JVM takes byte code as an input, reads it, interprets it &
then execute it.
• JVM can generate output corresponding to the
underlying operating system.
Prof. Aadil Ansari
JVM act as an Mediator between OS & Java
Text Editor
Java Source
Code
javac
Byte code(.class File)
Windows Mac Linux
Run using java
Compile using javac
Java Virtual
Machine
Prof. Aadil Ansari
Prof. Aadil Ansari
Data types
Prof. Aadil Ansari
Prof. Aadil Ansari
Prof. Aadil Ansari
• System.out.print(“Hello”);
• System.out.print(“n”);
• System.out.print(“Java!”);
print( )method //print and wait
println( )method //print a line and move to the next line
• System.out.println(“Hello”);
• System.out.println(“Java!”);
Prof. Aadil Ansari
Classes
• A class is a collection of fields (data) and methods
(procedure or function) that operate on that data.
• The basic syntax for a class definition:
• For Example:-
class Rectangle {
// my Rectangle class
}
class classname [extends SuperClassName]
{
[fields declaration]
[methods declaration]
}
Prof. Aadil Ansari
Adding Variables: Class Rectangle with fields
• Add variables
• The fields (data) are also called the instance variables.
class Rectangle
{
int length; // Data fields OR instance Variables
float width;
}
Prof. Aadil Ansari
Adding Methods
• Methods are declared inside the body of the
class but immediately after the declaration of
instance variable.
• The general form of a method declaration is:
type methodname (parameter-list)
{
Method-body;
}
Prof. Aadil Ansari
Adding Methods to Class Rectangle
class Rectangle
{
int length;
float width;
void getData(int x, float y) //Method declaration
{
length =x;
width= y;
}
}
Method Body
Prof. Aadil Ansari
Constructor
• Constructor is a special method with same name
as it’s class name
• No return type for constructor. Not even void
• Constructors are implicitly called when objects
are created
• A constructor without input parameter is default
constructor
• Constructor can be overloaded
Prof. Aadil Ansari
class Student4
• {
int id;
String name;
Student4(int i,String n) //constructor
{
id = i;
name = n;
}
void display()
{
System.out.println(id+" "+name);
}
public static void main(String args[])
{
Student4 s1 = new Student4(111,"Karan");
Student4 s2 = new Student4(222,"Aryan");
s1.display();
s2.display();
}Prof. Aadil Ansari
• Output:
111 Karan 222 Aryan
Prof. Aadil Ansari
Creating objects of a class
• Objects in java are created using new operator.
• The new operator creates an object of specified class &
returns a reference of that object.
• For Example:- Rectangle rect1;
rect1 = new Rectangle();
Prof. Aadil Ansari
Continue..
 Both the statement can be combined into one as shown
below.
Rectangle rect1 = new Rectangle();
 The method Rectangle() is default constructor of class.
We can create any number of objects of Rectangle class.
Rectangle rect1 = new Rectangle();
Rectangle rect2 = new Rectangle();
Prof. Aadil Ansari
Prof. Aadil Ansari
Exception handling & Error
• Signal occurs when some unusual condition occurs.
• Various types of signals are Exceptions, Errors,
Interrupts & Controls.
• Exception:- Appropriate execution is raised when some
unusual condition occurs.
• Errors:- Compile time error.
Prof. Aadil Ansari
Continue
• Exception Handling:-The statements that are
likely to cause an exception are enclosed within
a try block.
• There is another block defined by keyword
catch which responsible for handling the
exception thrown by the try block.
• The catch is added immediately after the try
block.
Prof. Aadil Ansari
General syntax of try & catch
try
{
// exception get generated here.
}
catch(Type_of_Exception e)
{
// exception is handled here
}
Prof. Aadil Ansari
For Example:-
class RunErrDemo
{
public static void main(String arg[])
{
int a,b,c;
a= 10, b=0;
try
{
c = a/b; //Exception occurs because the element is
divided by 0
}
Prof. Aadil Ansari
Program continue..
catch(ArithmeticException e)
{
System.out.println(“You cannot divide by Zero”);
}
System.out.println(“ The value of a:” +a);
System.out.println(“The value of b:”+b);
}
}
Prof. Aadil Ansari
Output for above program is
You cannot divide by Zero
The value of a: 10
The value of b: 0
Prof. Aadil Ansari
• Any Questions???????
Prof. Aadil Ansari
• Thank You
Prof. Aadil Ansari

More Related Content

What's hot

Java Tutorial Lab 4
Java Tutorial Lab 4Java Tutorial Lab 4
Java Tutorial Lab 4
Berk Soysal
 
Java8 features
Java8 featuresJava8 features
Java8 features
Minal Maniar
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference Card
Hari kiran G
 
Framework Design Guidelines
Framework Design GuidelinesFramework Design Guidelines
Framework Design Guidelines
Mohamed Meligy
 
Advanced c#
Advanced c#Advanced c#
Advanced c#
AkashThakrar
 
The Ring programming language version 1.5.1 book - Part 68 of 180
The Ring programming language version 1.5.1 book - Part 68 of 180The Ring programming language version 1.5.1 book - Part 68 of 180
The Ring programming language version 1.5.1 book - Part 68 of 180
Mahmoud Samir Fayed
 
C++
C++C++
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and Classes
Michael Heron
 
Basics of java (1)
Basics of java (1)Basics of java (1)
Basics of java (1)
raj upadhyay
 
Java Introduction Workshop Day 2
Java Introduction Workshop Day 2 Java Introduction Workshop Day 2
Java Introduction Workshop Day 2
Osama Saad
 
Exception handling
Exception handlingException handling
Exception handling
Minal Maniar
 
QSpiders - Major difference
QSpiders - Major differenceQSpiders - Major difference
Introduction to c first week slides
Introduction to c first week slidesIntroduction to c first week slides
Introduction to c first week slides
luqman bawany
 
Abstract classes & interfaces
Abstract classes & interfacesAbstract classes & interfaces
Abstract classes & interfaces
moazamali28
 
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building BlocksOCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
İbrahim Kürce
 
Beginning Java for .NET developers
Beginning Java for .NET developersBeginning Java for .NET developers
Beginning Java for .NET developers
Andrei Rinea
 
C++ - Constructors,Destructors, Operator overloading and Type conversion
C++ - Constructors,Destructors, Operator overloading and Type conversionC++ - Constructors,Destructors, Operator overloading and Type conversion
C++ - Constructors,Destructors, Operator overloading and Type conversion
Hashni T
 
Logic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing ApplicationsLogic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing Applications
kjkleindorfer
 
Constructors
ConstructorsConstructors
Constructors
Puneet tiwari
 
OCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & StatementsOCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & Statements
İbrahim Kürce
 

What's hot (20)

Java Tutorial Lab 4
Java Tutorial Lab 4Java Tutorial Lab 4
Java Tutorial Lab 4
 
Java8 features
Java8 featuresJava8 features
Java8 features
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference Card
 
Framework Design Guidelines
Framework Design GuidelinesFramework Design Guidelines
Framework Design Guidelines
 
Advanced c#
Advanced c#Advanced c#
Advanced c#
 
The Ring programming language version 1.5.1 book - Part 68 of 180
The Ring programming language version 1.5.1 book - Part 68 of 180The Ring programming language version 1.5.1 book - Part 68 of 180
The Ring programming language version 1.5.1 book - Part 68 of 180
 
C++
C++C++
C++
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and Classes
 
Basics of java (1)
Basics of java (1)Basics of java (1)
Basics of java (1)
 
Java Introduction Workshop Day 2
Java Introduction Workshop Day 2 Java Introduction Workshop Day 2
Java Introduction Workshop Day 2
 
Exception handling
Exception handlingException handling
Exception handling
 
QSpiders - Major difference
QSpiders - Major differenceQSpiders - Major difference
QSpiders - Major difference
 
Introduction to c first week slides
Introduction to c first week slidesIntroduction to c first week slides
Introduction to c first week slides
 
Abstract classes & interfaces
Abstract classes & interfacesAbstract classes & interfaces
Abstract classes & interfaces
 
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building BlocksOCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
 
Beginning Java for .NET developers
Beginning Java for .NET developersBeginning Java for .NET developers
Beginning Java for .NET developers
 
C++ - Constructors,Destructors, Operator overloading and Type conversion
C++ - Constructors,Destructors, Operator overloading and Type conversionC++ - Constructors,Destructors, Operator overloading and Type conversion
C++ - Constructors,Destructors, Operator overloading and Type conversion
 
Logic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing ApplicationsLogic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing Applications
 
Constructors
ConstructorsConstructors
Constructors
 
OCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & StatementsOCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & Statements
 

Similar to JAVA VIRTUAL MACHINE

#_ varible function
#_ varible function #_ varible function
#_ varible function
abdullah al mahamud rosi
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
Partnered Health
 
Java
JavaJava
Module 1.pptx
Module 1.pptxModule 1.pptx
Module 1.pptx
YakaviBalakrishnan
 
Core Java Concepts
Core Java ConceptsCore Java Concepts
Core Java Concepts
mdfkhan625
 
PROGRAMMING IN JAVA
PROGRAMMING IN JAVAPROGRAMMING IN JAVA
PROGRAMMING IN JAVA
SivaSankari36
 
Oops
OopsOops
Java
JavaJava
Adv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdfAdv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdf
KALAISELVI P
 
Core java
Core javaCore java
Core java
Shivaraj R
 
Core java
Core javaCore java
Core java
Sun Technlogies
 
Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
agorolabs
 
Java Tutorial
Java Tutorial Java Tutorial
Java Tutorial
Akash Pandey
 
Exception Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception HandlingException Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception Handling
AboMohammad10
 
Control structures functions and modules in python programming
Control structures functions and modules in python programmingControl structures functions and modules in python programming
Control structures functions and modules in python programming
Srinivas Narasegouda
 
Class introduction in java
Class introduction in javaClass introduction in java
Class introduction in java
yugandhar vadlamudi
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptx
Epsiba1
 
JAVA(module1).pptx
JAVA(module1).pptxJAVA(module1).pptx
JAVA(module1).pptx
SRKCREATIONS
 
BCA Class and Object (3).pptx
BCA Class and Object (3).pptxBCA Class and Object (3).pptx
BCA Class and Object (3).pptx
SarthakSrivastava70
 

Similar to JAVA VIRTUAL MACHINE (20)

#_ varible function
#_ varible function #_ varible function
#_ varible function
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
 
Java
JavaJava
Java
 
Module 1.pptx
Module 1.pptxModule 1.pptx
Module 1.pptx
 
Core Java Concepts
Core Java ConceptsCore Java Concepts
Core Java Concepts
 
PROGRAMMING IN JAVA
PROGRAMMING IN JAVAPROGRAMMING IN JAVA
PROGRAMMING IN JAVA
 
Oops
OopsOops
Oops
 
Java
JavaJava
Java
 
Adv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdfAdv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdf
 
Core java
Core javaCore java
Core java
 
Core java
Core javaCore java
Core java
 
Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
 
Java Tutorial
Java Tutorial Java Tutorial
Java Tutorial
 
Exception Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception HandlingException Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception Handling
 
Control structures functions and modules in python programming
Control structures functions and modules in python programmingControl structures functions and modules in python programming
Control structures functions and modules in python programming
 
Class introduction in java
Class introduction in javaClass introduction in java
Class introduction in java
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptx
 
core java
core javacore java
core java
 
JAVA(module1).pptx
JAVA(module1).pptxJAVA(module1).pptx
JAVA(module1).pptx
 
BCA Class and Object (3).pptx
BCA Class and Object (3).pptxBCA Class and Object (3).pptx
BCA Class and Object (3).pptx
 

Recently uploaded

Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 

Recently uploaded (20)

Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 

JAVA VIRTUAL MACHINE

  • 1. Java Virtual Machine (JVM) By: Prof. Ansari Aadil S. 1 Prof. Aadil Ansari
  • 2. Basic Introduction to JVM • Java Virtual Machine is a set of software & program components. As name suggests, it is a virtual computer that resides within real computer. • Java can achieve platform independent feature due to JVM. • When we want to write java program, we write the source code into notepad & store it in the file having extension .java Prof. Aadil Ansari
  • 3. Continue.. • The .java file is compiled using javac compiler. On compilation a .class file gets generated. This class file is actually a byte code. • JVM takes byte code as an input, reads it, interprets it & then execute it. • JVM can generate output corresponding to the underlying operating system. Prof. Aadil Ansari
  • 4. JVM act as an Mediator between OS & Java Text Editor Java Source Code javac Byte code(.class File) Windows Mac Linux Run using java Compile using javac Java Virtual Machine Prof. Aadil Ansari
  • 9. • System.out.print(“Hello”); • System.out.print(“n”); • System.out.print(“Java!”); print( )method //print and wait println( )method //print a line and move to the next line • System.out.println(“Hello”); • System.out.println(“Java!”); Prof. Aadil Ansari
  • 10. Classes • A class is a collection of fields (data) and methods (procedure or function) that operate on that data. • The basic syntax for a class definition: • For Example:- class Rectangle { // my Rectangle class } class classname [extends SuperClassName] { [fields declaration] [methods declaration] } Prof. Aadil Ansari
  • 11. Adding Variables: Class Rectangle with fields • Add variables • The fields (data) are also called the instance variables. class Rectangle { int length; // Data fields OR instance Variables float width; } Prof. Aadil Ansari
  • 12. Adding Methods • Methods are declared inside the body of the class but immediately after the declaration of instance variable. • The general form of a method declaration is: type methodname (parameter-list) { Method-body; } Prof. Aadil Ansari
  • 13. Adding Methods to Class Rectangle class Rectangle { int length; float width; void getData(int x, float y) //Method declaration { length =x; width= y; } } Method Body Prof. Aadil Ansari
  • 14. Constructor • Constructor is a special method with same name as it’s class name • No return type for constructor. Not even void • Constructors are implicitly called when objects are created • A constructor without input parameter is default constructor • Constructor can be overloaded Prof. Aadil Ansari
  • 15. class Student4 • { int id; String name; Student4(int i,String n) //constructor { id = i; name = n; } void display() { System.out.println(id+" "+name); } public static void main(String args[]) { Student4 s1 = new Student4(111,"Karan"); Student4 s2 = new Student4(222,"Aryan"); s1.display(); s2.display(); }Prof. Aadil Ansari
  • 16. • Output: 111 Karan 222 Aryan Prof. Aadil Ansari
  • 17. Creating objects of a class • Objects in java are created using new operator. • The new operator creates an object of specified class & returns a reference of that object. • For Example:- Rectangle rect1; rect1 = new Rectangle(); Prof. Aadil Ansari
  • 18. Continue..  Both the statement can be combined into one as shown below. Rectangle rect1 = new Rectangle();  The method Rectangle() is default constructor of class. We can create any number of objects of Rectangle class. Rectangle rect1 = new Rectangle(); Rectangle rect2 = new Rectangle(); Prof. Aadil Ansari
  • 20. Exception handling & Error • Signal occurs when some unusual condition occurs. • Various types of signals are Exceptions, Errors, Interrupts & Controls. • Exception:- Appropriate execution is raised when some unusual condition occurs. • Errors:- Compile time error. Prof. Aadil Ansari
  • 21. Continue • Exception Handling:-The statements that are likely to cause an exception are enclosed within a try block. • There is another block defined by keyword catch which responsible for handling the exception thrown by the try block. • The catch is added immediately after the try block. Prof. Aadil Ansari
  • 22. General syntax of try & catch try { // exception get generated here. } catch(Type_of_Exception e) { // exception is handled here } Prof. Aadil Ansari
  • 23. For Example:- class RunErrDemo { public static void main(String arg[]) { int a,b,c; a= 10, b=0; try { c = a/b; //Exception occurs because the element is divided by 0 } Prof. Aadil Ansari
  • 24. Program continue.. catch(ArithmeticException e) { System.out.println(“You cannot divide by Zero”); } System.out.println(“ The value of a:” +a); System.out.println(“The value of b:”+b); } } Prof. Aadil Ansari
  • 25. Output for above program is You cannot divide by Zero The value of a: 10 The value of b: 0 Prof. Aadil Ansari
  • 27. • Thank You Prof. Aadil Ansari