DEV Community

silambarasan rajendran
silambarasan rajendran

Posted on

Day-06: Hello-world from JAVA

To install Java in Linux machine:
sudo apt install default-jdk -y

Code working flow:

  1. Source Code to Byte Code - Compilation
  2. 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 
Enter fullscreen mode Exit fullscreen mode

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. 
Enter fullscreen mode Exit fullscreen mode

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"); } } 
Enter fullscreen mode Exit fullscreen mode

To Compilation this Source Code:
javac First.java

To Run this byte code:
java First

Output will be:

Image description

Some of the Common Errors:

 public class First { public static void main(String[] args) { System.out.println("Welcome To Java"); } 
Enter fullscreen mode Exit fullscreen mode

Removed ‘}’ at the end

First.java:6: error: reached end of file while parsing } ^ 1 error

Top comments (0)