SlideShare a Scribd company logo
1 of 27
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 4Berk Soysal
 
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 CardHari kiran G
 
Framework Design Guidelines
Framework Design GuidelinesFramework Design Guidelines
Framework Design GuidelinesMohamed Meligy
 
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 180Mahmoud Samir Fayed
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and ClassesMichael 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 handlingMinal Maniar
 
Introduction to c first week slides
Introduction to c first week slidesIntroduction to c first week slides
Introduction to c first week slidesluqman bawany
 
Abstract classes & interfaces
Abstract classes & interfacesAbstract classes & interfaces
Abstract classes & interfacesmoazamali28
 
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 developersAndrei 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 conversionHashni 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 Applicationskjkleindorfer
 
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

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 studentsPartnered Health
 
Core Java Concepts
Core Java ConceptsCore Java Concepts
Core Java Conceptsmdfkhan625
 
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.pdfKALAISELVI P
 
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 javaagorolabs
 
Exception Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception HandlingException Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception HandlingAboMohammad10
 
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 programmingSrinivas Narasegouda
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptxEpsiba1
 
JAVA(module1).pptx
JAVA(module1).pptxJAVA(module1).pptx
JAVA(module1).pptxSRKCREATIONS
 

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

Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 

Recently uploaded (20)

Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 

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