4. Steps to Create, Compile and Execute a Java Program
How does java program work
Steps to write a java program and how it is executed.
Step 1: Writing the Source Code
To create a Java program, you need an editor or an Integrated Development Environment (IDE). Some popular options include:
- Notepad
- Word
- Edit Plus
- Notepad++
- Sublime Text
- Atom
- Eclipse
- IntelliJ IDEA
- NetBeans
- Visual Studio Code (VS Code)
In the editor or IDE, you write a set of instructions using the Java programming language. This file should be saved with a .java extension. This file is known as the "source code."
Step 2: Compiling the Java Program
- Receiving The
.javafile, which contains the source code written by the programmer. - The compiler checks the source code for any syntax errors.
- If there are syntax errors, it will generate a compile-time error on the command prompt.
- If the syntax is correct, the compiler will generate a bytecode file with a
.classextension. - Compiler gives or shows all the error at once.
NOTE - First call command prompt and to to call compiler we should use a command called demo.java (here demo is the file name it could be different for you)
Step 3: Generating Bytecode
After compiling, the source code is converted into bytecode, which is a mid-level language. This bytecode is neither directly understandable by humans(programmer) nor by the machine. The bytecode file is saved with a .class extension.
Step 4: Executing the Bytecode
To run the bytecode, it needs to be translated into machine-level language, which is understandable by the computer. This translation is done by the Java Virtual Machine (JVM), which acts as an interpreter or translator. The JVM converts the bytecode into binary language (0's and 1's) that the machine can execute.
- The JVM will show one error at one time .
NOTE - To call JVM use a command called java demo (demo is the file name it could be different for you).
In short-
- Write: Create source code in an editor or IDE and save it with a
.javaextension.
.class extension.- Execute: Use the JVM to interpret the bytecode and run the program.
This process allows Java programs to be platform-independent, as the JVM can be implemented on any device, enabling the same bytecode to run on different operating systems.
.png)
Comments
Post a Comment