Java Beginner's Guide [1] - Introduction & Installing JDK



Hi there! Today I’m going to start a new tutorial series for the beginners who want to learn java. So this tutorial will help the people who have no programming experience before for sure. Let’s start! šŸ»

What is java?

Java is a high-level programming language developed by Sun Microsystems. It was originally designed for developing programs for set-top boxes and handheld devices, but later became a popular choice for creating web applications also. Java is an object-oriented language and it is very similar to C++. Don’t worry you will learn what’s is object-oriented programming in the upcoming tutorials.



What is JDK and How to download it?

Before we start coding in Java, we need to download something called JDK – Java development kit. This provides the facility to compile a code which is written in Java. The compiler is something which translates the human-readable code into a machine-readable format.

Let’s download Java JDK. So first you need to open up your file browser and search Java JDK. Click the link that looks like the highlighted one in the image.



Then you will find something like below.



Before download, you have to accept the license agreement then you can choose the file that will be compatible with your device. In my case, it will be Windows X64. You can find your system type by moving to Control panel -> System and Security -> System.



After the downloading finish, you can start the installing process by double-clicking on the downloaded file. Then you can follow the below steps to install JDK successfully.

1. Click Next.


2. If you don't want to change the location of the installation, Click Next.


3. Then you will see this window. And the system will start the installation.


4. The system will again ask whether you want to change the destination folder. If not you can click next otherwise change it.


5. The system will continue the installing process.


6. After the Installation, the system will show the following window. Click Close.


Good! You installed JDK successfully.  Now you have to set up the environment variables. For that, you have to find the place you install JDK.

In my case, it is in C drive. Go to C-> Program Files -> Java -> bin. And right click on appletviewer.exe (You can right click on anything in this folder. I have chosen the topmost one) and select properties. Then copy the location in the pop-up window.


And then find your control panel and go to Control panel -> System and Security -> System. And select Advanced System Settings. Go to Environment variables and create a new user variable (by clicking New.. button) which is called JAVA_HOME and paste the copied link there. And click “OK” in every window that popped up.


You have your compiler set-upped and ready to run. You can check it by typing “java -version” in your command line. If it shows the version you downloaded then you’re good to go. šŸ˜Š



Let’s write our first Java program

When we consider a Java program, it can be defined as a collection of objects that communicate via invoking each other's methods. Let us now briefly look into what do class, object, methods, and instance variables mean.
  • Class − A class can be defined as a template/blueprint that describes the behavior/state that the object of its type supports.
  • Object − Objects have states and behaviors. Example: A person has states - color, name, gender as well as behavior such as eating, talking, walking, etc. An object is an instance of a class.
  • Methods − A method is basically a behavior. A class can contain many methods. It is in methods where the logic is written, data is manipulated and all the actions are executed.
  • Instance Variables − Each object has its unique set of instance variables. An object's state is created by the values assigned to these instance variables.

Ok. Let's write a simple program. Open your notepad or notepad++. And open up a new file.

In java for everything, we need classes. Type following lines in the file you opened.

class in java


Inside every class, there will be methods and variables. So let’s write a method. Its name is main.

Your first java program


Ok! Now your very first java program is ready to compile & run. Save it as HelloWorld.java. This is very important! Your file name and the class name in the code must be similar. Otherwise, it will not compile correctly. And remember the location you saved your file. In my case it is the Desktop.

Open your command line again. And type the following first command in the image (cd Desktop) to move to the desktop. If you save it in another place then you have to enter that relevant path to your file.

Then compile your code using the second command (javac HelloWorld.java). If it returns nothing then, you have done your works without any doubts. Now you can type the last command (java HelloWorld) and get the output.

You can find this program from here.



Congratulations! You have written your first java program and put the first step to learning one of the Most Popular Programming Languages.

Congratulations !!

From the next tutorial onwards, I will be using Eclipse IDE (Integrated Development Environment). It is much easier to use an IDE when you coding since you don’t need to bother with the command line.



So, If you want to know how to download Eclipse for windows, refer this youtube video.

References: https://www.tutorialspoint.com/java

Thank you!



Next

Kalpani

Comments