Java Runtime Environment (JRE)

Java Runtime Environment (JRE) is a set of software tools for the development of Java applications. It combines Java Virtual Machine (JVM), and platform core classes and auxiliary libraries. JRE is a part of the Java Development Kit (JDK), but it can be downloaded separately.

JRE was originally developed by the Sun Microsystems., a wholly-owned subsidiary of Oracle Corporation. Available for many computer platforms including JRE Mac, and Windows, and Unix

If JRE is not installed on the computer, then Java programs can not be recognized by the operating system and will not run.

JRE software provides a runtime environment in which Java programs can be executed, such as software programs that have been compiled solely for computer processors. JRE software is available as both a standalone environment and a web browser plug-in, which allows Java applet to run in a web browser. jre-architecture A Java Runtime Environment performs the following main tasks respectively.

  • Loads the class
  • Verifies the byte-code
  • Interprets the byte-code

Class Loader

Class loader loads all the class files needed to execute the program. The class loader secures the program by separating the namespace from classes available locally for the classes received through the network. Once the byte-code has been successfully loaded, the next step is the byte-code verifier byte-code verifier.

Byte-code Verifier

The byte-code verifier verifies the byte code to see if any security problems are there in the code. It checks the byte code and ensures the followings.

  • Code adheres to JVM specifications.
  • There is no unauthorized access to memory.
  • Code does not cause any heap overflow.
  • There is no invalid data conversion in code like float for object references

Once this code has been verified and proven that there is no security problem with the code, JVM will convert the byte code to the machine code which will be executed directly by the machine in which the Java program runs.

Just in time (JIT) compiler

When Java program is executed, byte code is interpreted by JVM. But this interpretation is a slow process. To overcome this difficulty, the Jere Component JIT compiler is included. JIT makes execution faster

If the JIT compiler library is present, when a special bytecode is executed for the first time, JIT compliance compiles it into native machine code that can be run directly by the Java machine. Once the byte code is compiled by the JIT compiler, the required execution time will be very low. This compilation occurs when the byte code is being executed and hence the name "Just in Time"

Once the bytecode is compiled into that particular machine code, it is cached by the JIT compiler and will be reused for future needs. Therefore, the main performance improvement can be seen using the JIT compiler when the same code is repeatedly executed because JIT uses the machine code which is cached and stored.

Java Virtual Machine (JVM)

Java Virtual Machine (JVM) is part of the Java Runtime Environment (JRE). JVM (Java Virtual Machine) is an abstract machine. It is a specification that Java, compiler and interpreter comply to ensure safe, portable program and runtime environment.

JVM provides a strict set of rules that can be used by the developer to implement a native interpreter that runs Java code on any machine. This is a logical machine rather than a hardware.

JVMs are available for many hardware and software platforms. JVM, JRE and JDK depend on the platform because the configuration of each OS is different. However, Java platform is free.

The JVM performs following main tasks:

  • Loads code
  • Verifies code
  • Executes code

When running a Java Virtual Machine program, it requires memory to store many things, including other information extracted from the bitcodes and loaded class files, programs instant objects, parameters of the parameters, return value, Includes intermediate results of local variables and computations.

Java virtual machine organizes the memory needed to execute the program in many runtime data areas.

  • Register Set
  • Instruction Set
  • Stack
  • Garbage Collected Heap
  • Constant Pool
  • Method Area
  • Native Method Stack
runtime-data-areas

Register set

Registrars of Java Virtual Machine are similar to registers in our computers. However, because the virtual machine is based on a heap, its registers are not used to pass or obtain logic.

In Java, the registers hold the position of the machine, and to maintain that condition, each row of the byte code is updated after execution.

The following four registers hold the state of the virtual machine:

  • Frame: Reference frame, and an indicator for the execution environment of the current method is included.
  • Optop: Operands Top, and Operands Stack have a pointer at the top, and is used to evaluate arithmetic expressions
  • Pc: Program counter, and the next byte code address to execute is included.
  • Vars: The variable register, and contains is a pointer to local variables

All these registrars are 32-bit wide, and are allocated immediately. This is possible because the compiler knows the size of the local variable and the operand stack, and because the interpreter knows the size of the execution environment

Instruction Set

When Java code is compiled, it is converted to byte-code, which is similar to assembly language created by C and C ++ compilers.

Each instruction in the byte-code has an opode followed by an operand.

The following list contains examples of the OPCode and their description:

  • Iload: loads an integer
  • Aload: loads a pointer
  • Ior: logically or two integer

Opcodes are represented by 8-bit numbers. Operations vary in length. They are alliances with eight bits, and therefore, large operations with eight bits are divided into multiple bytes.

The reason for using such a small memory space is to maintain the compactness of memory. The Java team felt that the compact code was worth a hit on CPU when looking for each instruction.

A hit that results in the inability of the interpreter to decide that each instruction is due to the different length of instructions.

This decision retrieves lost performance because the compact byte-code travels over the network faster than the codes found in other programming languages, where unused memory space is free as a result of large.

Fixed instructions length Of course, the code with fixed instruction length runs faster on the CPU because interpreter can jump through directions, expect their length and exact locations.

Instruction set provides specification for opcode and operand syntax and value, and identifier values. It includes instructions for methods of methods

Stack

