April 5, 2025 Menu

In this section, we'll be writing our first java program: the famous Hello World. But before that, you need to make sure that Java is properly configured in your machine. Check this guide on how to properly install java in your machine.



We break the process of programming in Java into three steps:


  1. Create the program by typing it into a text editor and saving it to a file named, say, FirstProgram.java.
  2. Compile it by typing "javac FirstProgram.java" in the terminal window.
  3. Run (or execute) it by typing "java FirstProgram" in the terminal window.
The first step creates the program; the second translates it into a language more suitable for machine execution (and puts the result in a file named MyProgram.class); the third actually runs the program.

1
2
3
4
5
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

  • Creating a Java Program - A program is nothing more than a sequence of characters like sentences or paragraphs. We create program by defining or typing that sequence of characters using a text editor in the same way as we do for e-mail. The code above is an example. Type that into your text editor and save it into a filed named Main.java. 
  • Compiling the Java Program - Java is high-level language. In other words, it is designed to be best understood by the programmer (that's you). We need the help of the compiler so that the computer can execute it. A compiler is an application that translates programs from the Java language to a language more suitable for executing on the computer. It takes a file with the .java extension as input and produces a file with a .class extension. To compile your program, you need to type the command below at the terminal or command prompt:


                        % javac Main.java

  • Executing a Java program - Once you compile your program, you can run it. To run your Hello World program, type the following at the terminal or command prompt:


                        % java Main


If all goes well, you should see the following response:


                        Hello, World

Congratulations! 
Next
This is the most recent post.
Previous
JDK Installation for Microsoft Windows

Mag-post ng isang Komento

Emoticon
:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

 
Top