0% found this document useful (0 votes)
10 views

Topic 2_Java Environment Setup

This document provides a comprehensive guide to setting up a Java development environment, including downloading Java SE, configuring environment variables, and using popular Java editors like Notepad, Netbeans, and Eclipse. It also includes a simple Java program example, explaining how to save, compile, and run it, along with an overview of different types of Java errors. The document emphasizes the importance of matching the program file name with the class name for successful compilation.

Uploaded by

joyikehi7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Topic 2_Java Environment Setup

This document provides a comprehensive guide to setting up a Java development environment, including downloading Java SE, configuring environment variables, and using popular Java editors like Notepad, Netbeans, and Eclipse. It also includes a simple Java program example, explaining how to save, compile, and run it, along with an overview of different types of Java errors. The document emphasizes the importance of matching the program file name with the class name for successful compilation.

Uploaded by

joyikehi7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

JAVA ENVIRONMENT SETUP

Set Up Your Java Development


Environment
If you want to set up your own environment for Java programming language, please
follow the steps given below to set up your Java environment.

Java SE is freely available for download:


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

You can download a version based on your operating system.

Follow the instructions to download Java and run the .exe to install Java on your
machine. Once you installed Java on your machine, you will need to set environment
variables to point to correct installation directories:

CLASSPATH is the environment variable, which shows the Java compiler, javac.exe,
the location where the class files are stored. It finds the path where the class files are
stored while compiling the Java program using the javac complier. The following steps
are required:
Setting Up the Path for Windows

Assuming you have installed Java in c:\Program Files\java\jdk directory:

Step 1 : Right Click on This PC and click on properties .

Step 2 : Click on Advanced tab

Step 3: Click on Environment Variables

Step 4: Create a new class path for JAVA_HOME

Step 5: Enter the Variable name as path and the value to your jdk bin path i.e

c:\Programfiles\Java\jdk-1.6\bin and

NOTE: Make sure u start with .; in the value so that it doesn't corrupt the other
environment variables which is already set.
Setting the Environment Variables for Java (con’t)
Popular Java Editors
To write Java programs, you need a text editor. An Editor is a software system that
allows you to create and edit JAVA program on your computer.

There are even more sophisticated IDEs available in the market. The most popular
ones are briefly described below −

❑ Notepad − On Windows machine, you can use any simple text editor like Notepad
(recommended for this tutorial) or WordPad. Notepad++ is also a free text editor
which enhanced facilities.

❑ Netbeans − It is a Java IDE that is open-source and free which can be


downloaded from www.netbeans.org/index.html.

❑ Eclipse − It is also a Java IDE developed by the Eclipse open-source community


and can be downloaded from www.eclipse.org.

IDE or Integrated Development Environment, provides all common tools and


facilities to aid in programming, such as source code editor, build tools and
debuggers etc.
First Java Program

class HelloWorld

public static void main(String args[])

System.out.println("Hello, World!");

}
How the program works?

1. class HelloWorld { ... }


In Java, every application begins with a CLASS definition.
In the program, HelloWorld is the name of the class, and the curl
(start and end) defines the class boundary.

2. public static void main(String args[]) { ... }


This is the main method. Every application in Java must contain the
main method.
The Java compiler starts executing the code from the main method.
How the program works (con’t)

3. System.out.println ("Hello, World!");


The code above is a print statement. It prints the text Hello, World!
to standard output (your screen). The text inside the quotation
marks is called String in Java.

4. Program File Name - Name of the program file should exactly


match the class name.
When saving the file, you should save it using the class name and
append '.java' to the end of the name (if the file name and the class
name do not match, your program will not compile).
How to SAVE, COMPILE and RUN the Program
Please follow the subsequent steps:
1. Open Notepad and add the code as above.
2. Save the file as: HelloWorld.java.
3. Open a command prompt window and go to the directory where
you saved the class. Assume it's C:\codes.
4. Type 'javac HelloWorld.java' and press enter to compile your
code. If there are no errors in your code, the command prompt will
take you to the next line (Assumption : The path variable is set).
5. Now, type ' java HelloWorld ' to run your program.
NB. You will be able to see ' Hello World ' printed on the window.
Java Program Files

❑ This file contains the source code of the program.


❑ Source File The file extension of source file is .java.

❑ Class File
❑ This file contains the Bytecode of the program.
❑ Executable File The file extension of file is .class

❑ This file contains binary executable file generated by


the JVM. The JVM links the various bytecode files to
produce a binary file that can be directly executed
Runtime errors are those errors that occur
during the execution of a Java program and
Java Error Types generally occur due to some illegal operation
performed in the program.
❑ Runtime Errors
Compile errors are those errors that occur at
the time of compilation of the program.
❑ 2. Compile Errors
Syntax Errors
Syntax and Semantic When the rules / grammer of the Java
programming language are not followed, the
❑ 3. Logical Errors compiler will show syntax errors.

Semantic Errors are errors reported by the


compiler when the statements written in the
Java program are not meaningful to the
compiler.
Logical errors are those errors that occur due
to error in the logic applied in the program to
produce the desired output.

You might also like