0% found this document useful (0 votes)
10 views8 pages

CH 1 Java

The document provides an overview of the Java Development Kit (JDK), Java Runtime Environment (JRE), and Java Virtual Machine (JVM), explaining their roles in Java application development and execution. JDK includes development tools like compilers and debuggers, while JRE provides the environment to run Java applications, and JVM interprets bytecode into machine code. It also discusses variable types in Java, including local, instance, and static variables.

Uploaded by

amitup0227
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views8 pages

CH 1 Java

The document provides an overview of the Java Development Kit (JDK), Java Runtime Environment (JRE), and Java Virtual Machine (JVM), explaining their roles in Java application development and execution. JDK includes development tools like compilers and debuggers, while JRE provides the environment to run Java applications, and JVM interprets bytecode into machine code. It also discusses variable types in Java, including local, instance, and static variables.

Uploaded by

amitup0227
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

JDK (Java Development Kit)

Java JDK (Java Development Kit) is a software development kit for developing Java
programming applications

JDK is a superset of JRE, it contains everything that JRE has along with
development tools such as compiler, debugger etc.

1. JDK stands for Java Development Kit. To install Java on your system,
you need to first install JDK on your system.

2. JDK consists of Private JRE, JVM, compiler, Java application


launcher, Appletviewer, etc. It also provides the Standard Edition (SE)
of java API.

The JDK contains the JRE and the JRE contains the JVM virtually
The JDK consists of the JRE as well as command-line development tools like
compilers and debuggers that are required or useful when creating java
applications

JRE has an instance of JVM with it, library classes and development tools. To
understand the working of JRE let us see an example of a simple "Hello World"
program.

1. import java.util.*

2. public static void main(String[] args){

3. System.out.println(?Hello world?);

4. }

Once you write this program, you have to save it with .java extension. Compile
your program. The output of the Java compiler is a byte-code which is platform
independent. After compiling, the compiler generates a .class file which has
the bytecode. The bytecode is platform independent and runs on any device
having the JRE. From here, the work of JRE begins. To run any Java program,
you need JRE.

Features of JDK

1. It has all the java development tools such as compiler, JVM, JRE,
debugger etc.
2. You need jdk in order to write and run java program.
3. JDK supports multiple platforms and can be installed on Windows,
Mac and other operating systems.
JRE (Java Runtime Environment)
JRE is the environment within which the java virtual machine runs. JRE contains
Java virtual Machine(JVM), class libraries, and other files excluding development
tools such as compiler and debugger.
Which means you can run the code in JRE but you can’t develop and compile the
code in JRE.

1. JRE stands for Java Runtime Environment. It provides runtime


environment for java applications.
2. You need JRE in order to run java programs. If you are not a developer
and not writing java programs, you do not need JDK but you still need
JRE to run java programs.
3. All the JDK already comes with JRE so you do not need to download
and install it separately.
4. JRE contains set of libraries and other files that JVM uses at runtime.

Features of JRE

1. JRE contains set of libraries and other tools that JVM needs at
runtime.
2. You can easily run any java program on JRE but you need jdk to write
and compile java programs.
3. JRE contains libraries that are required for integrations such as Java
Database Connectivity (JDBC), Java Naming and Directory Interface
(JNDI), Remote Method Invocation (RMI) etc.
JVM (Java Virtual Machine)
Java is a high level programming language. A program written in high level
language cannot be run on any machine directly. First, it needs to be translated
into that particular machine language. The javac compiler does this thing, it
takes java program (.java file containing source code) and translates it into
machine code (referred as byte code or .class file).

The JVM is an abstract computing machine that enables a computer to run a Java
program. When you run a Java application, the JVM reads the compiled bytecode
(generated by the JDK) and interprets it into machine code for execution.

Java Virtual Machine (JVM) is a virtual machine that resides in the real machine
(your computer) and the machine language for JVM is byte code. This makes it
easier for compiler as it has to generate byte code for JVM rather than different
machine code for each type of machine. JVM executes the byte code generated
by compiler and produce output. JVM is the one that makes java platform
independent.

Features of JVM

1. JVM makes it possible to run java code on any machine, it is the JVM
that makes java truly platform independent.
2. It also allows to run java applications on cloud platforms.
3. JDK and JRE both of these contain JVM.
4. JVM is an interpreter as it executes the java code line by line.
5. JVM converts the bytecode into machine code. JVM is platform
independent as JVM doesn’t depend on the hardware and operating
system of the machine.
How JVM works?

Variable

variable is a container which holds the value while the Java program is
executed. A variable is assigned with a data type.

There are three types of Variable in Java:

1. Local Variable
2. Instance Variable
3. static Variable
2.1 Local Variable:
When we declare any variable inside any method then it is called a local
variable. Therefore, they can be used only within the method, block, not
outside the method.

Example:

public class Calculator {

public void add() {

// a,b are variables here.

int a = 5; // local variable created inside method


int b = 6; // we can't use a,b outside this method.

System.out.println(a + b);

public static void main(String[] args) {

Calculator obj = new Calculator();

obj.add();

2.2 Instance Variable:


When we declare any variable outside any method and within-class are
called Instance variables. Therefore, they can be used anywhere in the class
and can be used while creating an object.
Example:

public class Calculator {

int a = 5; // instance variable created outside method (at class level)

int b = 6; // we can use a,b anywhere in this class

public void add() {

System.out.println(a + b);

}
public static void main(String[] args) {

Calculator obj = new Calculator();

obj.add();

2.3 Static Variable:


When we define a variable, we need to add a static keyword before the
name of the variable. Therefore, we can use this variable among all the
instance of the class.
Static Variable in Java

• The static variables are those that are common to all the class instances.
• Only a single copy of the static variable is created and shared among all the class
instances.
• Because it is a class-level variable, memory allocation of such variables only happens once
when the class is loaded in the memory.
• If an object modifies the value of a static variable, the change is reflected across all objects.

Example:

public class Calculator {

static int firstNumber; // static variable created at class level with static keyword

static int secondNumber; // we can call a,b directly with class name.

// static variables are destroyed when the program ends.


public static void main(String[] args) {

Calculator.firstNumber = 5;

Calculator.secondNumber = 6;

System.out.println(firstNumber + secondNumber);

You might also like