0% found this document useful (0 votes)
0 views4 pages

How java works

The Java programming language operates in three main steps: writing source code, compiling it into bytecode, and executing it through the Java Virtual Machine (JVM). The execution process involves creating, compiling, loading, verifying, and running the program, with the JVM playing a crucial role in interpreting the bytecode. Java is considered both a compiler and interpreter-based language as it compiles source code into binary and then executes it using the JVM.
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)
0 views4 pages

How java works

The Java programming language operates in three main steps: writing source code, compiling it into bytecode, and executing it through the Java Virtual Machine (JVM). The execution process involves creating, compiling, loading, verifying, and running the program, with the JVM playing a crucial role in interpreting the bytecode. Java is considered both a compiler and interpreter-based language as it compiles source code into binary and then executes it using the JVM.
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/ 4

How Does Java Programming Language Work?

The working of the Java programming language can be summed up in three steps. Let’s go
through the steps given
below:

1. Here for the first step, we need to have a java source code otherwise we won't be able
to run the program you need to save it with the program.java extension.
2. Secondly, we need to use a compiler so that it compiles the source code which in turn
gives out the java bytecode and that needs to have a program.class extension. The
Java bytecode is a redesigned version of the java source codes, and this bytecode can
be run anywhere irrespective of the machine on which it has been built.
3. Later on, we put the java bytecode through the Java Virtual Machine which is an
interpreter that reads all the statements thoroughly step by step from the java bytecode
which will further convert it to the machine-level language so that the machine can
execute the code. We get the output only after the conversion is through.

So knowing about the working of java we need to understand the execution process of the
program written in the language.

Execution Process of Java Program


The computer does not understand our human languages and it only understands codes that
are in binary or coded form that means 0 or 1. During programming, there are a lot of steps
that it undergoes-

1. Creation of a Java Program-When we talk about creating a program or typing a


code that solves any kind of problem that we may have, it means physically writing
the program on any text editor. You may or may not edit the program after you have
written it once. When you create a program you don't just make it and let it be the way
it is you can modify it and save it on the device. But you need to save it with the java
extension otherwise it would just appear as a normal text file.

2. Compiling a Java Program-Now once the program is created and does not have
any errors or mistakes we can go ahead and compile the program when you compile a
program it means the compiler compiles the program and if there are no errors after
compiling the program we can further run it and get the desired output. We compile
the Java program in a command prompt or another console.
3. Loading the Program into the Memory by Java Virtual Machine- A lot of memory is
required by JVM when you want to load the .class file extension before the execution.
Loading is the process of placing a program in memory for it to run. The .class files are
needed by the program to execute the file.

4. Java Virtual Machine verification for bytecode- Jvm has a bytecode verifier that is
due to maintenance of the security of the program. The bytecode verifies the code
only and only after the classes have been loaded in the memory to maintain the
security of the program. It makes sure that the bytecodes are valid and accessible. It
also saves the computer from various viruses and unsecure websites.
5. Java Program Execution-The above steps are executed by JVM when it interprets
the bytecode. Earlier JVM's were slow and only interpreted one bytecode at a time.
Nowadays the modern JVM's are much faster as they use JIT(just-in-time)
compilation units. These JVMs can execute various tasks at the same time. We also
call them HotSpot compilers as they are used by JVM to find out the hot spots in our
bytecode. Later on, the source code is converted bytecode into machine language.

Let’s understand the tools that come in handy when we code in the java programming
language.

1. Java Development Kit : As the name formally states Java development kit is a full-
time kit that has a compiler, Java Runtime Environment(JRE), Debuggers, Java
documents inclusive in it. For further execution in java, we need to have JDK
installed on our computers to further lead on to the creation, compilation, and running
of the java program. Here, as we use JDK we need an environment to run the
programs.We use JRE Java Runtime Environment which provides the least
requirements to execute the java program. It provides the JVM, Core classes and
supporting files.

2. Java Virtual Machine : This generally is referred to as JVM contains three


phases that we have to follow. It is a very important part not only of JDK but also JRE
as it is inbuilt in both of the places. When you run a program using the JRE amd
JDK it also goes to the JVM as it is required to run the java program and it also
interprets the program. The phases are as follows: Compile the Code: The Java
Development Kit(JDK) provides us with the JAVAC compiler to get through with this
step. Run the Code: JVM runs the bytecode that is provided by the compiler.
3. Just in Time: Just in time, i.e JIT can be easily defined as a compiler that is
witnessed in the manufacturing workflow and it aims directly at reducing the costs
within the production systems and the flow times as well.
4. Java Runtime Environment: JDK includes JRE. Which in turn after installation
allows the java program to run. But we still can’t compile it. It has a browser,
the applet supports, and a few plugins included in it. So, to run a java program on
your respective computers you need JRE. JRE is made up of multiple elements
altogether and they are:

 Java virtual machine (JVM)


 Java class libraries
 Java class loader when our software tends to execute a particular program, it requires
some environment to run in. Usually, it’s any operating system for example, Unix,
Linux, Microsoft Windows, or the MacOS. Here our JRE acts as a translater and also
a facilitator between the java program and the operating system.

Is Java a Compiler or Interpreter Based Language?


When we talk about compilers we mean that- A tool that converts source code into machine
language making it easier for the computer to interpret it is called a compiler.

Let’s have a look at the Java interpreter- As a compiler, an interpreter is also a programming
tool that converts our source code into readable(for computers) machine code but it doesn't
work in the same way that the compiler does. It converts each statement going through it
thoroughly before moving on to the next one and then executes it. No executor is needed for
an interpreter.

hence we can conclude that we can consider java to be both compiler and interpreter based
language because the source code first gets compiled into binary code and then the same
binary code runs on the JVm (Java Virtual Machine), and this is mostly a software-based
interpreter

So since we have completely understood how the codes in java are executed let's sum
up what we just read.

You might also like