SlideShare a Scribd company logo
1 of 10
How to run Java Program
without IDE.
How to do it!!
1. Create a folder in eg: D: (D Drive) and name it eg: (myapplication)
2. Create a source file eg: (HelloWorldApp.java) in notepad
save as Text Documents(*.txt) and keep Encoding combo box as ANSI and Save.
Code
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
3. Now you need to compile your file for that you need JRE
4. You need to set path varible i.e environment variable in order to run your program.
5. Open command prompt
cd D:
cd myapplication
set path=C:Program FilesJavajdk1.8.0.60bin;
javac HelloWorldApp.java
java -cp . HelloWorldApp
6. And here your program runs.
How actually it works!!
1. Because of Software based Virtual machine that acts as run time engine to run particular
programming language application. i.e JVM(Java Virtual Machine)
2. JVM is a part of JRE and it is responsible to load and run the java class file.
3. While working with command prompt we need to invoke the Java compiler by supplying javac
command where it comes in contact with JDK(Java Devlopment Kit)
4. JDK is a bundle software needed for developing Java Application. It has (JRE, set of API classes, Java
Compiler, Webstart and additionalfiles needed to write Java Applets and applications)
5. Java directly do not execute Java program- that job is only of JVM(Java Virtual Machine).
6. However, the Java virtual machine cannot execute .java files directly. The compiler's job is to
translate Java source files into "class files" that the virtual machine can execute.
7. Now if you need to compile multiple .java files together, then its possible by just "javac
HelloWorldApp.java one.java two.java" or "javac *.java".
8. And one more thing, Java compiler doesn't create an object file, but instead it creates a bytecode
file which is, essentially, an object file for a virtual machine.
9. However, bytecode is not an executable file.
To execute a bytecode file, you actually need to invoke a Java interpreter (called java).
Every platform has its own Java interpreter which will automatically address the platform-specific
issues that can no longer be put off.
When platform-specific operations are required by the bytecode, the Java interpreter links in
appropriate code specific to the platform.
Loading of Classes and Interfaces
Loading means read .class file from hard disk and store
corresponding binary data inside method area of JVM.
For each .class file JVM will store following information
1. Fully qualified name of class
2. Fully qualified name of immediate parent
3. Whether .class file represents class|interface|enum
4. Methods|Constructors|Variables information
5. Modifiers information
6. Constant Pool information
Linking of Classes and Interfaces
After “loading” activity JVM immediately perform Linking activity. Linking once again contain 3
activities,
1. Verification
in java .class files we never getting these alert messages.
What is the reason is inside JVM a special component is there i.e., Byte Code Verifier.
This Byte Code Verifier is responsible to verify weather .class file is properly formatted or not,
structurally correct or not, generated by valid compiler or not. If the .class file is not generated by
valid compiler then Byte Code Verifier raises runtime error java.lang.VerifyError.
This total process is done in verification activity.
2. Preparation
In preparation phase, JVM will allocate memory for class level static variables and assigned default
values.
E.g. For int ---> 0, For double ---> 0.0, For boolean ---> false
Here just default values will be assigned and original values will be assigned in initialization phase.
3. Resolution
Next phase is Resolution.
It is the process of replacing all symbolic references used in our class with original direct references
from method area.
Run Java Program - Initialization
• In Initialization activity, for class level static variables assigns
original values and static blocks will be executed from top to
bottom.
• While Loading, Linking and Initialization if any error occurs
then we will get runtime Exception saying
java.lang.LinkageError. Previously we discussed about
VerifyError. This is the child class of LinkageError.
Types of class loaders in class loader
subsystem
1. Bootstrap class loader/ Primordial class loader
Bootstrap class loader is responsible for to load classes from bootstrap class path.
Here bootstrap class path means, usually in java application internal JVM uses rt.jar.
All core java API classes like String class, StringBuilder class, StringBuffer class, java.lang packages,
java.io - enthusiast about java & open-source? packages etc are available in rt.jar.
This rt.jar path is known as bootstrap class path and the path of rt.jar is
jdk --> jre --> lib --> rt.jar
This location by default consider as bootstrap class path.
This Bootstrap class loader is responsible for loading all the classes inside this rt.jar.
This Bootstrap class loader is implemented not in java it is implemented by native languages like C,
C++ etc.
2. Extension class loader
The extension class loader is the child of bootstrap class loader. This class loader is responsible to
load classes from extension class path
jdk --> jre --> lib-->ext -->*.jar
The extension class loader is responsible for loading all the classes present in the ext folder.
This Extension class loader is implemented in java only. The class name of extension class loader is
sun.misc.Launcher$ExtClassLoader.class
3. Application class loader/System class loader
The Application class loader is the child of Extension class loader.
This class loader is responsible to load classes from Application class path.
Application class path means classes in our application (Environment variable class path).
It internally uses environment vatiable path. This Application class loader is implemented in java
only.
The class name of extension class loader is
sun.misc.Launcher$AppClassLoader.class
Example
public class LoaderTest {
public static void main(String[] args) {
System.out.println(String.class.getClassLoader());
System.out.println(Employee123.class.getClassLoader());
System.out.println(LoaderTest.class.getClassLoader());
}
}
Output:
null // Because Bootstrap class loader is not java object it is designed with
C or C++
sun.misc.Launcher$ExtClassLoader@33909752 //Here i am created class
Employee123 and create jar for this class and put in ext folder
sun.misc.Launcher$AppClassLoader@73d16e93
Run Java Program - Invoking HelloWorld.main
Thank You!!

