


























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



























































































Module 1: Core Java Programming
Section 1: Basics of Programming:
Section 2: OOPS:
Section 3: Java libraries: 22.Object Class function 23.In-depth of Strings 24.In-depth of Arrays 25.Exception Handling 26.Multithreaded Programming 27.Collection Framework libraries 28.File Programming
Module 2: J2EE (Java 2 Enterprise Edition)
Section 1: JDBC Programming:
Pre-Condition You need to completed Java and Sql
Section 2: Servlets Programming: Pre-Condition You need to completed Java+Sql+JDBC and web Technologies (HTML,CSS,JavaScript)
Section 3: JSP Programming
Module 3: Frameworks
Java Program
Java components explanation: A programmer writes a statements in java editor using high-level language and saves it with an extension of filename.java
Java Statement s
(English)
Java Compiler
(Javac)
*Syntax
Byte code
Filename.cl ass
Executable
JIT: Just in Time (Compiler)InterpreterExecutionResult
--------------- //Statements } //End of Main Method Body Body } //End of Class body
OCJP: Oracle certified Java Professionals (Java Certification cost 8k) The folder structure need to be maintained
Javac filename.java : compilation command Java classname : Execution command
class Program { public static void main(String[] args) { System.out.println('H'); } }
Output : H
class Program { public static void main(String[] args) { System.out.println('H'); System.out.println('i'); } }
//This program output will have 3lines first line will print H and second will print i and third line will be empty as the cursor will move to next line ================================================== ===================================
Println: Prints the statement and moves cursor to next line so in the last program we got three-line o/p Print: Prints the statement and move to next char in same line
class Program { public static void main(String[] args) { System.out.print('H'); System.out.print('i'); System.out.println();//Moves cursor to next line System.out.println("Execution Ended"); } } ================================================== =================================== + Operator: The + operator performs two roles
class Program { public static void main(String[] args) {
Int Long
Float //used to store numeric floating point numbers Double
Char //used to store character
Boolean //use to store true/false
Variable initialization: Variable initialization syntax Variablename=value; Eg x=12; y=4.5; i=’k’; j=true;
Note : without initializing we will not be able to use the variable in java. class Program { public static void main(String[] args) { //Variable Declaration and Initialization int x=12; float y=4.5f; char j='S'; boolean i=true; System.out.println("Value of x is "+x); System.out.println("Value of y is "+y); System.out.println("Value of j is "+j); System.out.println("Value of i is "+i); } }
Note: in java language it is mandatory to initialize the variable before we use it in any operation otherwise the java compiler throws error
class Program { public static void main(String[] args) { //Variable Declaration and Initialization int x1=12; System.out.println("Value of x is "+x1); x1=24; //re assignment System.out.println("Value of x is "+x1); x1=45;//re assignment System.out.println("Value of x is "+x1);
class Program { public static void main(String[] args) { //This is the program to get compile time error final int x=123; //if we use final we can assign value for final variable only once System.out.println("Value of x is "+x); x=24; //re assignment so that it will give compilation error System.out.println("Value of x is "+x); } }
class test { static int x1=12; } class Program { public static void main(String[] args) { //This is the program to copy value from one variable to other test.x1=12; int x2=34; int x3=56; System.out.println("Value of x1 is "+test.x1); System.out.println("Value of x2 is "+x2); System.out.println("Value of x3 is "+x3); x2=test.x1;//copy value f x1 to x x3=x2;//copy value f x2 to x //System.out.println("Value of x1 is "+test.x1); System.out.println("Value of x2 is "+x2); System.out.println("Value of x3 is "+x3); } }
Java language provides a keyword by name “final” whenever a variable is declared by using final keyword we can initialize the variable only once if we try to re- initialize then the compiler throws error
class Program { public static void main(String[] args) { //When you are trying to declate float or long we need to suffic with f an l
class Program { public static void main(String[] args) { int num=5; System.out.println("Programn starts"); if (num==5) { System.out.println("Given number is 5"); } System.out.println("Programn Ends"); } }
If else Syntax If (Condition) { //Execute the statements1. } else { //Execute the statements2. }
Eg: class Program { public static void main(String[] args) { int age=17; System.out.println("Programn starts"); if (age>=18) { System.out.println("Eligible to Vote"); } else { System.out.println("Not Eligible to Vote"); } System.out.println("Programn Ends"); } }
If elseif Syntax If (Condition) { //Execute the statements1. } elseif(Condition)
//Execute the statements2. } else { //Execute the statements3. }
Eg: class Program { public static void main(String[] args) { int num=6 ; System.out.println("*****Program starts*****"); if (num==5) { System.out.println("Given number is "+num); } else if (num==7) { System.out.println("Given number is "+num); } else System.out.println("Given number is Neither5 Nor7 "); System.out.println("*****Program Ends*****");
} }
Switch Syntax Switch (Condition) { Case 1://Execute the statements1. Break; Case 2://Execute the statements2. Break; Case 3://Execute the statements3. Break; Case 4://Execute the statements4. Break; }
Eg: class Program { public static void main(String[] args) { int Marks=70;
do while loop syntax do { //statements Increment/decrement } While(condition);
Execution flow
class Program { public static void main(String[] args) { for(int i=1; i<=5;i++) { System.out.print(i); } System.out.print("\n Thankyou"); } } ================================================== ================================== class Program { public static void main(String[] args) { for(int i=5; i>=1;i--) { System.out.print(i); } System.out.print("\nThankyou"); } } ================================================== ================================== class Program //Nested for loop { public static void main(String[] args) {
for(int k=1; k<=5;k++) { System.out.println("Running outer loop-"+k);
for(int i=1; i<=5;i++) { System.out.println("\tRunning inner loop-"+i); } } } } ================================================== ================================== class Program //Nested for loop { public static void main(String[] args) { for(int k=1; k<=5;k++) { for(int i=1; i<=5;i++) { System.out.print(i); } System.out.println(); } } } ================================================== ================================== class Program //Nested for loop { public static void main(String[] args) { for(int k=1; k<=5;k++) { for(int i=5; i>=1;i--) { System.out.print(i); } System.out.println(); } } } ================================================== ================================== class Program //Nested for loop {
public static void main(String[] args) { for(int k=1; k<=5;k++) { for(int i=1; i<=k;i++) { System.out.print(k); } System.out.println(); } } } ================================================== ================================== class Program // Neted loop { public static void main(String[] args) { for(int k=5; k>=1;k--) { for(int i=1; i<=k;i++) { System.out.print(i); } System.out.println(); } } } ================================================== ================================== class Program // Nested loop { public static void main(String[] args) { for(int k=5; k>=1;k--) { for(int i=1; i<=k;i++) { System.out.print(k); } System.out.println(); } } } ================================================== ================================== class Program
// Nested loop important for interview to check for syntax and breaking for from infinite { public static void main(String[] args) { int i=1; for(;;) { System.out.print(i); i++; if (i==10) { break; } } } } ================================================== ================================== class Program // while looping { public static void main(String[] args) { int i=1; while (i<=5) { System.out.print(i); i++; } } } ================================================== ================================== class Program // while looping Assignment using while loop //1.User withdraw of rupees 2000 continously //2.once the balance reaches withdraw (5000) the loop to be terminated { public static void main(String[] args) { int bal=100000; int withdraw=2000; int minbal=5000; while ((bal-withdraw)>minbal) { bal=(bal-withdraw); System.out.println(bal); }
// Methods or Functions //Main method is the starting point of execution //can we write program without main method: yes //can we compile a program without main method: yes //can we execute a program without main method: No
class Program { static void test() { System.out.println("Running test() method.."); } //Main Method public static void main(String[] args) { //JVM starts execution here System.out.println("Execution started"); test(); //calling test() test(); //calling test() System.out.println("Execution ended"); }//JVM Ends execution here } ================================================== =================================== // Methods or Functions class Program { static void test() { System.out.println("Running test() method.."); demo();//call to demo() method System.out.println("Finish test() method.."); } static void demo() { System.out.println("Running demo() method.."); } //Main Method public static void main(String[] args) {//JVM starts execution here System.out.println("Execution started"); test(); //calling test() System.out.println("Execution ended"); }//JVM Ends execution here } ================================================== =================================== // Methods or Functions class Program { static void square(int n)
System.out.println("calculating square of "+n); int res; res=nn; System.out.println("Square is "+res); } //Main Method public static void main(String[] args) {//JVM starts execution here System.out.println("Execution started"); square(5); //when you are calling a function without initializing you cannot call square(9); square(283); System.out.println("Execution ended"); }//JVM Ends execution here } ================================================== =================================== // Methods or Functions class Program { static void areaOfTriangle(double base, double height) { System.out.println("calculating area of triangle"); System.out.println("\tBase is "+base); System.out.println("\tHeight is"+height); double a1; a1=0.5base*height; System.out.println("\tArea is "+a1); System.out.println("****************"); } //Main Method public static void main(String[] args) {//JVM starts execution here System.out.println("Execution started"); areaOfTriangle(5.0,8.0); areaOfTriangle(25.0,87.0); System.out.println("Execution ended"); }//JVM Ends execution here } ================================================== =================================== // Methods or Functions //in this example the return user can take it or he can ignore depends on user class Program { static double waiter(double amt) { System.out.println("Paying the bill"); double change; double billAmt=1400.0;