Our Learning Journey

My First Code in Java

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.

  1. Open a text editor and copy the code above into a new file.
  2. Save the file with a .java extension, for example MyFirstCode.java.
  3. Open a terminal or command prompt and navigate to the directory where you saved the file.
  4. Compile the Java program by typing javac MyFirstCode.java. This will create a new file called MyFirstCode.class.
  5. Run the program by typing java MyFirstCode.

You should see the text “Hello, World!” printed to the console.

Leave a Reply

Your email address will not be published. Required fields are marked *