More Related Content

What's hot

Token Authentication in ASP.NET Core
Token Authentication in ASP.NET CoreToken Authentication in ASP.NET Core
Token Authentication in ASP.NET CoreStormpath
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBhargav Anadkat
 
What is dotnet (.NET) ?
What is dotnet (.NET) ?What is dotnet (.NET) ?
What is dotnet (.NET) ?Talha Shahzad
 
What Is Virtual DOM In React JS.pptx
What Is Virtual DOM In React JS.pptxWhat Is Virtual DOM In React JS.pptx
What Is Virtual DOM In React JS.pptxAkrati Rawat
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node jsAkshay Mathur
 
Introduction To Single Page Application
Introduction To Single Page ApplicationIntroduction To Single Page Application
Introduction To Single Page ApplicationKMS Technology
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applicationshchen1
 
IRJET- Fake Profile Identification using Machine Learning
IRJET-  	  Fake Profile Identification using Machine LearningIRJET-  	  Fake Profile Identification using Machine Learning
IRJET- Fake Profile Identification using Machine LearningIRJET Journal
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Adnan Sohail
 

What's hot (20)

Token Authentication in ASP.NET Core
Token Authentication in ASP.NET CoreToken Authentication in ASP.NET Core
Token Authentication in ASP.NET Core
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPM
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
What is dotnet (.NET) ?
What is dotnet (.NET) ?What is dotnet (.NET) ?
What is dotnet (.NET) ?
 
Next.js - ReactPlayIO.pptx
Next.js - ReactPlayIO.pptxNext.js - ReactPlayIO.pptx
Next.js - ReactPlayIO.pptx
 
What Is Virtual DOM In React JS.pptx
What Is Virtual DOM In React JS.pptxWhat Is Virtual DOM In React JS.pptx
What Is Virtual DOM In React JS.pptx
 
Java Basics
Java BasicsJava Basics
Java Basics
 
jQuery Ajax
jQuery AjaxjQuery Ajax
jQuery Ajax
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
 
Introduction To Single Page Application
Introduction To Single Page ApplicationIntroduction To Single Page Application
Introduction To Single Page Application
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
C# REST API
C# REST APIC# REST API
C# REST API
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
 
core java
core javacore java
core java
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
 
IRJET- Fake Profile Identification using Machine Learning
IRJET-  	  Fake Profile Identification using Machine LearningIRJET-  	  Fake Profile Identification using Machine Learning
IRJET- Fake Profile Identification using Machine Learning
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 

Similar to How to run java program without IDE

Lecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVMLecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVMmanish kumar
 
Unit of competency
Unit of competencyUnit of competency
Unit of competencyloidasacueza
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionGanesh Samarthyam
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)Prof. Erwin Globio
 
