To install Java in Linux machine:
sudo apt install default-jdk -y
Code working flow:
- Source Code to Byte Code - Compilation
- Byte Code to Binary Code - Execution
Source Code to Byte Code - Compile Time
Compiler: A compiler turns your source code into byte code. This is an intermediate form that the computer can understand, but it's not ready to run directly.
Tools: IDE - IntelliJ or Eclipse, and the compiler - javac
Byte Code to Binary Code - Run Time
What happens: After you have the byte code, it still needs to be turned into machine code that your computer's processor can execute.
JRE: The Java Runtime Environment (JRE), or similar, takes the byte code and turns it into binary machine code.
Tools: The JVM (Java Virtual Machine) reads the byte code and makes the program run by converting it into binary.
Compile Time:
Source code → Byte code (done by the compiler).
Run Time:
Byte code → Binary code (done by the JRE/JVM).
Sample Java Programme:
public class First
{
public static void main(String[] args)
{
System.out.println("Welcome To Java");
}
}
To Compilation this Source Code:
javac First.java
To Run this byte code:
java First
Output will be:
Some of the Common Errors:
public class First {
public static void main(String[] args) {
System.out.println("Welcome To Java");
}
Removed ‘}’ at the end
First.java:6: error: reached end of file while parsing } ^ 1 error
Top comments (0)