0% found this document useful (0 votes)
28 views14 pages

Day 2

The document provides steps to check if Java is installed on a system, install Java if not present, set the JAVA_HOME and PATH environment variables, write a simple Hello World program in Java, compile and run the program. It also discusses various Java tools like javac, java etc and how to download the Eclipse IDE.

Uploaded by

Uqfdu1dg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views14 pages

Day 2

The document provides steps to check if Java is installed on a system, install Java if not present, set the JAVA_HOME and PATH environment variables, write a simple Hello World program in Java, compile and run the program. It also discusses various Java tools like javac, java etc and how to download the Eclipse IDE.

Uploaded by

Uqfdu1dg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

CODESY TRAINING CENTRE

Check if Java Present on your computer?


Open a command prompt and give below command: (Press Windows + R key to open RUN
window and then write “cmd” and hit ENTER button to open Command Prompt)

> java -version

If Java is installed and the PATH is configured correctly, you will see output as below:

java version "1.8.0_31"

Java(TM) SE Runtime Environment (build 1.8.0_31


1.8.0_31-b13)

Java HotSpot(TM) Client VM (build 25.31


25.31-b07,
b07, mixed mode, sharing)

NOTE: The exact messages will vary depending on the operating system used and the Java
version installed.

Otherwise, you’ll see an error message like the one below:

'java' is not recognized as an internal or external command,

operable program or batch file.

Additionally, you can also look for installed versions of Java (if it is installed) in Control Panel ->
Programs ->> Programs and Features
Features:

If Java is NOT present on your system, then follow below steps to install Java:

Contact Us on: +91 9405224852 / [email protected] 1


CODESY TRAINING CENTRE

Install Java on your computer:


Go to below website:

https://www.oracle.com/java/technologies/downloads/

If you want to download latest version of Java, then click on ““Java downloads”” tab (you will be on this
tab by default)

If you want to download a previous version of Java, then click on the ““Java archive”” tab.

NOTE: We are downloading the latest version of Java in this article.

Currently the latest version is JDK 21. Hence select JDK 21, then select your Operating System (my OS is
Windows so I have selected it as shown in below diagram) and then click on Download link present in
front of x64 Installer. Refer below screenshot:

Contact Us on: +91 9405224852 / [email protected] 2


CODESY TRAINING CENTRE

Once you click on Download link, installation will start as shown below:

Wait for installation to complete. Once installation is complete, click on the downloaded exe file directly
or go to the downloads (default download path can be different on your computer) and double click on
“EXE” (jdk-21_windows-x64_bin.exe).
x64_bin.exe).

The Java Setup window w will open as shown below. Click on Next button present on the window and
complete the installation process:

Contact Us on: +91 9405224852 / [email protected] 3


CODESY TRAINING CENTRE

Once you install Java on your computer, the next step is to set “PATH” and “JAVA_HOME” variables.

JAVA_HOME environment variable:

The JAVA_HOME environment variable points to the JDK installation directory. Other Java-dependent
programs (Apache Tomcat and other Java EE application servers, build tools such as Maven or Gradle)
can use this variable to access the JDK/JRE path.

PATH environment variable:

The operating system uses the PATH environment variable to find the native executable programs (.exe
files) to run.

Once we point the executable program’s directory in PATH, we can invoke these executable programs in
the command-line without the need to specify its full path.

For Java programs to run, we need to set the PATH variable pointing to the JDK installation directory
along with the bin directory. The bin directory holds the Java executables.

As a best practice, setting both the JAVA_HOME and PATH environment variables is always
recommended. This way, we can remove the compatibility issues between using old and new programs.

If the PATH variable is not set?

When we try to run a Java program from the command-line, the operating system looks into the PATH
variable to locate and run the JVM. If there’s no JDK on the PATH variable, the command terminates
with an error:

C:\Users\rohit>java HelloWorld

'java' is not recognized as an internal or external command,

operable program or batch file.

Another common issue is having different JDK versions in the PATH variable. In such a case, the
operating system considers the first occurrence of JDK in the PATH variable for execution. However, it’s
better to remove multiple versions in the PATH variable to avoid confusion at a later stage

Set JAVA_HOME and PATH environment variable:

Depending on the Windows Operating System version on your computer, you can follow below steps to
open Environment Variable window :

Contact Us on: +91 9405224852 / [email protected] 4


CODESY TRAINING CENTRE

Windows 11:

● Right-click
click on the Windows Start button and select System.
● In the System window, click on Advanced System Settings on the left sidebar.
● In the System Properties window (Advanced tab):
○ Click the Environment Variables button.

Windows 8 and 10:

● Open Search and type advanced system settings.


● In the shown options, select the View advanced system settings link.
● Under the Advanced tab, click Environment Variables.

