Here's a step-by-step guide to running a Java program in Linux terminal:
Step 1: Create a Java File
Create a .java file in a folder and write your Java program inside it.
Step 2: Open Terminal and Navigate
Open the terminal, go to the specific file location using cd command.
Step 3: Compile the Java File
Compile the .java file using javac command:
javac Filename.java
This will generate a .class file, which is in binary format.
Step 4: Run the Java Program
Run the Java program using java command:
java Filename
This will execute the program and display the output.
Key differences between .java and .class files:
-
.javafiles contain human-readable Java code. -
.classfiles contain binary code that can be executed by the JVM.
That's it! You've successfully run a Java program in Linux terminal.
Top comments (0)