*First Java Program
class Program1{
public static void main(String [] args)
{
System.out.println("Hello Java");
}
}
>output:
Hello Java
class Program1{
public static void main(String [] args)
{
System.out.println("Hello Java");
}
}
>output:
Hello Java
●Compilation:
javac FileName.java
javac Program1.java
(After compiling the java program .class will be generate)
●Execution:
java ClassName
java Program1
》output: Hello Java
javac FileName.java
javac Program1.java
(After compiling the java program .class will be generate)
●Execution:
java ClassName
java Program1
》output: Hello Java
☆JAVA class syntax:-
class ClassName
{ //class declaration
//data members~variables
// member functions~ methods
// blocks
//constructor
public static void main(String [] args)
{
//executable statement
}
}
class ClassName
{ //class declaration
//data members~variables
// member functions~ methods
// blocks
//constructor
public static void main(String [] args)
{
//executable statement
}
}
• Class name should not start with numeric or special characters.
• Class name should start with alphabet+numeric
Ex: Demo1 ✔
1_Demo ✖(which is not recommended)
• Class name should start with alphabet+numeric
Ex: Demo1 ✔
1_Demo ✖(which is not recommended)
☆Keywords:
➖Keywords are the set of predeclared words, which have its own functionality.
➖There are 52 keywords in present in Java.
➖Java is case sensitive programming language, hence all the keywords need to be declared in lower case.
➖Keywords are the set of predeclared words, which have its own functionality.
➖There are 52 keywords in present in Java.
➖Java is case sensitive programming language, hence all the keywords need to be declared in lower case.
☆Identifiers:
➖In java identifiers are used to recognise a specific area or information.
Ex:- className, method name and variable name
➖In java identifiers are used to recognise a specific area or information.
Ex:- className, method name and variable name
☆Class body:-
➖After class declaration, open in curly braces and closed curly braces represent class body.
➖In a class body, programmer can be declare data members, member functions, blocks and constructor.
➖If programmer want to declare any executable statements then those statements need to be declared inside class body.
➖Declaring executable statements outside class body throws error.
(It is because of Encapsulation rule).
➖After class declaration, open in curly braces and closed curly braces represent class body.
➖In a class body, programmer can be declare data members, member functions, blocks and constructor.
➖If programmer want to declare any executable statements then those statements need to be declared inside class body.
➖Declaring executable statements outside class body throws error.
(It is because of Encapsulation rule).
☆Main method:-
➖Main method places very important role in execution of java program because of main method is the entry point of Java program.
➖Without main method compilation takes place but execution don't.
➖Main method places very important role in execution of java program because of main method is the entry point of Java program.
➖Without main method compilation takes place but execution don't.
Ex:-
class Demo
{
public static void main(String [] args)
{
System.out.println("Hello");
}
}
javac Demo.java
java Demo
O/p:- Hello
class Demo
{
public static void main(String [] args)
{
System.out.println("Hello");
}
}
javac Demo.java
java Demo
O/p:- Hello
☆print:-
➖Prints the output and the cursor remains in the same line.
☆println:-
➖Prints the output and the cursor jumps to the next line.
➖Prints the output and the cursor remains in the same line.
☆println:-
➖Prints the output and the cursor jumps to the next line.
Ex:-
Ex:-
class Demo1
{
public static void main(String [] args)
{
System.out.print("Hello all");
System.out.println("Hello");
}
}
javac Demo1.java
java Demo
O/p:- Hello allHello
_ (cursor)
Ex:-
class Demo1
{
public static void main(String [] args)
{
System.out.print("Hello all");
System.out.println("Hello");
}
}
javac Demo1.java
java Demo
O/p:- Hello allHello
_ (cursor)
System.out.println("HI");
HI
System.out.println(2);
2
System.out.println("HI+HELLO");
HI+HELLO
System.out.println("2+2");
2+2
System.out.println(2+2);
4
System.out.println("hi"+"hello");
hihello
System.out.println("hi"+"hello"+"2+2");
hi+hello2+2
System.out.println(2+2+"hi");
4hi
System.out.println("hi"+2+2);
Hi22
System.out.println(2+2+"hi"+2+2);
4hi22
System.out.println("hi"+(2+2));
hi4
HI
System.out.println(2);
2
System.out.println("HI+HELLO");
HI+HELLO
System.out.println("2+2");
2+2
System.out.println(2+2);
4
System.out.println("hi"+"hello");
hihello
System.out.println("hi"+"hello"+"2+2");
hi+hello2+2
System.out.println(2+2+"hi");
4hi
System.out.println("hi"+2+2);
Hi22
System.out.println(2+2+"hi"+2+2);
4hi22
System.out.println("hi"+(2+2));
hi4
☆Java software installation:-
➖To deal with java programming language two software are essentials.
1. JDK
➖JDK stands for Java Development Kit, it is used to design and develop java programs.
➖Inside JDK many readymade frameworks or classes are present.
➖With the help of those readymade classes frameworks applications can be developed instantly.
➖To deal with java programming language two software are essentials.
1. JDK
➖JDK stands for Java Development Kit, it is used to design and develop java programs.
➖Inside JDK many readymade frameworks or classes are present.
➖With the help of those readymade classes frameworks applications can be developed instantly.
2. JRE
➖JRE stands for Java Runtime Environment, it is used to execute Java programs.
➖Java programming language makes use of many API(Application Programming Interface) to provide very good security for applications.
➖JRE stands for Java Runtime Environment, it is used to execute Java programs.
➖Java programming language makes use of many API(Application Programming Interface) to provide very good security for applications.
☆Configuring JDK software with OS(Operating System):-
➖After installation of JDK software visit inside below declared folder
C:\.......
➖copy the url
➖open system property window
Computer》Properties》Advanced system settings》Environment variables》system variables》PATH》PASTE THAT URL.
➖It pop-up window appears on the screen, the already some information will be predeclared. Don't manipulate that information, after information tyle ';' and paste the jdk url
➖Open the command prompt and type Java, a list of predeclared commands related to java appears on the screen. If not then crosscheck with configuration steps.
➖After installation of JDK software visit inside below declared folder
C:\.......
➖copy the url
➖open system property window
Computer》Properties》Advanced system settings》Environment variables》system variables》PATH》PASTE THAT URL.
➖It pop-up window appears on the screen, the already some information will be predeclared. Don't manipulate that information, after information tyle ';' and paste the jdk url
➖Open the command prompt and type Java, a list of predeclared commands related to java appears on the screen. If not then crosscheck with configuration steps.
☆Java program Execution flow:-
➖Java program execution flow involves three steps process, they are
1. Coding
2. Compilation
3. Execution
➖Java program execution flow involves three steps process, they are
1. Coding
2. Compilation
3. Execution
➖User declared java programs(.java) is considered to be as source file.
➖Once the source file is ready programmer need to invoke compiler to perform compilation operation.
➖The below declared command is used to invoke compiler
javac Filename.java
➖Once the source file is ready programmer need to invoke compiler to perform compilation operation.
➖The below declared command is used to invoke compiler
javac Filename.java
➖The work of compiler is, it compares user declared java program with standard java syntex(present inside java library).
➖This comparison is perform to detect syntactical mistakes. If any mistakes perform then compiler display fully qualified mistakes on screen.
➖If no mistakes perform, then compiler generate new file(compilation successful)
➖The newly generated file is considered to be as .class file or intermediate file.
➖The content of .class file is bytecode.
➖Once .class file is generated programmer need to invoke JRE or JVM for execution.
➖The below declared cmd is used to invoke JRE or JVM.
java ClassName
➖This comparison is perform to detect syntactical mistakes. If any mistakes perform then compiler display fully qualified mistakes on screen.
➖If no mistakes perform, then compiler generate new file(compilation successful)
➖The newly generated file is considered to be as .class file or intermediate file.
➖The content of .class file is bytecode.
➖Once .class file is generated programmer need to invoke JRE or JVM for execution.
➖The below declared cmd is used to invoke JRE or JVM.
java ClassName