Introduction To Java

You may watch full clip here on writing first program In Java on NetBeans;

Watch now!

In today’s tutorial we will learn on how you can get started with Java. We will discuss the following;

  • What is Java?
  • Why learn Java?
  • What Java is used for?
  • Prerequisites for writing Java program.
  • How to get started with Java in your computer or laptop?
  • We will write our first program in Java, “Hello world”.

What is Java?

Java is an object-oriented programming language that produces software for multiple platforms. It runs on most operating systems when a programmer writes the Java application, the compiled code(bytecode) runs on these operating systems such as windows, Linux or Mac. Java was developed in the mid-1990s by a computer scientist known as James A. Gosling. It is one of the most popular programming language in the world which runs in over 3 billions devices.

Why learn Java?

It very vital to have knowledge in Java language, is not must to have prior experience in programming before learning Java. These are the reasons as to why you need to know Java language;

  • It is very easy to learn and simple to use to write programs.
  • It is a popular programming language.
  • It is very secure, powerful and fast.
  • It runs in various operating systems such as windows, Linux, Mac
  • Java is very close to C++ & C# therefore a programmer can easily change programs between the languages.
  • It is a open source language and free language.

What Java is used for?

Java is one of the popular programming language that one should have knowledge in. It is applied in various areas of development which include;

  • Desktop applications development
  • Developing mobile applications
  • Database connections
  • Game development
  • Web applications
  • Web servers and much more.

What are prerequisites for writing Java Program?

These refers to the requirements before you write your Java program such as the best IDE’s, text editor or compilers one should use. Let’s get started.

  • You need to know the basics of how to use computer and be in a position to start command line.
  • You need have one of this Java IDE installed in your pc, the popular one are Eclipse, IntelliJ IDEA, NetBeans among others. So you can choose any of this IDE to run your Java program.
  • You can either use any of the text editors such as notepad, visual studio code, sublime text etc, but you save your work with .java extension for example, filename.java. Then run them in your installed Java IDE.
To learn about the best IDE to use when writing Java programs; Click Here.

How to get started with Java in your computer or laptop

In this we discuss how you can install and run Java in your computer, we will see how to check whether Java is installed in you computer as many PC’s are already installed with Java. Let’s start,

-First you will to check whether Java is installed in your PC, otherwise if not installed you can do in simple steps and install it from Oracle.com. To check whether Java is installed in your PC, you will need to start your command prompt and write the following codes;


C:\Users\your name>java -version

If Java is installed in your PC it will show the following code lines;


java version "1.8.0_281"
Java(TM) SE Runtime Environment (build 1.8.0_281-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)

Other if not installed you can simply install it from oracle.com and follow these steps to set up in your PC.

a) You will need to go to settings, then systems properties the click on control panel>system>advanced system settings.
b) After that click on “environment variables” button.
c) You will now select “path” and then click “edit” button.
d) Now click “new” button and add the path where the Java is installed follow \bin for example; C:\program files\java\jdk-12.0.1\bin, then click Ok and save the settings.
e) Finally you will need to check whether Java is installed in your command prompt as we have discussed above.

How to write first program in Java?

In this part we will write our first program “hello world” in java language. Remember in this part we will write our Java program in a text editor but you can always use Java IDEs when writing large files in Java. Let’s start.

-Java program should start with a class name which is the same as the name of the file. For instance, we may our first program here named as Demo.java, in our case here let’s write in visual studio code but as well you can write in any other text editor, as follows;


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

After that you will need now to save your work and copy the path directory where you save your work. Now paste in command prompt and write “javac Demo.java” should appear as follows;


C:\users\your name>javac Demo.java

Then press enter and if there are no errors in your codes should take to the next line, now write these code lines to output your program.


C:\users\your name>java Demo

It will now output;

Hello world

Thanks for reading though our first tutorial on how to get started with Java in your PC and for writing first program in Java. In our next tutorial we will discuss, on various syntaxes as we have used them in the above program. As we continue learning Java hoping to meet you in our next tutorial. Remember to subscribe to our YouTube Channel for live sessions and video tutorials.