Here is a simple “Hello, World!” program in Java:
public class MyFirstCode{
/* This is my first java program.
* This will print 'Hello World' as the output
*/
public static void main(String args[]){
System.out.println("Hello World!");
}
}
To run this program, we need to have the Java Development Kit (JDK) installed on our computer.
- Open a text editor and copy the code above into a new file.
- Save the file with a
.javaextension, for exampleMyFirstCode.java. - Open a terminal or command prompt and navigate to the directory where you saved the file.
- Compile the Java program by typing
javac MyFirstCode.java. This will create a new file calledMyFirstCode.class. - Run the program by typing
java MyFirstCode.
You should see the text “Hello, World!” printed to the console.
Leave a Reply