Your First Java Program - Hello World

Android Tutorial – Your First Java Program

Articles & Tutorials

Are you ready to start your first Java Program?

I’ve started an android course on my youtube channel and as I said in the latest video before to finish the course, I add all the detail on the website.

The first video was about to understand java programming language and start the first Java program.

 

What’s Java :

Java is cross-platform programming language, it means Java program can run on Windows, Unix, Mac, Android … ect

Right now, we have Java code running on billions of devices and those devices range from computers, also from little electronic devices that aren’t full-fledged computers but need to run some sort of programming language Java is a great choice for that.

So when you will learn java, you’ll really open a whole box of tools for yourself to address a big market.

 

How is Java cross-platform :

It means is that when you write code when you actually write your program you write it in a text file that you can read and it has a dot java extension (.java)

You do need to compile the code and you compile it using a java compiler that’s a freely available thing I’ll show you where to download it. The output of this compile process is basically the compiler looks at your code and it assembles into a dot class file (.class)

ex: car.java –> car.class

The dot class file is called “byte code”. It’s machine-readable, the translation process from java file to class file is called compiling the program.

The dot class file (.class) can run on any system with a Java Virtual Machine (JVM)

The dot class file (.class) is run by the JVM. It’s “interpreted”

 

Java Compil and Run Process

 

The main benefit of the Java paradigm :

The main benefit is you can write one program and run it anywhere.

  • Write code on your system
  • Compil to a .class file
  • Distribute the .class file to the different operating systems such as Windows, Mac, Unix, …
  • Your program can run on any operating system with JVM

 

First Java Program :

To write your first Java code, you need a simple text editor such as Notepad, Notepad++ or advanced editor such as Eclipse, Netbeans, IntelliJ (not free).

In the video, I’ve used an online compiler such as Browxy, I recommend you to use one of Java editor.

 

 

1) Download and Install JDK :

To download the latest version of the Java Development Kit (JDK), follow these steps :

  • Go to this link and click to “JDK Download”

Download JDK

  • Depending on your operating system, click to download

JDK Operating System version

  • In the popup, accept the license and click to download

JDK License

  • Install the JDK in the desired directory.
  • To check if the installation succeeded, open the command window (in windows, just type “cmd” in the search bar and click on it) and type this command :

Java -version

Java command version

If you see the java version it’s OK, else you must check in your variable environment if there is an entry point for the JDK

JDK Variable environement

 

2) Write the Java code :

class HelloWorld {
 public static void main(String args[]){
     System.out.println("Hello World");
 }
}

See the video to understand each detail of this code.

Save this code to HelloWorld.java

 

3) Compil and Run Program :

for compiling the program, just write this command: javac HelloWorld.java

for running the program, just write this command: java HelloWorld

 

 

Leave a Reply

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