Windows 7:

● On the Desktop, right-click


click My Computer and select Properties.
● Under the Advanced tab, click Environment Variables.

Set JAVA_HOME:

In the User Variables section, see if JAVA_HOME is already present or not. If NOT present then click on
the New button but if JAVA_HOME is present then select this entry and click on Edit button.

Then, set Variable name as JAVA_HOME and Variable value as path of JDK installation directory.
directory Refer
above screenshot for details.

Contact Us on: +91 9405224852 / [email protected] 5


CODESY TRAINING CENTRE

Set PATH:

In the User Variables section, see if PATH is already present or not. If NOT present then click on the New
button but if PATH is present then select this entry and click on Edit button.

If PATH is already there then check if an entry of the old version of Java is present there or not. If
present then remove this entry.

Click on OK button of User Variable and then click on OK button of Environment Variables window

Now,
ow, you can also check if JAVA_HOME is correctly set or not by below command in command prompt:

echo %JAVA_HOME%

The result should be the path to the JDK installation:

Now, output of java -version


version command:

NOTE: % used before and after JAVA_HOME is to treat JAVA_HOME as a variable (environment
variable)

Contact Us on: +91 9405224852 / [email protected] 6


CODESY TRAINING CENTRE

Write your First Java Program:


Open notepad and write the following program:

public class Hello {

public static void main(String[] args) {

System.out.println(
.println("Hello Java");

NOTE: If no access specifier is mentioned then default access specifier will be used. That means
if we do not mention “public” in class name then tha class will use “default” access specifier.
You can run your program if the main class is using the default acc
access
ess specifier but if you use
“private” for your main class then your program will not be executed.

Now save your program (file) with <<CLASS NAME>>.java (Hello.java)

Now Compile your program:

Go to Command Prompt and follow the instructions below:

1. First, you need to go to the directory where the Hello.java program is present. To do so, use
“cd” command as below:

cd “C:\RohitData\CODESY
CODESY\Core Java Batches\Programs”

2. Now compile your Java program with the following command:

javac Hello.java

Contact Us on: +91 9405224852 / [email protected] 7


CODESY TRAINING CENTRE

If there is no syntax
tax error, then the program will get successfully compiled. As a result of this
compilation, .class file (Hello.class) will be created at the same path where Hello.java file is
present. This is a ByteCode file generated by Java Compiler.

Now Execute your program:

Once you compile your program, you can execute it using Java Interpreter. Follow the instructions
below:

1. Execute your Java program with the following command:

java Hello

Your Java program will get executed and you will see output as below:

Contact Us on: +91 9405224852 / [email protected] 8


CODESY TRAINING CENTRE

javac - The compiler for the Java programming language.

java - The interpreter for the Java programming language.

jdb - The Java Debugger

Contact Us on: +91 9405224852 / [email protected] 9


CODESY TRAINING CENTRE

javap - Class file disassembler

javadoc - API documentation generator.

javah - C header and stub generator. Used tto write native methods.

appletviewer - Run and debug applets without a web browser.

jdeps - Java class dependency analyzer

Download Eclipse:

1. Go to https://www.eclipse.org/downloads/ URL and click on Dow


Download
nload Packages link
present on Eclipse IDE

2. Make sure that you download correct package as shown below

Contact Us on: +91 9405224852 / [email protected] 10


CODESY TRAINING CENTRE

3. Click on Download button

4. After clicking Download, wait for some time (max 1 or 2 minutes) for the Save As
window to appear.

Note: If Save As window is not displayed in 1 or 2 minutes, click on ““click here link as
click here”
below

Contact Us on: +91 9405224852 / [email protected] 11


CODESY TRAINING CENTRE

5. When Save As screen appears, select path where you want your Eclipse to be present
and click Save button

6. Once download is completed, you can see the ".zip” file of eclipse present at your
selected location. Right click on this “.zip” file and select Extract All button

Contact Us on: +91 9405224852 / [email protected] 12


CODESY TRAINING CENTRE

7. Select path where you want your unzipped eclipse package files (you can keep default
path as it is) and click Extract button

8. Once extraction completes, you can go inside that folders and see eclipse.exe file

9. Double click on eclipse.exe file. Eclipse IDE Launcher will display. Select Workspace and click
the Launch button.

Note: To create a new workspace, click the “Browse” button and select the folder where you
want the workspace to be created. If you need to create a new folder, right click and New ->
Folder (Give name to that folder) and go inside that folder. Then click the Select Folder button.

Contact Us on: +91 9405224852 / [email protected] 13


CODESY TRAINING CENTRE

10. Welcome screen will display as below


below:

11. For creating normal Java Project, Click File -> New -> Java Project

Contact Us on: +91 9405224852 / [email protected] 14

You might also like