Java is a high-level object-oriented programming language developed by James Gosling and Patrick Naughton. It is one of the most widely used programming languages in the world, thanks to its scalability, rigor and portability. These characteristics mean that it is frequently used to develop a wide range of applications, from desktop to mobile and Web applications. Its syntax is close to that of C++, but has been refined in comparison with the latter.
To understand the basics of Java, it’s essential to become familiar with key concepts such as the Java Development Kit (JDK), the Java Runtime Environment (JRE) and the Java Virtual Machine (JVM). In this article, we’ll explore these fundamental elements of Java and explain how they interact to enable the execution of Java programs.
What is the Java Development Kit (JDK)?
A. JDK overview: Roles and functions in the Java environment
The Java Development Kit (JDK) is a set of essential tools for developing Java applications. It provides a complete environment for writing, compiling, debugging and executing Java programs (cf. I.B). The tools provided by the JDK are generally found in all software development environments.
B. JDK components
1. The Java compiler (javac)
Java is an interpreted language, which means it cannot be executed directly by the operating system. To run a Java program, you have to go through another program called the interpreter. The interpreter reads a bytecode file, which is the result of compiling the Java source code.
The Java compiler, part of the JDK, plays an essential role in this process. It takes the Java source code and converts it into Java bytecode that can be understood by the Java Virtual Machine (JVM). The compiler checks syntax, types and performs optimizations during compilation.
Bytecode is the intermediate code between machine instructions and source code. Thus, to run a Java program, the source code is compiled by the javac compiler into bytecode, which is saved in a file with a .class extension. This bytecode is not directly usable, but must be interpreted by the JVM, which transforms it into machine code that can be understood by the operating system. This is why Java is considered a portable language, since the bytecode remains the same whatever the execution environment.
2. Standard libraries (Java Class Library)
The JDK includes an extensive library of predefined classes, known as the Java Class Library. These libraries offer a wide range of ready-to-use features, such as string management, file operations, graphical interfaces, network connections and more.
A large number of classes, provided by Java SE, implement generic data and processing that can be used by a wide range of applications. These classes form the API (Application Programmer Interface) of the Java language. All these classes are organized into packages (or libraries) dedicated to a specific theme.
Among the most widely used packages are the following:
- java.awt: graphical and interface management classes
- java.io: input/output management
- java.lang: basic classes (imported by default)
- java.util: utility classes
- javax.swing: other graphical classes
3. Development tools
The JDK offers a range of development tools to facilitate the process of creating Java applications. These include the debugger (jdb) for identifying and correcting errors, and the documentation generator (javadoc) for creating developer-readable documentation.
Java Runtime Environment (JRE) overview
A. Understanding the JRE
1. Definition and role of the JRE in Java program execution
The Java Runtime Environment (JRE) is the runtime environment required to run Java applications. It includes the Java Virtual Machine (JVM), class libraries and other essential components. It supports the execution of Java programs by providing an execution platform for the JVM. It loads and executes Java bytecode files and provides access to the necessary class libraries.
2. Differences between JDK and JRE
The JDK includes both the JRE and development tools, while the JRE is intended for running Java applications. The JDK is used for development, while the JRE is used to run Java applications.
3. Importance du JRE
The JRE is crucial in guaranteeing the portability of Java applications. Java applications can be run on any JRE-compatible system, regardless of the underlying operating system, while the JVM is available.
B. JRE components
1. The Java Virtual Machine (JVM)
The Java Virtual Machine is the central JRE component responsible for executing Java programs. It interprets Java bytecode or compiles it into native code, depending on the specific JVM implementation. It’s important to note that the JVM is also present in the JDK, but the JRE is primarily intended for running Java applications without the additional development tools provided by the JDK.
2. JRE class libraries
The JRE contains a set of predefined class libraries. These libraries provide functionality and APIs that enable Java applications to perform common operations. These integration libraries help developers create seamless data connections between their applications and services. Some of these libraries include :
- Java IDL (CORBA), which uses the Common Object Request architecture to support distributed objects written in the Java programming language.
- Java Database Connectivity API (JDBC), which provides tools for developers to write applications with access to remote relationship databases, flat files and spreadsheets.
- Java Naming and Directory Interface (JNDI): a programming interface and directory service that enables customers to create portable applications capable of retrieving information from databases using naming conventions.
What is Java Virtual Machine (JVM)?
A. Understanding the JVM
1. Definition and role of the JVM in Java program execution
The Java Virtual Machine (JVM) is an essential component of the Java runtime environment. Its main role is to execute Java programs by converting Java bytecode into executable instructions for the underlying machine.
2. Portability and platform independence thanks to the JVM
.
The JVM enables portability of Java programs, meaning they can be run on different platforms without requiring major modifications. It provides an abstraction layer between Java code and the operating system, allowing Java programs to be platform-independent.
B. Internal operation of the JVM
1. Bytecode loading, verification and execution
.
The JVM loads the bytecode files generated by the Java compiler. It performs a rigorous check to ensure that the bytecode is safe and complies with security rules.
2. Memory management and garbage collection
.
The JVM dynamically manages memory to allocate and free the space required for program execution. It uses garbage collection to automatically reclaim memory used by objects that are no longer referenced.
a - The call stack
.
- a - The call stack
The JVM uses a call stack to manage method calls and local variables. Each method call is represented by a stack frame, which contains parameters, local variables and other information.
b - The pile (Heap)
- b - The pile (Heap)
The heap is a memory region used to allocate dynamic objects created by Java programs. It is managed by the JVM and enables objects to be created, modified and deleted at runtime.
c - Garbage Collection
- c - Garbage Collection
The JVM performs garbage collection to free memory occupied by objects that are no longer referenced. This prevents memory leaks and enables automatic memory management in Java programs.
Conclusion
In this article, we’ve explored the fundamental elements of Java, such as the JDK, the JRE and the JVM. The JDK is essential for developing Java applications, while the JRE enables these applications to run on a target machine. The JVM plays a central role by interpreting Java bytecode and providing a secure, portable runtime environment. By understanding these key concepts, you’ll be better prepared to create efficient, high-performance Java applications.
If you liked the article, and would like to learn Java, take a look at our Data Engineer course.