Java Interview Questions Answers Guide
Java Interview Questions Answers GuideJava Interview Questions Answers Guide
Java Interview Questions Answers GuideDaisyWatson5
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javajayc8586
 
Java programming material for beginners by Nithin, VVCE, Mysuru
Java programming material for beginners by Nithin, VVCE, MysuruJava programming material for beginners by Nithin, VVCE, Mysuru
Java programming material for beginners by Nithin, VVCE, MysuruNithin Kumar,VVCE, Mysuru
 
Introduction to java programming tutorial
Introduction to java programming   tutorialIntroduction to java programming   tutorial
Introduction to java programming tutorialjackschitze
 

Similar to How to run java program without IDE (20)

JAVA Program Examples
JAVA Program ExamplesJAVA Program Examples
JAVA Program Examples
 
Core java introduction
Core java introduction Core java introduction
Core java introduction
 
B.Sc. III(VI Sem) Advance Java Unit2: Appet
B.Sc. III(VI Sem) Advance Java Unit2: AppetB.Sc. III(VI Sem) Advance Java Unit2: Appet
B.Sc. III(VI Sem) Advance Java Unit2: Appet
 
Lecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVMLecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVM
 
Jvm internal detail
Jvm internal detailJvm internal detail
Jvm internal detail
 
02 basic java programming and operators
02 basic java programming and operators02 basic java programming and operators
02 basic java programming and operators
 
Unit of competency
Unit of competencyUnit of competency
Unit of competency
 
1.introduction to java
1.introduction to java1.introduction to java
1.introduction to java
 
Java Intro
Java IntroJava Intro
Java Intro
 
Java JDK.docx
Java JDK.docxJava JDK.docx
Java JDK.docx
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - Description
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)
 
Java introduction
Java introductionJava introduction
Java introduction
 
Java Interview Questions Answers Guide
Java Interview Questions Answers GuideJava Interview Questions Answers Guide
Java Interview Questions Answers Guide
 
JAVA for Every one
JAVA for Every oneJAVA for Every one
JAVA for Every one
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Java programming material for beginners by Nithin, VVCE, Mysuru
Java programming material for beginners by Nithin, VVCE, MysuruJava programming material for beginners by Nithin, VVCE, Mysuru
Java programming material for beginners by Nithin, VVCE, Mysuru
 
Introduction to java programming tutorial
Introduction to java programming   tutorialIntroduction to java programming   tutorial
Introduction to java programming tutorial
 
Basic Java I
Basic Java IBasic Java I
Basic Java I
 
Java basic
Java basicJava basic
Java basic
 

Recently uploaded

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
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
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
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
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
+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
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 

