Java Tutorial 1
(Java Environment Setup together with Write First Java Program)
> Download Java (JDK) Software together with Install
> laid upward Environment Variable (Path Variable)
(* If desire to execute Java programs from whatsoever directory inwards C Drive)
How to laid upward Path Environment Variable:
OS: Windows 7
> Select MYComputer together with Right click
> Properties
> Advanced System Settings
> Environment Variables
> Select "New" inwards System variables
> Enter Variable every 2nd "Path"
> Enter JDK bin directory path ("C:\Program Files\Java\jdk1.8.0_45\bin") inwards value field
> OK > OK > Ok
----------------------------------------
Verify the Environment setup:
> Launch Command Prompt
> Type coffee (It provides details)
-------------------------------------
Three steps to write together with execute Java Programs
i) Write Java Program inwards Notepad (Editor)
ii) Compile the Program (It creates Class file)
Command prompt > Change to Program file Directory
> Type javac Programname.java (java is extension of Java program, javac ascendence for compilation)
iii) Run /Execute the Java Program
> Type coffee programName
(It provides Output on the console)
-----------------------------------------------------
Use Eclipse IDE to write together with execute Java programs.
Eclipse IDE (Integrated Development Environment)
It is a platform to write together with execute Java programs, Perl, Python, PHP, Ruby etc...
It provides Editor, context help, assist for syntax errors, Auto compilation together with debugging.
-----------------------------
Download Eclipse software together with extract.
Steps:
----------------
> Create Java Project
-> Create a Package
-> Create a Class / Interface
(We tin plough over notice write coffee code inwards the Class file)
--------------------------------------
Ex:
public shape Sample {
populace static void principal (String [] args){
System.out.println("Hello Java together with Selenium");
}
}
-------------------------------------------------
Java Program construction or Java Syntax:
1) Package annunciation statement
ex:
package abcd;
--------------------------------
2) Import statements
we tin plough over notice import Built inwards together with User defined Libraries using import keyword.
(In lodge to purpose Existing Classes, Objects, together with Methods)
Example:
import java.io.console;
(It Imports Console Class alone from io package)
import java.io.*;
(It imports all classes from io package)
------------------
java - project
io - package
Console - Class
----------------------------------------------
3) Class annunciation statement
ex:
public shape Sample {
}
public - Access Modifier
class - Java keyword to declare a class
Sample - Name of the Class
Note: First missive of the alphabet of Class lift should live upper case.
-------------------------------------------------
4) Comments section
// This is a Sample Java Program
-----------------------------------
5) Main Method
(Java programme execution starts from principal method.)
(Main method is mandatory inwards every Java program)
public static void principal (String [] args) {
}
public - Access Modifier
static - purpose principal method without invoking whatsoever object.
void - returns nothing
main - method name
-------------------------------------------
6) Declarations
We tin plough over notice declare variables together with constants
-----------------------------
Normal statements
Conditional blocks
Loop blocks
Method declarations
Etc...
-----------------------------
Sample Java Program:
package abcd;
import java.io.Console;
import java.lang.*;
public shape Sample2 {
// This is a Sample Java Program
populace static void principal (String [] args){
int a = 50, b, c; // Declaration of Variables
b= 20; // Initialization
System.out.println(a + b); // 70
System.out.println("Addition of a, b is: "+ (a+b));
lastly int MONEY = 100; // Declaration of Constant
if (a > b) {
System.out.println("A is a Big Number");
}
else
{
System.out.println("B is a Big Number");
}
for (c = 1; c <= 10; c++){
System.out.println(c);
}
}
}
(Java Environment Setup together with Write First Java Program)
> Download Java (JDK) Software together with Install
> laid upward Environment Variable (Path Variable)
(* If desire to execute Java programs from whatsoever directory inwards C Drive)
How to laid upward Path Environment Variable:
OS: Windows 7
> Select MYComputer together with Right click
> Properties
> Advanced System Settings
> Environment Variables
> Select "New" inwards System variables
> Enter Variable every 2nd "Path"
> Enter JDK bin directory path ("C:\Program Files\Java\jdk1.8.0_45\bin") inwards value field
> OK > OK > Ok
----------------------------------------
Verify the Environment setup:
> Launch Command Prompt
> Type coffee (It provides details)
-------------------------------------
Three steps to write together with execute Java Programs
i) Write Java Program inwards Notepad (Editor)
ii) Compile the Program (It creates Class file)
Command prompt > Change to Program file Directory
> Type javac Programname.java (java is extension of Java program, javac ascendence for compilation)
iii) Run /Execute the Java Program
> Type coffee programName
(It provides Output on the console)
-----------------------------------------------------
Use Eclipse IDE to write together with execute Java programs.
Eclipse IDE (Integrated Development Environment)
It is a platform to write together with execute Java programs, Perl, Python, PHP, Ruby etc...
It provides Editor, context help, assist for syntax errors, Auto compilation together with debugging.
-----------------------------
Download Eclipse software together with extract.
Steps:
----------------
> Create Java Project
-> Create a Package
-> Create a Class / Interface
(We tin plough over notice write coffee code inwards the Class file)
--------------------------------------
Ex:
public shape Sample {
populace static void principal (String [] args){
System.out.println("Hello Java together with Selenium");
}
}
-------------------------------------------------
Java Program construction or Java Syntax:
1) Package annunciation statement
ex:
package abcd;
--------------------------------
2) Import statements
we tin plough over notice import Built inwards together with User defined Libraries using import keyword.
(In lodge to purpose Existing Classes, Objects, together with Methods)
Example:
import java.io.console;
(It Imports Console Class alone from io package)
import java.io.*;
(It imports all classes from io package)
------------------
java - project
io - package
Console - Class
----------------------------------------------
3) Class annunciation statement
ex:
public shape Sample {
}
public - Access Modifier
class - Java keyword to declare a class
Sample - Name of the Class
Note: First missive of the alphabet of Class lift should live upper case.
-------------------------------------------------
4) Comments section
// This is a Sample Java Program
-----------------------------------
5) Main Method
(Java programme execution starts from principal method.)
(Main method is mandatory inwards every Java program)
public static void principal (String [] args) {
}
public - Access Modifier
static - purpose principal method without invoking whatsoever object.
void - returns nothing
main - method name
-------------------------------------------
6) Declarations
We tin plough over notice declare variables together with constants
-----------------------------
Normal statements
Conditional blocks
Loop blocks
Method declarations
Etc...
-----------------------------
Sample Java Program:
package abcd;
import java.io.Console;
import java.lang.*;
public shape Sample2 {
// This is a Sample Java Program
populace static void principal (String [] args){
int a = 50, b, c; // Declaration of Variables
b= 20; // Initialization
System.out.println(a + b); // 70
System.out.println("Addition of a, b is: "+ (a+b));
lastly int MONEY = 100; // Declaration of Constant
if (a > b) {
System.out.println("A is a Big Number");
}
else
{
System.out.println("B is a Big Number");
}
for (c = 1; c <= 10; c++){
System.out.println(c);
}
}
}