Getting Started with Java - Installing JDK

 After knowing the brief history of Java, and understanding its importance and applications. Let us learn how to setup Java in your own system, to build and run Java Programs. Some PCs might have Java installed already. You can check whether Java is installed through Command Prompt(cmd.exe) using the command 'java -version'. On its execution, it will display the version of Java installed on your System. If it is not installed in your System already. Then follow our guide and start your career in Java Programming.

Setting-up Java 

  1. Go to oracle.com And download the latest version of JDK(Java Development Kit) available.
  2. Then select your platform and architecture. And start downloading.
  3. Install the downloaded file. And then go to Advanced System Properties(Control Panel > System and Security > System > Advanced System Settings). And a box will appear on the screen named System Properties. 
  4. Then go to Environment Variables, being shown at the end of the box in the above image. And then in System Variables, select Path and click edit. And such window will appear.
  5. Now click on 'New' Button and add the path where Java is installed in your system. 
  6. For getting your path. Go to C Drive of your PC, then Program Files, Then Java, then jdk-11.0.1, or whatever version you see there. Then go to the bin folder. And now click on the location and copy the path.
  7. And then paste this path, in the edit environment variable window in Step 4. And then press OK.
And Java is installed in your system, Then check the installation by opening cmd.exe and typing 'java -version'.
And on getting this output, after executing the above command. It means Java is installed successfully on your System.

Selecting an IDE for Java

Integrated Development Environment(IDE) is a software for building applications or programs that combines common developer tools into a single Graphical User Interface(GUI). These are very much helpful in increasing the productivity of the programmer.

I would prefer you to go with Eclipse-IDE. It is one of the best IDEs for Java and other programming languages. You can also go with VSCode, Visual Studios, IntelliJ and other IDEs as well, it is upto you.

Download Eclipse IDE for Java Developers from eclipse.org.
And install the program after being downloaded. 

And your Java Set-up is finally ready✌, Lets write our very First program in our Eclipse IDE.

Java Quick-Start

  1. Open Eclipse IDE.
  2. It will ask you to set a directory for saving all the programs you are going to make in Eclipse. Select any directory of your wish. Then click Launch button
  3. Then in it will ask you to create a new package, it is actually nothing but a folder that would be created in the directory you selected in the upper step. And this package would be displayed in the package manager section on the left side.
  4. Then after creating a package, double-click on the package name in the Package Explorer Window. And and right click on the src folder and select 'Class'. This will create a new Java class for you.
  5. Then start writing your code there.
For the time being, this is your first step in the world of Java Programming, now we'll write a simple Hello World program in Eclipse. And compile and run it.

Write the following code in the code panel.
class Main
{
  public static void main(String args[]) 
  {
    System.out.println("Hello World");
  }
}

* We'll learn about every aspect of the code in the later tutorials, but for now it is nothing but a piece of text to be copied and pasted in the IDE.

And then click the run button as shown in the image below.
And your output would be displayed in the console window. At the bottom

Congratulations!🎉, finally you compiled and ran your first Java Program👍.

Compiling and Running Programs through CMD

Yes, you can compile and run programs through cmd.exe also. But for this also you need java-jdk installed in your system(Discussed in the Upper section of post). For doing this, write a code in simple notepad file, and save it with a extension .java. Also remember the location, where you are saving the file. 
  1. Copy the above Hello world code in notepad file, saving it with the name hello.java
  2. Open cmd.exe
  3. Navigate to the folder where you have created the file, using the 'cd'(change directory) command. And then list all the items on reaching the desired folder using 'dir' command. 
  4. Then execute the command 'javac filename.java', this command will compile the code and create a new file with the same file name but with .class extension, Only if the code is compiled without any errors. This file created is called the Byte Code
  5. Now again go to cmd and execute 'java filename', this will run your compiled code. And output would be printed the command prompt itself.

Ritish

Just a novice blogger

Post a Comment (0)
Previous Post Next Post