Compilation in Java:
- You write Java code in a .java file.
- The Java compiler (javac) compiles the .java file into an intermediate format called .class file (bytecode).
- The .class file contains platform-independent bytecode.
Interpretation in Java:
- The .class file (bytecode)is executed by the Java Virtual Machine (JVM).
- The JVM interprets the bytecode line by line and executes it on the fly.
- The JVM provides a platform-dependent implementation, allowing the bytecode to run on any platform that has a JVM.
Key differences:
- Compilation: Java code is compiled into bytecode beforehand.
- Interpretation: Bytecode is interpreted and executed by the JVM at runtime.
Character User Interface (CUI)
- A text-based interface where users interact using commands and receive text-based output.
Graphical User Interface (GUI)
- A visual interface where users interact using graphical elements like buttons, menus, and icons.
TERMINAL:
- ls--->listing file
- javac First.java
- java First javac--->To compile java program
code working:
Source Code → Intermediate Code → Byte Code → Machine Code
- compilation-source code to Byte code
- Execution-Byte code to Binary code
Java programme:
public class First
{
public static void main(String[] args)
{
System.out.println("Welcome To Java");
}
}
step-by-step Java compilation process:
Write Java Code: Create a Java program in a file with a
.java
extension (e.g.,First.java
).Compile Java Code: Use the
javac
command to compile the Java code into bytecode (e.g.,javac First.java
).Generate Bytecode: The
javac
command generates a.class
file (e.g.,HelloWorld.class
) containing the bytecode.Load Bytecode: The Java Virtual Machine (JVM) loads the
.class
file into memory.Execute Bytecode: The JVM executes the bytecode, running the Java program.
Top comments (0)