Java Tutorial, Software Development

Chapter 3: How To Write Your First Java Program

How to write your first Java program? If you’re starting out learning Java, this probably is the first question you’d ask yourself. But before writing a Java program, you need to install the Java Development Kit for your operating system, e.g., Windows, and machine’s architecture, e.g., x64. Then, you need to install an Integrated Development Environment(IDE) to facilitate your development effort. More importantly, you need to decide on one architecture the tools support to avoid incompatibilities that may frustrate you. For instance, if you chose JDK for Windows x64, it would be best to install the IDE and other software specifically for Windows x64.

  • Know your operating system and machine’s architecture, e.g., x64
  • Download and install
    • Java Development Kit matching your operating system, e.g., Windows x64
    • IDE matching your operating system
    • other tools matching your operating system
  • Avoid compatibility issues among the JDK and tools, e.g., by not mixing up Windows x32 and x64 applications.

IDEs for Java Development

Before actually writing your first Java program, you need to down and install an IDE. What IDE? Most Java developers would name only major IDEs – Eclipse IDE and IntelliJ IDEA; the rest aren’t as famous as these two. Eclipse IDE is an open-source development tool. It’s free but no intuitive to use. On the other hand, IntelliJ IDEA is a commercial tool that you pay monthly or annually.  It’s not cheap, but it could hasten your development.

How To Download And Install Eclipse IDE on Windows 10

Here is a video that shows how to download and install Eclipse IDE on Windows 10. It also offers basic Java codes that display a “Hello” greeting on the console.

How To Download And Install IntelliJ IDEA on Windows 10

Sorry, this is still in progress.

Write Your First Java Program

Your first Java program would look something like the following codes.

If we create another Java program, we’d be creating codes similar to the above codes.

The only differences between the two source code files are the program’s name and the messages they print out. See lines 1 and 5. In essence, we create a Java program by using the keywords public and class; and the main method on line 3.

The main method has to be in that format.

When Your Java Program Runs

Before you run a Java program, we have to compile it. In most cases, the IDE does this for you. When you run your program, the JVM loads the bytecodes into the memory and looks for the class you specified with the java command. Consider the following MS-DOS command.

Then, the JVM looks for a specific method – the main method. It has to have the following method definition or format.

What happens if you renamed the main method as follows? Your program will crash, and you get an error!


What’s Next?

Next, we’ll install Oracle JDK8 on Windows 10. The article is also applicable to later versions of Oracle JDK.

Chapter 4: Oracle JDK8 on Windows 10: Installation


Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.

You Might Also Like