How to run java program without IDE

  • 1. How to run Java Program without IDE.
  • 2. How to do it!! 1. Create a folder in eg: D: (D Drive) and name it eg: (myapplication) 2. Create a source file eg: (HelloWorldApp.java) in notepad save as Text Documents(*.txt) and keep Encoding combo box as ANSI and Save. Code /** * The HelloWorldApp class implements an application that * simply prints "Hello World!" to standard output. */ class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); // Display the string. } } 3. Now you need to compile your file for that you need JRE 4. You need to set path varible i.e environment variable in order to run your program. 5. Open command prompt cd D: cd myapplication set path=C:Program FilesJavajdk1.8.0.60bin; javac HelloWorldApp.java java -cp . HelloWorldApp 6. And here your program runs.
  • 3. How actually it works!! 1. Because of Software based Virtual machine that acts as run time engine to run particular programming language application. i.e JVM(Java Virtual Machine) 2. JVM is a part of JRE and it is responsible to load and run the java class file. 3. While working with command prompt we need to invoke the Java compiler by supplying javac command where it comes in contact with JDK(Java Devlopment Kit) 4. JDK is a bundle software needed for developing Java Application. It has (JRE, set of API classes, Java Compiler, Webstart and additionalfiles needed to write Java Applets and applications) 5. Java directly do not execute Java program- that job is only of JVM(Java Virtual Machine). 6. However, the Java virtual machine cannot execute .java files directly. The compiler's job is to translate Java source files into "class files" that the virtual machine can execute. 7. Now if you need to compile multiple .java files together, then its possible by just "javac HelloWorldApp.java one.java two.java" or "javac *.java". 8. And one more thing, Java compiler doesn't create an object file, but instead it creates a bytecode file which is, essentially, an object file for a virtual machine. 9. However, bytecode is not an executable file. To execute a bytecode file, you actually need to invoke a Java interpreter (called java). Every platform has its own Java interpreter which will automatically address the platform-specific issues that can no longer be put off. When platform-specific operations are required by the bytecode, the Java interpreter links in appropriate code specific to the platform.
  • 4. Loading of Classes and Interfaces Loading means read .class file from hard disk and store corresponding binary data inside method area of JVM. For each .class file JVM will store following information 1. Fully qualified name of class 2. Fully qualified name of immediate parent 3. Whether .class file represents class|interface|enum 4. Methods|Constructors|Variables information 5. Modifiers information 6. Constant Pool information
  • 5. Linking of Classes and Interfaces After “loading” activity JVM immediately perform Linking activity. Linking once again contain 3 activities, 1. Verification in java .class files we never getting these alert messages. What is the reason is inside JVM a special component is there i.e., Byte Code Verifier. This Byte Code Verifier is responsible to verify weather .class file is properly formatted or not, structurally correct or not, generated by valid compiler or not. If the .class file is not generated by valid compiler then Byte Code Verifier raises runtime error java.lang.VerifyError. This total process is done in verification activity. 2. Preparation In preparation phase, JVM will allocate memory for class level static variables and assigned default values. E.g. For int ---> 0, For double ---> 0.0, For boolean ---> false Here just default values will be assigned and original values will be assigned in initialization phase. 3. Resolution Next phase is Resolution. It is the process of replacing all symbolic references used in our class with original direct references from method area.
  • 6. Run Java Program - Initialization • In Initialization activity, for class level static variables assigns original values and static blocks will be executed from top to bottom. • While Loading, Linking and Initialization if any error occurs then we will get runtime Exception saying java.lang.LinkageError. Previously we discussed about VerifyError. This is the child class of LinkageError.
  • 7. Types of class loaders in class loader subsystem 1. Bootstrap class loader/ Primordial class loader Bootstrap class loader is responsible for to load classes from bootstrap class path. Here bootstrap class path means, usually in java application internal JVM uses rt.jar. All core java API classes like String class, StringBuilder class, StringBuffer class, java.lang packages, java.io - enthusiast about java & open-source? packages etc are available in rt.jar. This rt.jar path is known as bootstrap class path and the path of rt.jar is jdk --> jre --> lib --> rt.jar This location by default consider as bootstrap class path. This Bootstrap class loader is responsible for loading all the classes inside this rt.jar. This Bootstrap class loader is implemented not in java it is implemented by native languages like C, C++ etc.
  • 8. 2. Extension class loader The extension class loader is the child of bootstrap class loader. This class loader is responsible to load classes from extension class path jdk --> jre --> lib-->ext -->*.jar The extension class loader is responsible for loading all the classes present in the ext folder. This Extension class loader is implemented in java only. The class name of extension class loader is sun.misc.Launcher$ExtClassLoader.class 3. Application class loader/System class loader The Application class loader is the child of Extension class loader. This class loader is responsible to load classes from Application class path. Application class path means classes in our application (Environment variable class path). It internally uses environment vatiable path. This Application class loader is implemented in java only. The class name of extension class loader is sun.misc.Launcher$AppClassLoader.class
  • 9. Example public class LoaderTest { public static void main(String[] args) { System.out.println(String.class.getClassLoader()); System.out.println(Employee123.class.getClassLoader()); System.out.println(LoaderTest.class.getClassLoader()); } } Output: null // Because Bootstrap class loader is not java object it is designed with C or C++ sun.misc.Launcher$ExtClassLoader@33909752 //Here i am created class Employee123 and create jar for this class and put in ext folder sun.misc.Launcher$AppClassLoader@73d16e93 Run Java Program - Invoking HelloWorld.main