Java Environment Setup

Java Environment Setup

Java Environment Setup

A) Java Environment Setup
> Download Java (JDK) and Install

> Set Environment Variable (Path variable)

How to set Path Environment Variable (For Windows 7):
Select Computer icon on Desktop and Right click

> Properties

> Advanced System Settings

> Environment Variables

> Select New in System Variables

> Enter Variable as Path

> Enter Jdk bin directory path (C:\Program Files\Java\jdk1.8.0_40\bin) in Value field

> Ok > OK >OK

B) Verify the Java Environment:

Launch command prompt
> Type Java (it provides the details)
————————————
Steps:
1) Download Java (JDK) software and Install

2) Set Environment Variable (Path variable) in order access Java from any directory in C Drive.

3) Verify the Java Environment setup using java or javac commands.
———————————————
3 steps for writing and executing Java programs
1) Write Java program in Notepad (Editor)

2) Compile the program (It creates Class file)

Command prompt > Change to Program file directory

> Type javac Program name.java (java is extension, javac is java command for compilation)

3) Run / execute the Program (Output)

> Type java space Program name
It provides output on the console
————————————–
Sample Java Program:—————————–
public class Sample{

public static void main (String [] args){

System.out.println (“Hello Java World”);

}

}
———————————————–
Note:

i) First letter of the class name should be upper case value

ii) Class name and program file name as to same.
————————————————–
Download Eclipse software and unzip
What is Eclipse (IDE-Integrated development environment)?

It is a Platform to create and execute Java programs, Perl, Python, Ruby and PHP etc…

It provides Editor, Context help, help for syntax errors, Auto compilation and debugging.

Open Eclipse main folder

> Click Eclipse file

It launches Eclipse IDE
———————–
Create Java Project
-> Create a Package
-> Create Class / Interface
————————————-
Java Program Structure / java Syntax

1) Package declaration statement

ex:

package Saturday;

Note: Package is used to store and Organize Classes based on functionality.

It must be first in our Java Program

2) Import statements

Import statements are kept after the package statement

We can import Built in and User defined packages /Libraries

Ex:

import java.io.Console;

import is a keyword to import built in / user defined packages

java is Project

io is package

Console is a class in io package
——————-
import java.io.*;

It loads/imports all classes from io package

3) Class declaration statement

Ex:
public class Sample {
}

public is access modifier

class keyword to declare a class

Sample – name of the Class
—————————–

Follow me on social media: