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
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
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.
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.
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");
}
}
public class First
{
 public static void main(String[] args)
    {
    System.out.println("Welcome To Java"); 
    }
}
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:

Some of the Common Errors:

public class First {
public static void main(String[] args) {
System.out.println("Welcome To Java");
}
 public class First {  
    public static void main(String[] args)  {     
        System.out.println("Welcome To Java");      
    } 
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

原文链接:Day-06: Hello-world from JAVA

© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享
I am the luckiest person in the world.
我是世界上最幸运的人
评论 抢沙发

请登录后发表评论

    暂无评论内容