During execution of Java stack methods, the existing parameter provides byte-code. Each style of the classroom is assigned a stack frame that is stored in the Java stack. Each stack frame has the local variable, operand stack and current state of the execution environment.

The local variable for the method is stored in the array of 32-bit variables indexed by the vars register.

Large variables are divided into two local variables. When local variables are used, they are loaded on the operand stack for the method.

Operand Stack is 32-bit earlier, the first out (FIFO) stack that stores operators for the Opcodes in JVM Instruction set. These operands are used in both the parameters of the instructions as well as in the results of the instructions.

The execution environment provides information about the current state of the method in Java stack.

It stores pointers to previous method, pointers to its local variables, and pointers to the top and bottom of the operand stack. It might also be contain debugging information.

Garbage Collected Heap

Each program running in the Java Runtime Environment contains a garbage-stacked pile. Since the examples of class objects are allocated from this stack, another word for the heap is memory allocation pool. By default, the size of the stack on most systems is set to 1MB

Although the heap is set to a specific size when we start a program, it can grow, for example, when new objects are allocated. To ensure that the heap does not get too large, objects that are no longer in use are automatically DE allocated or garbage-collected by the Java Virtual Machine.

Java stores automatic garbage as background garbage. Each thread running in the Java runtime environment has two stacks attached to it: the first stack is used for Java code; The second is used for the C code.

The memory used by these piles is drawn from the total system memory pool. Whenever a new thread starts execution, it is assigned a maximum stack size for the Java code and for the C code.

By default, on most systems, the maximum size of the Java code stack is 400KB, and the maximum size of the C code stack is 128KB.

If our system has memory limitations, then we can force Java to perform more aggressive cleaning and thus reduce the total amount of memory used. To do this, reduce the maximum size of the Java and C code stacks. If our system has a lot of memory, then we can force Java to perform less aggressive cleaning, thus reducing the amount of background processing. To do this, increase the maximum size of the Java and C code stacks

Constant Pool

There is constant pool associated with it in each class in the heap. Because the constants do not change, they are usually made at compile time. Items in the constant pool encode all the names used by any method in a particular category.

How many constants exist in the class, and an offset is present in which it has been specified that where a specific list of constants in the class description starts from

Method Area

Method area is a not heap area in JVM. The Java method is stored in all the bytecode method fields. It also stores symbolic tables for dynamic linking and additional debugging information associated with the classes.

Native Method Stack

In addition to all runtime data areas as defined by the Java Virtual Machine Specification and previously described, a running Java application can be used by native methods or other data fields created for it. When a thread calls the original method, then it enters into a new world, in which the structure and security restrictions of the Java virtual machine no longer obstruct its independence.

An original method can access the runtime data areas of the virtual machine (this depends on the basic method interface), but it can do anything else. It can use the registers inside the original processor, allocate memory to any original heap, or use any type of stack.

Native methods are inherently implementation dependent. Implementation designers are free to decide what mechanisms they will use to enable a Java application running on their implementation to invoke native methods.

Java Development Kit

As a mechanic need a set of tools for repairing machines, a student needs stationary for study and a sportsman need sports related tools such as bat, ball, hockey sticks etc. Similarly a software developer need a set of tools for developing a software.

JDK stands for Java Development Kit, It is a program development environment for writing Java applets and applications.

It consists of a runtime environment that "sits on top" of the operating system layer as well as the tools for programming that developers need to compile, debug, and run applets and applications written in the Java language. JDK provides tool such as Javac compiler, Java Interpreter, Javadoc documentation generator tool, jar and other tool which are needed for programming.

For creating java application JDK must be installed and configured in the system.

Creating First Java Program

Let us look at the steps involved in creating and executing our first java program.

  • Download and Install the JDK in the System.
  • Set the path for compiler and Interpreter.
  • Create a java program.
  • Compile the java program.
  • Run the java program.

Open any basic text editor such as notepad and type the following program.


Class First {
	Public static void main(String args[]) {
		System.out.println("This is my first java program.");
	}
}				

Now save the above program with the name First.java in any local hard drive (such as C or D).

To compile and run the program open command prompt (go to run and type cmd then press ok). And move to location where you have saved your java program using CD command.

Then set the path for the compiler and interpreter ( path="c:\program files\java\jdk1.7\bin") which may differ on the basis of operating system and JDK installed.


To Compile: - javac First.java 
To Run:- java First 				


Understanding First Java Program.

  • class :- It is a keyword in java which is used to create a class in java program.
  • First :- It is the name of our class.
  • public :- It is an access modifier which determines the visibility. It means it is visible to all.
  • static :- It is a keyword in java. If we declare any method or variable with static keyword they are called as static methods or variables. The core advantage of static method is that there is no need to create object to invoke the static method. The main method is executed by the JVM, so it doesn't require to create object to invoke the main method. So it saves memory.
  • void :- It is a return type of a method which means nothing. Any method with the return type doesn’t return any value.
  • main :- It is an entry and exit point of any program. A program must have one main method. The program execution starts from the main.
  • String args[] :- It is used for command line argument.
  • System.out.println() :- It is used to print the statement on the screen.

About Author

Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.

Share this Article Facebook
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions

Recent Addition

new tutorial Protractor Online Training : We have closed registration for training

Please do email to chercher.tech@gmail.com for any queries

If you already registered then please do check your email for the Webex link