├── .DS_Store ├── Session1 ├── .DS_Store └── src │ └── MyApp.java ├── Session10 ├── .DS_Store ├── .classpath ├── .gitignore ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs └── src │ ├── Blocks.java │ ├── FileIO.java │ ├── MultiThreading.java │ ├── ObjectClass.java │ └── WrapperClasses.java ├── Session11 ├── .DS_Store ├── .classpath ├── .gitignore ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs ├── bms-cinema-hall.png └── src │ ├── ListDemo.java │ ├── RuntimeDemo.java │ ├── Synchronization.java │ └── UtilityDateClasses.java ├── Session12 ├── .DS_Store ├── .classpath ├── .gitignore ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs └── src │ └── com │ └── auribises │ ├── collections │ ├── MapDemo.java │ ├── QueueDemo.java │ └── SetDemo.java │ ├── controller │ └── DB.java │ ├── main │ └── CustomerManagementApp.java │ └── model │ └── Customer.java ├── Session13 ├── .DS_Store └── src │ └── com │ └── auribises │ ├── db │ ├── CustomerDAO.java │ ├── DAO.java │ └── DB.java │ ├── java8 │ ├── Java8Features.java │ └── StreamDemo.java │ ├── main │ └── CMSApp.java │ └── model │ └── Customer.java ├── Session14 ├── .DS_Store └── src │ ├── .DS_Store │ └── main │ ├── java │ └── com │ │ └── auribises │ │ ├── controller │ │ ├── LoginServlet.java │ │ └── RegisterServlet.java │ │ ├── db │ │ └── DB.java │ │ └── model │ │ └── User.java │ └── webapp │ ├── META-INF │ └── MANIFEST.MF │ ├── WEB-INF │ ├── lib │ │ └── mysql-connector-java-8.0.28.jar │ └── web.xml │ ├── index.html │ └── register.html ├── Session15 ├── .DS_Store └── src │ └── main │ ├── java │ └── com │ │ └── auribises │ │ ├── controller │ │ ├── FrontController.java │ │ ├── HomeServlet.java │ │ ├── LoginServlet.java │ │ └── RegisterServlet.java │ │ ├── db │ │ └── DB.java │ │ └── model │ │ └── User.java │ └── webapp │ ├── META-INF │ └── MANIFEST.MF │ ├── WEB-INF │ ├── lib │ │ └── mysql-connector-java-8.0.28.jar │ └── web.xml │ ├── errorpage.jsp │ ├── header.jsp │ ├── index.html │ ├── register.html │ ├── registerUser.jsp │ └── tags.jsp ├── Session16 ├── .DS_Store ├── pom.xml └── src │ ├── main │ └── java │ │ ├── beans.xml │ │ ├── com │ │ └── auribises │ │ │ ├── bean │ │ │ ├── Address.java │ │ │ ├── Connection.java │ │ │ ├── FoodItem.java │ │ │ ├── Pizza.java │ │ │ ├── PostProcessor.java │ │ │ └── Restaurant.java │ │ │ └── session16 │ │ │ ├── App.java │ │ │ ├── DIApp.java │ │ │ └── InheritanceApp.java │ │ ├── di.xml │ │ └── inheritance.xml │ └── test │ └── java │ └── com │ └── auribises │ └── session16 │ └── AppTest.java ├── Session17 ├── .DS_Store ├── beans.xml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── beans.xml │ │ ├── com │ │ └── auribises │ │ │ ├── bean │ │ │ ├── AfterAdvice.java │ │ │ ├── BeforeAdvice.java │ │ │ └── Product.java │ │ │ ├── db │ │ │ ├── DB.java │ │ │ └── DishMapper.java │ │ │ ├── model │ │ │ └── Dish.java │ │ │ └── session17 │ │ │ ├── App.java │ │ │ ├── HibernateApp.java │ │ │ └── SpringJDBCApp.java │ │ ├── dish.hbm.xml │ │ ├── hibernate.cfg.xml │ │ └── springjdbc.xml │ └── test │ └── java │ └── com │ └── auribises │ └── session17 │ └── AppTest.java ├── Session18 ├── pom.xml └── src │ ├── main │ └── java │ │ ├── com │ │ └── auribises │ │ │ ├── model │ │ │ ├── Address.java │ │ │ ├── Customer.java │ │ │ ├── Dish.java │ │ │ ├── Employee.java │ │ │ ├── Phone.java │ │ │ ├── Product.java │ │ │ ├── Restaurant.java │ │ │ └── SmartPhone.java │ │ │ └── session18 │ │ │ ├── App.java │ │ │ ├── InheritanceApp.java │ │ │ ├── OneToManyApp.java │ │ │ └── OneToOneApp.java │ │ ├── employee.hbm.xml │ │ ├── hibernate.cfg.xml │ │ ├── inheritance.hbm.xml │ │ ├── onetomany.hbm.xml │ │ └── onetoone.hbm.xml │ └── test │ └── java │ └── com │ └── auribises │ └── session18 │ └── AppTest.java ├── Session19 ├── .DS_Store ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── auribises │ │ │ ├── model │ │ │ ├── News.java │ │ │ └── User.java │ │ │ └── session19 │ │ │ ├── AppController.java │ │ │ ├── NewsWebService.java │ │ │ ├── ServletInitializer.java │ │ │ └── Session19Application.java │ └── resources │ │ ├── application.properties │ │ ├── static │ │ ├── index.html │ │ └── register.html │ │ └── templates │ │ ├── error.html │ │ ├── home.html │ │ ├── success.html │ │ └── welcome.html │ └── test │ └── java │ └── com │ └── auribises │ └── session19 │ └── Session19ApplicationTests.java ├── Session2 ├── .DS_Store └── src │ ├── DataTypes.java │ └── Operators.java ├── Session20A ├── .DS_Store ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── auribises │ │ │ └── session20a │ │ │ ├── ServletInitializer.java │ │ │ ├── Session20AApplication.java │ │ │ ├── controller │ │ │ └── AppController.java │ │ │ ├── model │ │ │ └── Customer.java │ │ │ └── repository │ │ │ └── CustomerRepository.java │ └── resources │ │ ├── application.properties │ │ └── static │ │ └── index.html │ └── test │ └── java │ └── com │ └── auribises │ └── session20a │ └── Session20AApplicationTests.java ├── Session20B ├── .DS_Store ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── auribises │ │ │ └── session20b │ │ │ ├── ServletInitializer.java │ │ │ ├── Session20BApplication.java │ │ │ ├── controller │ │ │ └── AppController.java │ │ │ ├── model │ │ │ └── Customer.java │ │ │ └── repository │ │ │ └── CustomerRepository.java │ └── resources │ │ ├── application.properties │ │ └── static │ │ └── index.html │ └── test │ └── java │ └── com │ └── auribises │ └── session20b │ └── Session20BApplicationTests.java ├── Session3 ├── .DS_Store └── src │ ├── Arrays.java │ ├── BreakContinue.java │ ├── ConditionalContructs.java │ ├── ConsoleBasedView.java │ ├── Loops.java │ └── NestedLoops.java ├── Session4 ├── .DS_Store ├── .classpath ├── .gitignore ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs └── src │ ├── ArraySyntaxes.java │ ├── AssignmentOnArrays.java │ ├── GC.java │ ├── Methods.java │ ├── MultiDimensioanlArrays.java │ ├── Strings.java │ ├── ValueVsReference.java │ └── WhyArrays.java ├── Session5 ├── .DS_Store ├── .classpath ├── .gitignore ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs └── src │ ├── ImmutableStrings.java │ ├── Methods.java │ ├── MethodsInMemory.java │ ├── MethodsInMemoryWithReferences.java │ ├── MutableStrings.java │ ├── StringBuiltInMethods.java │ └── StringComparison.java ├── Session6 ├── .DS_Store ├── .classpath ├── .gitignore ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs └── src │ ├── ConstructorChaining.java │ ├── Constructors.java │ ├── Encapsulation.java │ ├── MethodOverloading.java │ ├── OOPS.java │ ├── POJO.java │ └── ThisKeyword.java ├── Session7 ├── .DS_Store ├── .classpath ├── .gitignore ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs └── src │ ├── HasARelationship.java │ ├── InheritanceTypes.java │ ├── StaticVsNonStatic.java │ ├── WhatIsInheritance.java │ └── WhyInheritance.java ├── Session8 ├── .DS_Store ├── .classpath ├── .gitignore ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs └── src │ ├── AbstractClassAgain.java │ ├── AbstractClassChallenges.java │ ├── AbstractionWithInterfaces.java │ ├── FinalKeyword.java │ ├── InterfacesAgain.java │ ├── RTP.java │ ├── WhatIsAbstractClass.java │ ├── WhatIsInterface.java │ └── WhyAbstractClasses.java └── Session9 ├── .DS_Store ├── .classpath ├── .gitignore ├── .project ├── .settings └── org.eclipse.jdt.core.prefs └── src ├── .DS_Store ├── AnonymousClass.java ├── LambdaExpressions.java └── com ├── .DS_Store └── auribises ├── .DS_Store ├── exceptions ├── ExceptionHandling.java └── ThrowThrowsKeyword.java ├── one ├── App.java └── One.java └── two └── App.java /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/.DS_Store -------------------------------------------------------------------------------- /Session1/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session1/.DS_Store -------------------------------------------------------------------------------- /Session1/src/MyApp.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author ishant 3 | * 4 | */ 5 | public class MyApp { 6 | 7 | /** 8 | * @param args: it is command line arguments 9 | */ 10 | public static void main(String[] args) { 11 | System.out.println("Thank You all for being a wonderful audience"); 12 | System.out.println("I will see ya tomorrow now"); 13 | System.out.println("Code the same what we did in the class"); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Session10/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session10/.DS_Store -------------------------------------------------------------------------------- /Session10/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Session10/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | -------------------------------------------------------------------------------- /Session10/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Session10 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /Session10/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=16 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=16 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning 13 | org.eclipse.jdt.core.compiler.release=enabled 14 | org.eclipse.jdt.core.compiler.source=16 15 | -------------------------------------------------------------------------------- /Session10/src/Blocks.java: -------------------------------------------------------------------------------- 1 | 2 | public class Blocks { 3 | 4 | String currentLocation; 5 | String sourceLocation; 6 | String destinitionLocation; 7 | 8 | Blocks(){ 9 | System.out.println("3. Block Constructor"); 10 | 11 | if(currentLocation.equals("delhi")) { 12 | sourceLocation = "delhi"; 13 | destinitionLocation = "bangalore"; 14 | }else if(currentLocation.equals("bangalore")) { 15 | sourceLocation = "bangalore"; 16 | destinitionLocation = "delhi"; 17 | }else { 18 | sourceLocation = "mumbai"; 19 | destinitionLocation = "chennai"; 20 | } 21 | } 22 | 23 | public static void main(String[] args) { 24 | 25 | System.out.println("1. main"); 26 | Blocks bRef = new Blocks(); 27 | System.out.println("bRef data: "+bRef); 28 | 29 | } 30 | 31 | // Create initialization block 32 | // Pre-Processing of Data 33 | { 34 | System.out.println("2. Initialization Block"); 35 | currentLocation = "mumbai"; 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return "Blocks [currentLocation=" + currentLocation + ", sourceLocation=" + sourceLocation 41 | + ", destinitionLocation=" + destinitionLocation + "]"; 42 | } 43 | 44 | // In order to initialize something before program starts :) 45 | static { 46 | System.out.println("0. Static Block"); 47 | } 48 | 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /Session10/src/ObjectClass.java: -------------------------------------------------------------------------------- 1 | // Class -> Object 2 | // Object is the parent class for all the classes in Java 3 | // Hence RTP at Object level i.e. 4 | // Reference Variable of Object can refer to any Class in Java 5 | 6 | //class Student extends Object{ 7 | class Student { // extends Object will be done by compiler for us 8 | 9 | int rollNumber; 10 | String name; 11 | 12 | Student(){ 13 | 14 | } 15 | 16 | Student(int rollNumber, String name) { 17 | this.rollNumber = rollNumber; 18 | this.name = name; 19 | } 20 | 21 | public int hashCode() { 22 | return rollNumber; 23 | } 24 | 25 | // override equals here and compare 2 student objects with data :) 26 | 27 | @Override 28 | public String toString() { 29 | return "Student [rollNumber=" + rollNumber + ", name=" + name + "]"; 30 | } 31 | 32 | /*void show() { 33 | System.out.println("Student Details: "+rollNumber+" "+name); 34 | }*/ 35 | 36 | /*public String toString() { 37 | return rollNumber+" "+name; 38 | }*/ 39 | 40 | 41 | 42 | } 43 | 44 | public class ObjectClass { 45 | 46 | public static void main(String[] args) { 47 | 48 | Student s1 = new Student(1, "John"); 49 | Student s2 = new Student(1, "John"); 50 | 51 | System.out.println("s1 is: "+s1); 52 | System.out.println("s1.toString() is: "+s1.toString()); 53 | 54 | //s1.show(); 55 | 56 | System.out.println("s1 class is: "+s1.getClass()); 57 | 58 | 59 | System.out.println("s1 hashcode is: "+s1.hashCode()); 60 | System.out.println("s2 hashcode is: "+s2.hashCode()); 61 | 62 | 63 | /*Object oRef = new Student(); 64 | oRef = new String(); 65 | oRef = new RuntimeException();*/ 66 | 67 | 68 | if(s1 == s2) { 69 | System.out.println("s1 == s2"); 70 | }else { 71 | System.out.println("s1 != s2"); 72 | } 73 | 74 | if(s1.equals(s2)) { // for s1 and s2 should return true 75 | System.out.println("s1 equals s2"); 76 | }else { 77 | System.out.println("s1 not equals s2"); 78 | } 79 | 80 | // Assignment: use equals method in Student class as overrided version to compare 2 objects 81 | // you can google it and solve it :) 82 | 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /Session10/src/WrapperClasses.java: -------------------------------------------------------------------------------- 1 | 2 | public class WrapperClasses { 3 | 4 | public static void main(String[] args) { 5 | 6 | 7 | int i = 10; // Primitive Type 8 | 9 | // Convert Primitive to Reference type 10 | // i.e. we will have an object version of int through Integer class 11 | 12 | // BOXING: Converted primtive to Reference 13 | Integer iRef = Integer.valueOf(i); 14 | // UNBOXING: Get the int value back from Object 15 | int j = iRef.intValue(); 16 | 17 | 18 | // AUTO BOXING: Automatically i will be converted to iRef1. No need to valueOf Method 19 | Integer iRef1 = i; 20 | 21 | // AUTO UNBOXING 22 | int k = iRef1; // no need to execute intValue method 23 | 24 | // Same for every data type 25 | char ch = 'A'; 26 | Character cRef = ch; 27 | char ch1 = cRef; 28 | 29 | System.out.println(iRef1+" "+iRef1.hashCode()); 30 | 31 | /* 32 | int -> Integer 33 | byte -> Byte 34 | short -> Short 35 | long -> Long 36 | float -> Float 37 | double -> Double 38 | char -> Character 39 | boolean -> Boolean 40 | */ 41 | 42 | 43 | 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /Session11/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session11/.DS_Store -------------------------------------------------------------------------------- /Session11/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Session11/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | -------------------------------------------------------------------------------- /Session11/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Session11 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /Session11/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=16 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=16 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning 13 | org.eclipse.jdt.core.compiler.release=enabled 14 | org.eclipse.jdt.core.compiler.source=16 15 | -------------------------------------------------------------------------------- /Session11/bms-cinema-hall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session11/bms-cinema-hall.png -------------------------------------------------------------------------------- /Session11/src/RuntimeDemo.java: -------------------------------------------------------------------------------- 1 | 2 | class Student{ 3 | 4 | int roll; 5 | String name; 6 | 7 | Student(){ 8 | 9 | } 10 | 11 | Student(int roll, String name) { 12 | this.roll = roll; 13 | this.name = name; 14 | } 15 | 16 | // acts as a destructor. 17 | // gets executed when object is removed from memory 18 | @Override 19 | protected void finalize() throws Throwable { 20 | System.out.println("Object deleted: "+roll+" "+name); 21 | } 22 | 23 | } 24 | 25 | public class RuntimeDemo { 26 | 27 | public static void main(String[] args) { 28 | 29 | Student s1 = new Student(1, "John"); 30 | Student s2 = new Student(2, "Fionna"); 31 | 32 | // Reference to Java Runtime 33 | Runtime runtime = Runtime.getRuntime(); 34 | System.out.println("Processors: "+runtime.availableProcessors()); 35 | System.out.println("Free memory: "+runtime.freeMemory()); 36 | System.out.println("Max memory: "+runtime.maxMemory()); 37 | System.out.println("Total memory: "+runtime.totalMemory()); 38 | 39 | // in case we update references to null, objects will be instantly deleted from memory when gc is executed 40 | s1 = null; 41 | s2 = null; 42 | 43 | runtime.gc(); 44 | //System.gc(); 45 | 46 | } 47 | 48 | } 49 | 50 | // assignment: analyze the memory like free memory after deleting the objects i.e. executing gc call 51 | -------------------------------------------------------------------------------- /Session11/src/UtilityDateClasses.java: -------------------------------------------------------------------------------- 1 | import java.text.SimpleDateFormat; 2 | import java.util.Calendar; 3 | import java.util.Date; 4 | 5 | public class UtilityDateClasses { 6 | 7 | public static void main(String[] args) { 8 | 9 | Date date = new Date(); 10 | System.out.println("Today is: "+date); 11 | 12 | Calendar calendar = Calendar.getInstance(); 13 | 14 | System.out.println(calendar.get(Calendar.DAY_OF_MONTH)); 15 | System.out.println((calendar.get(Calendar.MONTH)+1)); // 0-11 16 | System.out.println(calendar.get(Calendar.YEAR)); 17 | 18 | //SimpleDateFormat format1 = new SimpleDateFormat("dd/MM/yyyy"); 19 | SimpleDateFormat format1 = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss"); 20 | String formattedDate = format1.format(date); 21 | System.out.println("formattedDate is: "+formattedDate); 22 | 23 | 24 | // We can manipulate Calendar data as well 25 | calendar.set(Calendar.DAY_OF_MONTH, 20); 26 | Date date1 = calendar.getTime(); 27 | System.out.println("date1 is: "+date1); 28 | } 29 | } 30 | 31 | // Assignment: Mr. John runs a wheel alignment and balancing company. 32 | // A client Mr George comes on 1st Feb, 2022 and his next visit is due after 7 weeks (7 can be taken as an input from User) 33 | // Suggest the date on which Mr. George has to come again :) 34 | -------------------------------------------------------------------------------- /Session12/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session12/.DS_Store -------------------------------------------------------------------------------- /Session12/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Session12/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | -------------------------------------------------------------------------------- /Session12/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Session12 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /Session12/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=16 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=16 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning 13 | org.eclipse.jdt.core.compiler.release=enabled 14 | org.eclipse.jdt.core.compiler.source=16 15 | -------------------------------------------------------------------------------- /Session12/src/com/auribises/collections/QueueDemo.java: -------------------------------------------------------------------------------- 1 | package com.auribises.collections; 2 | 3 | import java.util.PriorityQueue; 4 | import java.util.Queue; 5 | 6 | public class QueueDemo { 7 | 8 | public static void main(String[] args) { 9 | 10 | // Queue follow FIFO 11 | 12 | // Polymorphic Statement 13 | //Queue queue = new PriorityQueue(); 14 | 15 | // Direct Object Construction 16 | PriorityQueue queue = new PriorityQueue(); 17 | 18 | /*queue.add(10); 19 | queue.add(9);*/ 20 | 21 | for(int i=10;i>0;i--) { 22 | queue.add(i); 23 | } 24 | 25 | // Head 10 9 8 7 6 5 4 3 2 1 Tail 26 | 27 | // PriorityQueue will sort the data in Queue for Processing Purpose 28 | // Head 1 2 3 4 5 6 7 8 9 10 Tail 29 | 30 | // 1. peek -> returns the head of queue 31 | // 2. poll -> removes and return the head of queue 32 | 33 | //int head = queue.peek(); 34 | /*int head = queue.poll(); 35 | System.out.println("head is: "+head); 36 | System.out.println("Size of queue is: "+queue.size());*/ 37 | 38 | //System.out.println(queue.contains(9)); 39 | 40 | int size = queue.size(); 41 | for(int i=0;i on statement will be used to execute insert, update and delete SQL Commands 66 | result = statement.executeUpdate(sql); 67 | System.out.println("[DB] 3.2. Statement Executed"); 68 | } catch (Exception e) { 69 | System.err.println("Something Went Wrong: "+e); 70 | } 71 | 72 | return result; 73 | } 74 | 75 | public void closeConnection() { 76 | try { 77 | connection.close(); 78 | System.out.println("[DB] 4. Connection Closed"); 79 | } catch (Exception e) { 80 | System.err.println("Something Went Wrong: "+e); 81 | } 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /Session12/src/com/auribises/main/CustomerManagementApp.java: -------------------------------------------------------------------------------- 1 | package com.auribises.main; 2 | 3 | import com.auribises.controller.DB; 4 | import com.auribises.model.Customer; 5 | 6 | public class CustomerManagementApp { 7 | 8 | DB db; 9 | 10 | public CustomerManagementApp() { 11 | System.out.println("~~~~~~~~~~~~~~~~~~"); 12 | System.out.println("Welcome to CMS App"); 13 | System.out.println("~~~~~~~~~~~~~~~~~~"); 14 | db = new DB(); 15 | } 16 | 17 | void registerNewCustomer() { 18 | Customer customer = new Customer(); 19 | customer.inputCustomerDetails(); 20 | 21 | System.out.println("Please Review Customer Data: "); 22 | System.out.println(customer); 23 | 24 | String sql = customer.toSQL(); 25 | int result = db.executeSQLStatement(sql); 26 | 27 | String message = result>0 ? customer.name+" Inserted Successfully" : customer.name+" Not Inserted"; 28 | System.out.println(message); 29 | } 30 | 31 | void exitApp() { 32 | db.closeConnection(); 33 | System.out.println("Thank You For Using CMS App :)"); 34 | } 35 | 36 | public static void main(String[] args) { 37 | 38 | CustomerManagementApp app = new CustomerManagementApp(); 39 | app.registerNewCustomer(); 40 | app.exitApp(); 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /Session13/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session13/.DS_Store -------------------------------------------------------------------------------- /Session13/src/com/auribises/db/DAO.java: -------------------------------------------------------------------------------- 1 | package com.auribises.db; 2 | 3 | import java.util.List; 4 | 5 | // Generics in Java 6 | // T can be any name of your choice 7 | public interface DAO { 8 | 9 | int insert(T object); 10 | int update(T object); 11 | int delete(int id); 12 | List query(); 13 | 14 | } 15 | 16 | // DAO interface contains RULES which must be implemented by the class which will perform DB operations 17 | -------------------------------------------------------------------------------- /Session13/src/com/auribises/java8/Java8Features.java: -------------------------------------------------------------------------------- 1 | package com.auribises.java8; 2 | 3 | @FunctionalInterface 4 | interface Register{ 5 | void registerUser(String email, String password); 6 | } 7 | 8 | class Authentication{ 9 | 10 | static void login(String username, String password) { 11 | System.out.println("[Auth] User Logged In with username "+username); 12 | } 13 | 14 | void register(String username, String password) { 15 | System.out.println("[Auth] User Registered with username "+username); 16 | } 17 | } 18 | 19 | class DB{ 20 | 21 | static void fetchRecordsFromServer() { 22 | System.out.println("Fetching Records...."); 23 | System.out.println("Form the Server...."); 24 | } 25 | } 26 | 27 | 28 | public class Java8Features { 29 | 30 | public static void main(String[] args) { 31 | 32 | Register ref1 = new Register() { 33 | public void registerUser(String email, String password) { 34 | System.out.println("[AC] User registered with email "+email+" !!"); 35 | } 36 | }; 37 | 38 | ref1.registerUser("john@example.com", "john123"); 39 | 40 | Register ref2 = (email, password) -> System.out.println("[LE] User registered with email "+email+" !!"); 41 | ref2.registerUser("fionna@example.com", "fionna123"); 42 | 43 | Authentication auth = new Authentication(); 44 | 45 | // Method Reference for non static method | Java8 46 | // using operator :: if the signature of method is same we can simpy copy its reference 47 | // and hence, no need to define it :) 48 | //Register ref3 = auth::register; 49 | 50 | // Method Reference for static method | Java8 51 | Register ref3 = Authentication::login; 52 | ref3.registerUser("dave@example.com", "dave123"); 53 | 54 | // Define the run method as the definition what we have from fetchRecordsFromServer method :) 55 | Runnable runnable = DB::fetchRecordsFromServer; 56 | Thread th = new Thread(runnable); 57 | th.start(); 58 | 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /Session13/src/com/auribises/java8/StreamDemo.java: -------------------------------------------------------------------------------- 1 | package com.auribises.java8; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | import java.util.stream.Stream; 7 | 8 | public class StreamDemo { 9 | 10 | public static void main(String[] args) { 11 | 12 | 13 | /*List data = new ArrayList(); 14 | data.add(10); 15 | data.add(20); 16 | data.add(30); 17 | data.add(40); 18 | data.add(50);*/ 19 | 20 | List data = Arrays.asList(10, 20, 30, 40, 50); 21 | System.out.println("data is: "+data); 22 | 23 | // Read data into Stream i.e. Creating a Stream 24 | Stream stream = data.stream(); 25 | 26 | // Iterating in Stream 27 | // Perform any operation on Stream, it will release the stream afterwards 28 | //stream.forEach((element)->System.out.println(element)); 29 | 30 | // Re Using the Same Stream to perform some operation is error at runtime 31 | //stream.forEach((element)->System.out.println(element)); 32 | 33 | // Filtered the Stream 34 | //Stream filteredData = stream.filter((element)->element>=25); 35 | //filteredData.forEach((element)->System.out.println(element)); 36 | 37 | //Stream mappedData = stream.map((element)->element+2); 38 | //mappedData.forEach((element)->System.out.println(element)); 39 | 40 | System.out.println(stream.reduce((a, b)->a+b).get()); 41 | 42 | // Explore some more methods on Streams :) 43 | 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /Session13/src/com/auribises/model/Customer.java: -------------------------------------------------------------------------------- 1 | package com.auribises.model; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | import java.util.Scanner; 6 | 7 | public class Customer { 8 | 9 | public int cid; 10 | public String name; 11 | public String phone; 12 | public String email; 13 | public int rewardPoints; 14 | public String registeredOn; 15 | 16 | public Customer() { 17 | Date date = new Date(); 18 | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 19 | registeredOn = formatter.format(date); 20 | } 21 | 22 | Customer(int cid, String name, String phone, String email, int rewardPoints, String registeredOn) { 23 | this.cid = cid; 24 | this.name = name; 25 | this.phone = phone; 26 | this.email = email; 27 | this.rewardPoints = rewardPoints; 28 | this.registeredOn = registeredOn; 29 | } 30 | 31 | public void inputCustomerDetails() { 32 | 33 | Scanner scanner = new Scanner(System.in); 34 | 35 | System.out.println("Enter Customer Name: "); 36 | name = scanner.nextLine(); 37 | 38 | System.out.println("Enter Customer Phone: "); 39 | phone = scanner.nextLine(); 40 | 41 | System.out.println("Enter Customer Email: "); 42 | email = scanner.nextLine(); 43 | 44 | System.out.println("Enter Customer RewardPoints: "); 45 | rewardPoints = scanner.nextInt(); 46 | 47 | //scanner.close(); 48 | System.out.println("Customer Data Entered Successfully :) "); 49 | System.out.println("Customer Details:"); 50 | showCustomer(); 51 | } 52 | 53 | public void showCustomer() { 54 | System.out.println("---------------------------------------------------------------------------------------"); 55 | System.out.println(cid+"\t"+name+"\t"+phone+"\t"+email+"\t"+rewardPoints+"\t"+registeredOn); 56 | System.out.println("---------------------------------------------------------------------------------------"); 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return "Customer [cid=" + cid + ", name=" + name + ", phone=" + phone + ", email=" + email + ", rewardPoints=" 62 | + rewardPoints + ", registeredOn=" + registeredOn + "]"; 63 | } 64 | 65 | public String toSQL() { 66 | return "insert into Customer value (null, '"+name+"', '"+phone+"', '"+email+"', "+rewardPoints+", '"+registeredOn+"');"; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /Session14/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session14/.DS_Store -------------------------------------------------------------------------------- /Session14/src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session14/src/.DS_Store -------------------------------------------------------------------------------- /Session14/src/main/java/com/auribises/model/User.java: -------------------------------------------------------------------------------- 1 | package com.auribises.model; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | 6 | /* 7 | 8 | create table User( 9 | uid int primary key auto_increment, 10 | name varchar(256), 11 | email varchar(256), 12 | password varchar(256), 13 | regsiteredOn datetime 14 | ); 15 | 16 | 17 | */ 18 | 19 | public class User { 20 | 21 | public int uid; 22 | public String name; 23 | public String email; 24 | public String password; 25 | public String regsiteredOn; 26 | 27 | public User(){ 28 | Date date = new Date(); 29 | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); 30 | regsiteredOn = formatter.format(date); 31 | } 32 | 33 | public User(int uid, String name, String email, String password, String regsiteredOn) { 34 | this.uid = uid; 35 | this.name = name; 36 | this.email = email; 37 | this.password = password; 38 | this.regsiteredOn = regsiteredOn; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return "User [uid=" + uid + ", name=" + name + ", email=" + email + ", password=" + password + ", regsiteredOn=" 44 | + regsiteredOn + "]"; 45 | } 46 | 47 | public String toInsertSQL() { 48 | return "insert into User values(null, '"+name+"', '"+email+"', '"+password+"', '"+regsiteredOn+"')"; 49 | } 50 | 51 | public String toSelectSQL() { 52 | return "select * from User where email = '"+email+"' and password = '"+password+"'"; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Session14/src/main/webapp/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /Session14/src/main/webapp/WEB-INF/lib/mysql-connector-java-8.0.28.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session14/src/main/webapp/WEB-INF/lib/mysql-connector-java-8.0.28.jar -------------------------------------------------------------------------------- /Session14/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Session14 4 | 5 | index.html 6 | 7 | 8 | RegisterServlet 9 | RegisterServlet 10 | com.auribises.controller.RegisterServlet 11 | 12 | 13 | RegisterServlet 14 | /RegisterServlet 15 | /Register.do 16 | 17 | 18 | 19 | LoginServlet 20 | LoginServlet 21 | com.auribises.controller.LoginServlet 22 | 23 | 24 | LoginServlet 25 | /LoginServlet 26 | /Auth 27 | 28 | -------------------------------------------------------------------------------- /Session14/src/main/webapp/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Welcome to eStore 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 31 | 32 |
33 |

Welcome to eStore Web App

34 |

Shop from electronics to clothing to toys from us

35 |
36 | 37 |
38 |

Login Here:

39 |
40 | 41 |
42 |
43 | 44 | 45 |
46 |
47 | 48 | 49 |
50 | 51 |
52 | 53 | 54 |
55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /Session14/src/main/webapp/register.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | eStore - Registration 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 28 | 29 |
30 |

Welcome to eStore Web App

31 |

Shop from electronics to clothing to toys from us

32 |
33 | 34 | 35 |
36 |

Register with Your Details:

37 |
38 | 39 |
40 |
41 | 42 | 43 |
44 |
45 | 46 | 47 |
48 |
49 | 50 | 51 |
52 |
53 | 54 | 55 |
56 | 57 |
58 | 59 |
60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /Session15/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session15/.DS_Store -------------------------------------------------------------------------------- /Session15/src/main/java/com/auribises/controller/FrontController.java: -------------------------------------------------------------------------------- 1 | package com.auribises.controller; 2 | 3 | import jakarta.servlet.RequestDispatcher; 4 | import jakarta.servlet.ServletException; 5 | import jakarta.servlet.annotation.WebServlet; 6 | import jakarta.servlet.http.HttpServlet; 7 | import jakarta.servlet.http.HttpServletRequest; 8 | import jakarta.servlet.http.HttpServletResponse; 9 | import java.io.IOException; 10 | import java.io.PrintWriter; 11 | 12 | 13 | public class FrontController extends HttpServlet { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 18 | 19 | response.setContentType("text/html"); 20 | PrintWriter out = response.getWriter(); // PrintWriter Object will write the response back to client 21 | 22 | String typeOfRequest = request.getParameter("txtType"); 23 | String urlPattern = ""; 24 | 25 | 26 | if(typeOfRequest.equals("register")) { 27 | urlPattern = "Register.do"; 28 | }else if(typeOfRequest.equals("login")) { 29 | urlPattern = "Auth"; 30 | }else { 31 | out.print("Invalid Request"); 32 | } 33 | 34 | if(!urlPattern.isEmpty()) { 35 | // RequestDispatcher API is used to send the request to the Servlet 36 | // it takes input as the URL Pattern for the Servlet :) 37 | RequestDispatcher dispatcher = request.getRequestDispatcher(urlPattern); 38 | //dispatcher.forward(request, response); 39 | dispatcher.include(request, response); 40 | } 41 | 42 | StringBuffer buffer = new StringBuffer(); 43 | buffer.append("
"); 44 | buffer.append("

Welcome to Front Controller

"); 45 | buffer.append("
"); 46 | out.print(buffer.toString()); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /Session15/src/main/java/com/auribises/controller/HomeServlet.java: -------------------------------------------------------------------------------- 1 | package com.auribises.controller; 2 | 3 | import jakarta.servlet.ServletException; 4 | import jakarta.servlet.annotation.WebServlet; 5 | import jakarta.servlet.http.Cookie; 6 | import jakarta.servlet.http.HttpServlet; 7 | import jakarta.servlet.http.HttpServletRequest; 8 | import jakarta.servlet.http.HttpServletResponse; 9 | import jakarta.servlet.http.HttpSession; 10 | 11 | import java.io.IOException; 12 | import java.io.PrintWriter; 13 | import java.util.Date; 14 | 15 | import com.auribises.model.User; 16 | 17 | 18 | public class HomeServlet extends HttpServlet { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | 23 | protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 24 | 25 | response.setContentType("text/html"); 26 | PrintWriter out = response.getWriter(); 27 | 28 | 29 | // 2. Session Tracking with URL ReWriting - Read the data 30 | String name = request.getParameter("name"); 31 | String email = request.getParameter("email"); 32 | String uid = request.getParameter("uid"); 33 | 34 | StringBuffer buffer = new StringBuffer(); 35 | buffer.append("
"); 36 | buffer.append("

Welcome to Home Dear User :)

"); 37 | buffer.append("

Its: "+new Date()+"

"); 38 | 39 | // 1. Session Tracking with Cookies - Read the data 40 | // get all the cookies from the browser which are stored locally in it 41 | Cookie[] cookies = request.getCookies(); 42 | for(Cookie cookie : cookies) { 43 | buffer.append("

"+cookie.getName()+" | "+cookie.getValue()+"

"); 44 | } 45 | 46 | // 3. Session Tracking with HttpSession - Read the data 47 | HttpSession session = request.getSession(); 48 | User user = (User)session.getAttribute("keyUser"); 49 | 50 | buffer.append("

[URL REWRTITNG] USER DETAILS: "+uid+" | "+name+" | "+email+"

"); 51 | buffer.append("

[HTTP SESSION] USER DETAILS: "+user.uid+" | "+user.name+" | "+user.email+" | "+user.regsiteredOn+"

"); 52 | 53 | buffer.append("
"); 54 | out.print(buffer.toString()); 55 | 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /Session15/src/main/java/com/auribises/model/User.java: -------------------------------------------------------------------------------- 1 | package com.auribises.model; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | 6 | /* 7 | 8 | create table User( 9 | uid int primary key auto_increment, 10 | name varchar(256), 11 | email varchar(256), 12 | password varchar(256), 13 | regsiteredOn datetime 14 | ); 15 | 16 | 17 | */ 18 | 19 | public class User { 20 | 21 | public int uid; 22 | public String name; 23 | public String email; 24 | public String password; 25 | public String regsiteredOn; 26 | 27 | public User(){ 28 | Date date = new Date(); 29 | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); 30 | regsiteredOn = formatter.format(date); 31 | } 32 | 33 | public User(int uid, String name, String email, String password, String regsiteredOn) { 34 | this.uid = uid; 35 | this.name = name; 36 | this.email = email; 37 | this.password = password; 38 | this.regsiteredOn = regsiteredOn; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return "User [uid=" + uid + ", name=" + name + ", email=" + email + ", password=" + password + ", regsiteredOn=" 44 | + regsiteredOn + "]"; 45 | } 46 | 47 | public String toInsertSQL() { 48 | return "insert into User values(null, '"+name+"', '"+email+"', '"+password+"', '"+regsiteredOn+"')"; 49 | } 50 | 51 | public String toSelectSQL() { 52 | return "select * from User where email = '"+email+"' and password = '"+password+"'"; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Session15/src/main/webapp/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /Session15/src/main/webapp/WEB-INF/lib/mysql-connector-java-8.0.28.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session15/src/main/webapp/WEB-INF/lib/mysql-connector-java-8.0.28.jar -------------------------------------------------------------------------------- /Session15/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Session15 4 | 5 | index.html 6 | 7 | 8 | RegisterServlet 9 | RegisterServlet 10 | com.auribises.controller.RegisterServlet 11 | 12 | 13 | RegisterServlet 14 | /RegisterServlet 15 | /Register.do 16 | 17 | 18 | 19 | LoginServlet 20 | LoginServlet 21 | com.auribises.controller.LoginServlet 22 | 23 | 24 | LoginServlet 25 | /LoginServlet 26 | /Auth 27 | 28 | 29 | 30 | FrontController 31 | FrontController 32 | com.auribises.controller.FrontController 33 | 34 | 35 | FrontController 36 | /FrontController 37 | /Front 38 | /App 39 | 40 | 41 | 42 | HomeServlet 43 | HomeServlet 44 | com.auribises.controller.HomeServlet 45 | 46 | 47 | HomeServlet 48 | /HomeServlet 49 | /Home 50 | /Welcome 51 | 52 | -------------------------------------------------------------------------------- /Session15/src/main/webapp/errorpage.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | <%@ page isErrorPage="true" %> 4 | 5 | 6 | 7 | 8 | 9 | Error Page 10 | 11 | 12 |
13 |

Something Went Wrong

14 |

Message: <%= exception %>

15 |
16 | 17 | -------------------------------------------------------------------------------- /Session15/src/main/webapp/header.jsp: -------------------------------------------------------------------------------- 1 | <%@page import="java.util.Date"%> 2 | <%@ page language="java" contentType="text/html; charset=UTF-8" 3 | pageEncoding="UTF-8"%> 4 | 5 | 6 | 7 | 8 | eStore 9 | 10 | 11 | 12 |
13 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14 | 15 |

Welcome to eStore

16 |

Its: <%= new Date() %>

17 | 18 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /Session15/src/main/webapp/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Welcome to eStore 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 34 | 35 |
36 |

Welcome to eStore Web App

37 |

Shop from electronics to clothing to toys from us

38 |
39 | 40 |
41 |

Login Here:

42 |
43 | 44 |
45 | 46 |
47 | 48 | 49 |
50 |
51 | 52 | 53 |
54 | 55 | 56 |
57 | 58 | 59 |
60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /Session15/src/main/webapp/register.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | eStore - Registration 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 28 | 29 |
30 |

Welcome to eStore Web App

31 |

Shop from electronics to clothing to toys from us

32 |
33 | 34 | 35 |
36 |

Register with Your Details:

37 |
38 | 39 | 40 | 41 |
42 |
43 | 44 | 45 |
46 |
47 | 48 | 49 |
50 |
51 | 52 | 53 |
54 |
55 | 56 | 57 |
58 | 59 | 60 |
61 | 62 |
63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /Session15/src/main/webapp/registerUser.jsp: -------------------------------------------------------------------------------- 1 | <%@page import="com.auribises.db.DB"%> 2 | <%@ page import="com.auribises.model.User"%> 3 | <%@ page language="java" contentType="text/html; charset=UTF-8" 4 | pageEncoding="UTF-8"%> 5 | 6 | 7 | 8 | 9 | REGISTER USER 10 | 11 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | <% 26 | 27 | User user = new User(); 28 | 29 | //request is available as implicit object i.e. it is the same HttpServlet Request Object 30 | user.name = request.getParameter("txtName"); 31 | user.email = request.getParameter("txtEmail"); 32 | user.password = request.getParameter("txtPassword"); 33 | 34 | // Assignment: Implement DAO and use it with JSP Page for Database operations 35 | DB db = DB.getDB(); 36 | String sql = user.toInsertSQL(); 37 | int result = db.executeUpdate(sql); 38 | 39 | if(result>0){ 40 | %> 41 |

User Registered Successfully with Email: <%= user.email %>

42 | 43 | <% 44 | }else{ 45 | %> 46 |

User Not Registered

47 | <% 48 | } 49 | %> 50 | 51 |
52 | 53 | 54 | -------------------------------------------------------------------------------- /Session16/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session16/.DS_Store -------------------------------------------------------------------------------- /Session16/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.auribises 6 | Session16 7 | 0.1.0-SNAPSHOT 8 | jar 9 | 10 | Session16 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 1.8 16 | 1.8 17 | 18 | 19 | 20 | 21 | 22 | junit 23 | junit 24 | 3.8.1 25 | test 26 | 27 | 28 | 29 | org.springframework 30 | spring-context 31 | 5.3.15 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Session16/src/main/java/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Session16/src/main/java/com/auribises/bean/Address.java: -------------------------------------------------------------------------------- 1 | package com.auribises.bean; 2 | 3 | public class Address { 4 | 5 | String adrsLine; 6 | String city; 7 | String state; 8 | int zipCode; 9 | 10 | public Address() { 11 | System.out.println("[Address] - Object Constrcutde with default Constructor"); 12 | } 13 | 14 | public String getAdrsLine() { 15 | return adrsLine; 16 | } 17 | 18 | public void setAdrsLine(String adrsLine) { 19 | this.adrsLine = adrsLine; 20 | } 21 | 22 | public String getCity() { 23 | return city; 24 | } 25 | 26 | public void setCity(String city) { 27 | this.city = city; 28 | } 29 | 30 | public String getState() { 31 | return state; 32 | } 33 | 34 | public void setState(String state) { 35 | this.state = state; 36 | } 37 | 38 | public int getZipCode() { 39 | return zipCode; 40 | } 41 | 42 | public void setZipCode(int zipCode) { 43 | this.zipCode = zipCode; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "Address [adrsLine=" + adrsLine + ", city=" + city + ", state=" + state + ", zipCode=" + zipCode + "]"; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /Session16/src/main/java/com/auribises/bean/Connection.java: -------------------------------------------------------------------------------- 1 | package com.auribises.bean; 2 | 3 | // Bean is a POJO class only and is a terminology in the Spring FW 4 | // Bean is just like the model but with a mandatory presence of Getters and Setters 5 | public class Connection { 6 | 7 | // Attributes 8 | String url; 9 | String username; 10 | String password; 11 | 12 | public Connection() { 13 | System.out.println("[Connection] Object Constructed with Default Constructor"); 14 | } 15 | 16 | Connection(String url, String username, String password) { 17 | System.out.println("[Connection] Object Constructed with Paramterized Constructor"); 18 | this.url = url; 19 | this.username = username; 20 | this.password = password; 21 | } 22 | 23 | // Getters and Setters are mandatory and must be public :) 24 | public String getUrl() { 25 | return url; 26 | } 27 | 28 | public void setUrl(String url) { 29 | this.url = url; 30 | } 31 | 32 | public String getUsername() { 33 | return username; 34 | } 35 | 36 | public void setUsername(String username) { 37 | this.username = username; 38 | } 39 | 40 | public String getPassword() { 41 | return password; 42 | } 43 | 44 | public void setPassword(String password) { 45 | this.password = password; 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return "Connection [url=" + url + ", username=" + username + ", password=" + password + "]"; 51 | } 52 | 53 | // User defined methods and can be any name 54 | // but signature goes as void and no input 55 | public void myInit() { 56 | System.out.println("[Connection] myInit executed"); 57 | } 58 | 59 | public void myDestroy() { 60 | System.out.println("[Connection] myDestroy executed"); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /Session16/src/main/java/com/auribises/bean/FoodItem.java: -------------------------------------------------------------------------------- 1 | package com.auribises.bean; 2 | 3 | public class FoodItem { 4 | 5 | String name; 6 | int price; 7 | 8 | public FoodItem() { 9 | System.out.println("[FoodItem] - Object Constructed"); 10 | } 11 | 12 | public String getName() { 13 | return name; 14 | } 15 | 16 | public void setName(String name) { 17 | this.name = name; 18 | } 19 | 20 | public int getPrice() { 21 | return price; 22 | } 23 | 24 | public void setPrice(int price) { 25 | this.price = price; 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | return "FoodItem [name=" + name + ", price=" + price + "]"; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Session16/src/main/java/com/auribises/bean/Pizza.java: -------------------------------------------------------------------------------- 1 | package com.auribises.bean; 2 | 3 | public class Pizza extends FoodItem{ 4 | 5 | int size; 6 | String toppings; 7 | 8 | public Pizza() { 9 | System.out.println("[Pizza] - Object Constructed"); 10 | } 11 | 12 | public int getSize() { 13 | return size; 14 | } 15 | 16 | public void setSize(int size) { 17 | this.size = size; 18 | } 19 | 20 | public String getToppings() { 21 | return toppings; 22 | } 23 | 24 | public void setToppings(String toppings) { 25 | this.toppings = toppings; 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | return "Pizza [size=" + size + ", toppings=" + toppings + ", name=" + name + ", price=" + price + "]"; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Session16/src/main/java/com/auribises/bean/PostProcessor.java: -------------------------------------------------------------------------------- 1 | package com.auribises.bean; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.beans.factory.config.BeanPostProcessor; 5 | 6 | public class PostProcessor implements BeanPostProcessor{ 7 | 8 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 9 | 10 | System.out.println("[PostProcessor] - BEFORE "+beanName); 11 | 12 | Connection con = (Connection)bean; 13 | System.out.println("Before Connection username is: "+con.username); 14 | // updated the password 15 | con.setPassword("password123456"); 16 | 17 | return bean; 18 | } 19 | 20 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { 21 | 22 | System.out.println("[PostProcessor] - AFTER "+beanName); 23 | 24 | Connection con = (Connection)bean; 25 | System.out.println("After Connection username is: "+con.username); 26 | 27 | String password = con.getPassword(); 28 | // securing the passsword further 29 | con.setPassword(password.replace('s', 'q')); 30 | 31 | return bean; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Session16/src/main/java/com/auribises/session16/DIApp.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session16; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | import com.auribises.bean.Restaurant; 7 | 8 | public class DIApp { 9 | 10 | public static void main(String[] args) { 11 | 12 | 13 | ApplicationContext context = new ClassPathXmlApplicationContext("di.xml"); 14 | Restaurant restaurant = context.getBean("rRef", Restaurant.class); 15 | System.out.println(restaurant); 16 | System.out.println(restaurant.getAddress()); 17 | System.out.println("SEARCH KEYWORDS: "+restaurant.getSearchKeywords()); 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Session16/src/main/java/com/auribises/session16/InheritanceApp.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session16; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | import com.auribises.bean.Pizza; 7 | 8 | public class InheritanceApp { 9 | 10 | public static void main(String[] args) { 11 | 12 | ApplicationContext context = new ClassPathXmlApplicationContext("inheritance.xml"); 13 | Pizza pizza = context.getBean("pRef", Pizza.class); 14 | 15 | System.out.println("PIZZA DETAILS"); 16 | System.out.println(pizza); 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Session16/src/main/java/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 34 | 35 | 36 | 37 | 38 | Johns Cafe 39 | Coffee 40 | Pastry 41 | Cakes 42 | Italian Cafe 43 | 44 | 45 | 46 | 48 | 49 | 50 | 51 | 52 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /Session16/src/main/java/inheritance.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Session16/src/test/java/com/auribises/session16/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session16; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Session17/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session17/.DS_Store -------------------------------------------------------------------------------- /Session17/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | befAdv 24 | aftAdv 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Session17/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.auribises 6 | Session17 7 | 1.0 8 | jar 9 | 10 | Session17 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | 20 | junit 21 | junit 22 | 3.8.1 23 | test 24 | 25 | 26 | 27 | org.springframework 28 | spring-context 29 | 5.3.15 30 | 31 | 32 | 33 | mysql 34 | mysql-connector-java 35 | 8.0.28 36 | 37 | 38 | 39 | org.springframework 40 | spring-jdbc 41 | 5.3.15 42 | 43 | 44 | 45 | org.hibernate 46 | hibernate-core 47 | 5.6.5.Final 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /Session17/src/main/java/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | befAdv 24 | aftAdv 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Session17/src/main/java/com/auribises/bean/AfterAdvice.java: -------------------------------------------------------------------------------- 1 | package com.auribises.bean; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import org.springframework.aop.AfterReturningAdvice; 6 | 7 | public class AfterAdvice implements AfterReturningAdvice{ 8 | 9 | final String TAG = "[AfterAdvice] "; 10 | 11 | public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable { 12 | System.out.println(TAG+"afterReturning executed for "+method.getName()); 13 | 14 | // 3. Post-Processing -> Notify Customer with an email and also to the departments 15 | if(method.getName().equals("purchaseProduct")) { 16 | 17 | Product product = (Product)target; 18 | 19 | if(product.canBuy) { 20 | System.out.println(TAG+"We will deliver "+product.name+" at "+args[0]+" by "+args[1]); 21 | System.out.println(TAG+"Email Sent to "+args[2]+" for invoice of "+product.price); 22 | System.out.println(TAG+"Notifying Dispatch and Shipment for the product delivery"); 23 | 24 | }else { 25 | System.out.println(TAG+" Sorry. We are out of Stock..."); 26 | } 27 | } 28 | 29 | 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Session17/src/main/java/com/auribises/bean/BeforeAdvice.java: -------------------------------------------------------------------------------- 1 | package com.auribises.bean; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import org.springframework.aop.MethodBeforeAdvice; 6 | 7 | public class BeforeAdvice implements MethodBeforeAdvice{ 8 | 9 | final String TAG = "[BeforeAdvice] "; 10 | 11 | public void before(Method method, Object[] args, Object target) throws Throwable { 12 | 13 | System.out.println(TAG+"before executed for "+method.getName()); 14 | 15 | // 1. Pre Processing -> Validate for the Stock 16 | if(method.getName().equals("purchaseProduct")) { 17 | 18 | Product product = (Product)target; 19 | 20 | if(product.stock > 0) { 21 | System.out.println(TAG+"Stock Validated !"); 22 | System.out.println(TAG+"Initiating Payment Transaction..."); 23 | System.out.println(); 24 | product.canBuy = true; 25 | }else { 26 | System.out.println(TAG+" Sorry. We are out of Stock..."); 27 | } 28 | } 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Session17/src/main/java/com/auribises/db/DB.java: -------------------------------------------------------------------------------- 1 | package com.auribises.db; 2 | 3 | import java.util.List; 4 | 5 | import javax.sql.DataSource; 6 | 7 | import org.springframework.jdbc.core.JdbcTemplate; 8 | 9 | import com.auribises.model.Dish; 10 | 11 | public class DB { 12 | 13 | public DB() { 14 | System.out.println("[DB] Object Created"); 15 | } 16 | 17 | // will be injected using setter injection with DriverManagerDataSourc 18 | DataSource dataSource; 19 | 20 | // API JdbcTemplate will be used to perform CRUD Operations 21 | JdbcTemplate jdbcTemplate; 22 | 23 | public DataSource getDataSource() { 24 | return dataSource; 25 | } 26 | 27 | public void setDataSource(DataSource dataSource) { 28 | System.out.println("[DB] SETTER INJECTION FOR DataSource"); 29 | this.dataSource = dataSource; 30 | 31 | // Create the Object of JdbcTemplate by passing dataSource as input 32 | jdbcTemplate = new JdbcTemplate(dataSource); 33 | System.out.println("[DB] JDBC Template Object Created"); 34 | } 35 | 36 | public void insertDish(Dish dish) { 37 | String sql = "insert into Dish values(null, ?, ?)"; 38 | 39 | // update method -> insert update and delete 40 | int result = jdbcTemplate.update(sql, dish.name, dish.price); 41 | if(result>0) 42 | System.out.println(dish.name+" inserted in Table"); 43 | } 44 | 45 | // Assignment: Update and Delete on Dish using the same method jdbcTemplate.update :) 46 | 47 | public void fetchDishes() { 48 | String sql = "select * from Dish"; 49 | List dishes = jdbcTemplate.query(sql, new DishMapper()); 50 | dishes.forEach((dish)->System.out.println(dish)); 51 | } 52 | 53 | // Assignment:Explore queryForObject method -> i.e. when you will need to have a single object returned by SQL Statement 54 | 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /Session17/src/main/java/com/auribises/db/DishMapper.java: -------------------------------------------------------------------------------- 1 | package com.auribises.db; 2 | 3 | import java.sql.ResultSet; 4 | import java.sql.SQLException; 5 | 6 | import org.springframework.jdbc.core.RowMapper; 7 | 8 | import com.auribises.model.Dish; 9 | 10 | public class DishMapper implements RowMapper{ 11 | 12 | public Dish mapRow(ResultSet rs, int rowNum) throws SQLException { 13 | Dish dish = new Dish(); 14 | dish.dishId = rs.getInt(1); 15 | dish.name = rs.getString(2); 16 | dish.price = rs.getInt(3); 17 | return dish; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Session17/src/main/java/com/auribises/model/Dish.java: -------------------------------------------------------------------------------- 1 | package com.auribises.model; 2 | 3 | public class Dish { 4 | 5 | public int dishId; 6 | public String name; 7 | public int price; 8 | 9 | public Dish() { 10 | 11 | } 12 | 13 | public Dish(int dishId, String name, int price) { 14 | this.dishId = dishId; 15 | this.name = name; 16 | this.price = price; 17 | } 18 | 19 | public int getDishId() { 20 | return dishId; 21 | } 22 | 23 | public void setDishId(int dishId) { 24 | this.dishId = dishId; 25 | } 26 | 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | 35 | public int getPrice() { 36 | return price; 37 | } 38 | 39 | public void setPrice(int price) { 40 | this.price = price; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "Dish [dishId=" + dishId + ", name=" + name + ", price=" + price + "]"; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Session17/src/main/java/com/auribises/session17/App.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session17; 2 | 3 | import org.springframework.aop.framework.ProxyFactoryBean; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | 7 | import com.auribises.bean.Product; 8 | 9 | public class App 10 | { 11 | public static void main( String[] args ) 12 | { 13 | System.out.println( "Welcome to AOP demo" ); 14 | 15 | ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); 16 | 17 | // For AOP we need to configure -> ProxyFactoryBean in xml file 18 | // It has 2 attributes: 19 | // 1. target 2. interceptroNames 20 | 21 | //Product pRef = context.getBean("product", Product.class); 22 | Product pRef = context.getBean("productProxy", Product.class); 23 | 24 | //System.out.println("[App] Product Details: "); 25 | //System.out.println(pRef); 26 | 27 | pRef.purchaseProduct("Home", "6PM Evenning", "john@example.com"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Session17/src/main/java/com/auribises/session17/SpringJDBCApp.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session17; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | import org.springframework.jdbc.datasource.DriverManagerDataSource; 6 | 7 | import com.auribises.db.DB; 8 | import com.auribises.model.Dish; 9 | 10 | public class SpringJDBCApp { 11 | 12 | public static void main(String[] args) { 13 | 14 | /* 15 | 16 | Spring JDBC Procedure: 17 | 1. Configure Dependencies i.e. Spring Core, Spring JDBC and MySQL Library 18 | 2. Create the Model i.e. Object to Save 19 | 3. Configure DriverManagerDataSource API in xml file 20 | 4. Create a database class which will have setter injection for DataSource 21 | Also internally create the object of JDBCTemplate class from Spring jdcb module 22 | 5. Get the reference to the DB Object using IOC 23 | 6. Perform CRUD Operations using JDBC Template API from Spring FW 24 | 25 | */ 26 | 27 | ApplicationContext context = new ClassPathXmlApplicationContext("springjdbc.xml"); 28 | DB dbRef = context.getBean("db", DB.class); 29 | 30 | // Dish d1 = new Dish(0, "Noodles", 200); 31 | // Dish d2 = new Dish(0, "Burger", 50); 32 | // Dish d3 = new Dish(0, "Samosa", 20); 33 | 34 | // dbRef.insertDish(d1); 35 | // dbRef.insertDish(d2); 36 | // dbRef.insertDish(d3); 37 | 38 | dbRef.fetchDishes(); 39 | 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Session17/src/main/java/dish.hbm.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Session17/src/main/java/hibernate.cfg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | com.mysql.cj.jdbc.Driver 13 | jdbc:mysql://localhost/estoredb 14 | root 15 | 16 | 17 | 18 | 10 19 | 20 | 21 | 100 22 | 23 | 24 | org.hibernate.dialect.MySQL5Dialect 25 | 26 | 27 | true 28 | 29 | 30 | 31 | update 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Session17/src/main/java/springjdbc.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Session17/src/test/java/com/auribises/session17/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session17; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Session18/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.auribises 6 | Session18 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | Session18 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | junit 20 | junit 21 | 3.8.1 22 | test 23 | 24 | 25 | 26 | mysql 27 | mysql-connector-java 28 | 8.0.28 29 | 30 | 31 | 32 | org.hibernate 33 | hibernate-core 34 | 5.6.5.Final 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Session18/src/main/java/com/auribises/model/Address.java: -------------------------------------------------------------------------------- 1 | package com.auribises.model; 2 | 3 | public class Address { 4 | 5 | Integer aid; 6 | String adrsLine; 7 | String city; 8 | int zipCode; 9 | 10 | Customer customer; // HAS-A Relationship | 1 to 1 mapping 11 | 12 | public Address() { 13 | // TODO Auto-generated constructor stub 14 | } 15 | 16 | Address(Integer aid, String adrsLine, String city, int zipCode, Customer customer) { 17 | this.aid = aid; 18 | this.adrsLine = adrsLine; 19 | this.city = city; 20 | this.zipCode = zipCode; 21 | this.customer = customer; 22 | } 23 | 24 | public Integer getAid() { 25 | return aid; 26 | } 27 | 28 | public void setAid(Integer aid) { 29 | this.aid = aid; 30 | } 31 | 32 | public String getAdrsLine() { 33 | return adrsLine; 34 | } 35 | 36 | public void setAdrsLine(String adrsLine) { 37 | this.adrsLine = adrsLine; 38 | } 39 | 40 | public String getCity() { 41 | return city; 42 | } 43 | 44 | public void setCity(String city) { 45 | this.city = city; 46 | } 47 | 48 | public int getZipCode() { 49 | return zipCode; 50 | } 51 | 52 | public void setZipCode(int zipCode) { 53 | this.zipCode = zipCode; 54 | } 55 | 56 | public Customer getCustomer() { 57 | return customer; 58 | } 59 | 60 | public void setCustomer(Customer customer) { 61 | this.customer = customer; 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return "Address [aid=" + aid + ", adrsLine=" + adrsLine + ", city=" + city + ", zipCode=" + zipCode+"]"; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Session18/src/main/java/com/auribises/model/Customer.java: -------------------------------------------------------------------------------- 1 | package com.auribises.model; 2 | 3 | public class Customer { 4 | 5 | Integer cid; 6 | String name; 7 | String phone; 8 | String email; 9 | 10 | Address address; // HAS-A Relationship | 1 to 1 mapping 11 | 12 | public Customer() { 13 | // TODO Auto-generated constructor stub 14 | } 15 | 16 | Customer(Integer cid, String name, String phone, String email, Address address) { 17 | this.cid = cid; 18 | this.name = name; 19 | this.phone = phone; 20 | this.email = email; 21 | this.address = address; 22 | } 23 | 24 | public Integer getCid() { 25 | return cid; 26 | } 27 | 28 | public void setCid(Integer cid) { 29 | this.cid = cid; 30 | } 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | public void setName(String name) { 37 | this.name = name; 38 | } 39 | 40 | public String getPhone() { 41 | return phone; 42 | } 43 | 44 | public void setPhone(String phone) { 45 | this.phone = phone; 46 | } 47 | 48 | public String getEmail() { 49 | return email; 50 | } 51 | 52 | public void setEmail(String email) { 53 | this.email = email; 54 | } 55 | 56 | public Address getAddress() { 57 | return address; 58 | } 59 | 60 | public void setAddress(Address address) { 61 | this.address = address; 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return "Customer [cid=" + cid + ", name=" + name + ", phone=" + phone + ", email=" + email + ", address=" 67 | + address + "]"; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /Session18/src/main/java/com/auribises/model/Dish.java: -------------------------------------------------------------------------------- 1 | package com.auribises.model; 2 | 3 | public class Dish { 4 | 5 | Integer dishId; 6 | String name; 7 | Integer price; 8 | 9 | public Dish() { 10 | // TODO Auto-generated constructor stub 11 | } 12 | 13 | public Dish(Integer dishId, String name, Integer price) { 14 | this.dishId = dishId; 15 | this.name = name; 16 | this.price = price; 17 | } 18 | 19 | public Integer getDishId() { 20 | return dishId; 21 | } 22 | 23 | public void setDishId(Integer dishId) { 24 | this.dishId = dishId; 25 | } 26 | 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | 35 | public Integer getPrice() { 36 | return price; 37 | } 38 | 39 | public void setPrice(Integer price) { 40 | this.price = price; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "Dish [dishId=" + dishId + ", name=" + name + ", price=" + price + "]"; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Session18/src/main/java/com/auribises/model/Employee.java: -------------------------------------------------------------------------------- 1 | package com.auribises.model; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.Id; 7 | import javax.persistence.Table; 8 | 9 | @Entity 10 | @Table(name = "ESTORE_EMPLOYEES") 11 | public class Employee { 12 | 13 | @Id 14 | @GeneratedValue 15 | @Column(name = "EID") 16 | Integer eid; 17 | 18 | @Column(name = "NAME") 19 | String name; 20 | 21 | @Column(name = "EMAIL") 22 | String email; 23 | 24 | @Column(name = "SALARY") 25 | Integer salary; 26 | 27 | public Employee() { 28 | // TODO Auto-generated constructor stub 29 | } 30 | 31 | public Employee(Integer eid, String name, String email, Integer salary) { 32 | this.eid = eid; 33 | this.name = name; 34 | this.email = email; 35 | this.salary = salary; 36 | } 37 | 38 | public Integer getEid() { 39 | return eid; 40 | } 41 | 42 | public void setEid(Integer eid) { 43 | this.eid = eid; 44 | } 45 | 46 | public String getName() { 47 | return name; 48 | } 49 | 50 | public void setName(String name) { 51 | this.name = name; 52 | } 53 | 54 | public String getEmail() { 55 | return email; 56 | } 57 | 58 | public void setEmail(String email) { 59 | this.email = email; 60 | } 61 | 62 | public Integer getSalary() { 63 | return salary; 64 | } 65 | 66 | public void setSalary(Integer salary) { 67 | this.salary = salary; 68 | } 69 | 70 | @Override 71 | public String toString() { 72 | return "Employee [eid=" + eid + ", name=" + name + ", email=" + email + ", salary=" + salary + "]"; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /Session18/src/main/java/com/auribises/model/Phone.java: -------------------------------------------------------------------------------- 1 | package com.auribises.model; 2 | 3 | public class Phone extends Product{ 4 | 5 | Integer screenSize; 6 | Integer ram; 7 | Integer memory; 8 | 9 | public Phone() { 10 | // TODO Auto-generated constructor stub 11 | } 12 | 13 | Phone(Integer screenSize, Integer ram, Integer memory) { 14 | this.screenSize = screenSize; 15 | this.ram = ram; 16 | this.memory = memory; 17 | } 18 | 19 | public Integer getScreenSize() { 20 | return screenSize; 21 | } 22 | 23 | public void setScreenSize(Integer screenSize) { 24 | this.screenSize = screenSize; 25 | } 26 | 27 | public Integer getRam() { 28 | return ram; 29 | } 30 | 31 | public void setRam(Integer ram) { 32 | this.ram = ram; 33 | } 34 | 35 | public Integer getMemory() { 36 | return memory; 37 | } 38 | 39 | public void setMemory(Integer memory) { 40 | this.memory = memory; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "Phone [screenSize=" + screenSize + ", ram=" + ram + ", memory=" + memory + ", pid=" + pid + ", name=" 46 | + name + ", price=" + price + "]"; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /Session18/src/main/java/com/auribises/model/Product.java: -------------------------------------------------------------------------------- 1 | package com.auribises.model; 2 | 3 | public class Product { 4 | 5 | Integer pid; 6 | String name; 7 | Integer price; 8 | 9 | public Product() { 10 | // TODO Auto-generated constructor stub 11 | } 12 | 13 | Product(Integer pid, String name, Integer price) { 14 | this.pid = pid; 15 | this.name = name; 16 | this.price = price; 17 | } 18 | 19 | public Integer getPid() { 20 | return pid; 21 | } 22 | 23 | public void setPid(Integer pid) { 24 | this.pid = pid; 25 | } 26 | 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | 35 | public Integer getPrice() { 36 | return price; 37 | } 38 | 39 | public void setPrice(Integer price) { 40 | this.price = price; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "Product [pid=" + pid + ", name=" + name + ", price=" + price + "]"; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Session18/src/main/java/com/auribises/model/Restaurant.java: -------------------------------------------------------------------------------- 1 | package com.auribises.model; 2 | 3 | import java.util.List; 4 | 5 | public class Restaurant { 6 | 7 | Integer rid; 8 | String name; 9 | String phone; 10 | String operatingHours; 11 | Integer pricePerPerson; 12 | 13 | List dishes; // HAS-A Relationship | 1 to many :) 14 | 15 | public Restaurant() { 16 | // TODO Auto-generated constructor stub 17 | } 18 | 19 | Restaurant(Integer rid, String name, String phone, String operatingHours, Integer pricePerPerson, 20 | List dishes) { 21 | this.rid = rid; 22 | this.name = name; 23 | this.phone = phone; 24 | this.operatingHours = operatingHours; 25 | this.pricePerPerson = pricePerPerson; 26 | this.dishes = dishes; 27 | } 28 | 29 | public Integer getRid() { 30 | return rid; 31 | } 32 | 33 | public void setRid(Integer rid) { 34 | this.rid = rid; 35 | } 36 | 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | public String getPhone() { 46 | return phone; 47 | } 48 | 49 | public void setPhone(String phone) { 50 | this.phone = phone; 51 | } 52 | 53 | public String getOperatingHours() { 54 | return operatingHours; 55 | } 56 | 57 | public void setOperatingHours(String operatingHours) { 58 | this.operatingHours = operatingHours; 59 | } 60 | 61 | public Integer getPricePerPerson() { 62 | return pricePerPerson; 63 | } 64 | 65 | public void setPricePerPerson(Integer pricePerPerson) { 66 | this.pricePerPerson = pricePerPerson; 67 | } 68 | 69 | public List getDishes() { 70 | return dishes; 71 | } 72 | 73 | public void setDishes(List dishes) { 74 | this.dishes = dishes; 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | 80 | StringBuffer buffer = new StringBuffer(); 81 | dishes.forEach((dish)->buffer.append(dish.toString()+"\n")); 82 | 83 | return "Restaurant [rid=" + rid + ", name=" + name + ", phone=" + phone + ", operatingHours=" + operatingHours 84 | + ", pricePerPerson=" + pricePerPerson + "]\nDISHES:\n"+buffer.toString(); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /Session18/src/main/java/com/auribises/model/SmartPhone.java: -------------------------------------------------------------------------------- 1 | package com.auribises.model; 2 | 3 | public class SmartPhone extends Phone{ 4 | 5 | String os; 6 | String features; 7 | 8 | public SmartPhone() { 9 | // TODO Auto-generated constructor stub 10 | } 11 | 12 | SmartPhone(String os, String features) { 13 | this.os = os; 14 | this.features = features; 15 | } 16 | 17 | public String getOs() { 18 | return os; 19 | } 20 | 21 | public void setOs(String os) { 22 | this.os = os; 23 | } 24 | 25 | public String getFeatures() { 26 | return features; 27 | } 28 | 29 | public void setFeatures(String features) { 30 | this.features = features; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "SmartPhone [os=" + os + ", features=" + features + ", screenSize=" + screenSize + ", ram=" + ram 36 | + ", memory=" + memory + ", pid=" + pid + ", name=" + name + ", price=" + price + "]"; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Session18/src/main/java/com/auribises/session18/OneToOneApp.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session18; 2 | 3 | import org.hibernate.Session; 4 | import org.hibernate.SessionFactory; 5 | import org.hibernate.Transaction; 6 | import org.hibernate.boot.MetadataSources; 7 | import org.hibernate.boot.registry.StandardServiceRegistry; 8 | import org.hibernate.boot.registry.StandardServiceRegistryBuilder; 9 | 10 | import com.auribises.model.Address; 11 | import com.auribises.model.Customer; 12 | 13 | public class OneToOneApp { 14 | 15 | public static void main(String[] args) { 16 | 17 | Customer customer = new Customer(); 18 | customer.setName("John"); 19 | customer.setPhone("+91 99999 11111"); 20 | customer.setEmail("john@example.com"); 21 | 22 | Address address = new Address(); 23 | address.setAdrsLine("Redwood Shores"); 24 | address.setCity("Ludhiana"); 25 | address.setZipCode(141001); 26 | 27 | 28 | customer.setAddress(address); 29 | address.setCustomer(customer); 30 | 31 | System.out.println("CUSTOMER DETAILS: "); 32 | System.out.println(customer); 33 | 34 | // SessionFactory will create Session 35 | SessionFactory sessionFactory = null; 36 | // Session is connection to DB and using this API we perform CRUD operations 37 | Session session = null; 38 | //Transaction API executes the SQL Statements as a transaction means commit and rollback feature 39 | Transaction transaction = null; 40 | 41 | try { 42 | 43 | // Read the hibernate configuration xml file -> Parse the XML File :) 44 | StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build(); 45 | 46 | // build Session Factory 47 | sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); 48 | 49 | session = sessionFactory.openSession(); 50 | transaction = session.beginTransaction(); 51 | 52 | // Saving the Customer Object, Address Object associated with it, will be automatically saved :) 53 | session.save(customer); 54 | 55 | transaction.commit(); 56 | System.out.println("Transaction Committed by hibernate :)"); 57 | session.close(); 58 | sessionFactory.close(); 59 | 60 | } catch (Exception e) { 61 | System.err.println("Exception is: "+e); 62 | } 63 | } 64 | 65 | } 66 | 67 | // Assignment: 1. Perform other CRUD Operations 68 | // 2. Use Annotation to form 1 to 1 mapping rather than hbm file 69 | -------------------------------------------------------------------------------- /Session18/src/main/java/employee.hbm.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Session18/src/main/java/hibernate.cfg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | com.mysql.cj.jdbc.Driver 13 | jdbc:mysql://localhost/estoredb 14 | root 15 | 16 | 17 | 18 | 10 19 | 20 | 21 | 100 22 | 23 | 24 | org.hibernate.dialect.MySQL5Dialect 25 | 26 | 27 | true 28 | 29 | 30 | 31 | update 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Session18/src/main/java/inheritance.hbm.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /Session18/src/main/java/onetomany.hbm.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Session18/src/main/java/onetoone.hbm.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 27 | 28 | 29 | customer 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Session18/src/test/java/com/auribises/session18/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session18; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Session19/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session19/.DS_Store -------------------------------------------------------------------------------- /Session19/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /Session19/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session19/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Session19/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /Session19/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.6.3 9 | 10 | 11 | com.auribises 12 | Session19 13 | 0.0.1-SNAPSHOT 14 | war 15 | Session19 16 | Demo project for Spring Boot 17 | 18 | 11 19 | 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-thymeleaf 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-tomcat 33 | provided 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-test 38 | test 39 | 40 | 41 | 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-maven-plugin 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /Session19/src/main/java/com/auribises/model/News.java: -------------------------------------------------------------------------------- 1 | package com.auribises.model; 2 | 3 | public class News { 4 | 5 | String author; 6 | String title; 7 | String description; 8 | 9 | public News() { 10 | // TODO Auto-generated constructor stub 11 | } 12 | 13 | public News(String author, String title, String description) { 14 | this.author = author; 15 | this.title = title; 16 | this.description = description; 17 | } 18 | 19 | public String getAuthor() { 20 | return author; 21 | } 22 | 23 | public void setAuthor(String author) { 24 | this.author = author; 25 | } 26 | 27 | public String getTitle() { 28 | return title; 29 | } 30 | 31 | public void setTitle(String title) { 32 | this.title = title; 33 | } 34 | 35 | public String getDescription() { 36 | return description; 37 | } 38 | 39 | public void setDescription(String description) { 40 | this.description = description; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "News [author=" + author + ", title=" + title + ", description=" + description + "]"; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Session19/src/main/java/com/auribises/model/User.java: -------------------------------------------------------------------------------- 1 | package com.auribises.model; 2 | 3 | public class User { 4 | 5 | String name; 6 | String email; 7 | String password; 8 | 9 | public User() { 10 | // TODO Auto-generated constructor stub 11 | } 12 | 13 | public User(String name, String email, String password) { 14 | this.name = name; 15 | this.email = email; 16 | this.password = password; 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public void setName(String name) { 24 | this.name = name; 25 | } 26 | 27 | public String getEmail() { 28 | return email; 29 | } 30 | 31 | public void setEmail(String email) { 32 | this.email = email; 33 | } 34 | 35 | public String getPassword() { 36 | return password; 37 | } 38 | 39 | public void setPassword(String password) { 40 | this.password = password; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "User [name=" + name + ", email=" + email + ", password=" + password + "]"; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Session19/src/main/java/com/auribises/session19/NewsWebService.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session19; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import com.auribises.model.News; 11 | 12 | @RestController // -> text/json :) 13 | @RequestMapping(path = "/news") 14 | public class NewsWebService { 15 | 16 | @GetMapping("/v1") 17 | public HashMap> getNews(){ 18 | 19 | HashMap> newsMap = new HashMap>(); 20 | 21 | News n1 = new News("Reuters", 22 | "Wall Street set for second day of losses; US 10-year yield near 2% By Reuters", 23 | "Wall Street set for second day of losses; U.S. 10-year yield near 2%"); 24 | 25 | News n2 = new News("bloomberg", 26 | "Fed Doesn't Yet Favor a Half-Point Hike or an Emergency Move - Bloomberg", 27 | "To continue, please click the box below to let us know you're not a robot."); 28 | 29 | News n3 = new News("Tom Warren", 30 | "SSD prices could spike after Western Digital loses 6.5 billion", 31 | "Western Digital says it has lost at least 6.5 billion gigabytes of NAND flash storage."); 32 | 33 | News n4 = new News("CNN", 34 | "France announces plans to build up to 14 nuclear reactors - CNN", 35 | "France has announced plans to build up to 14 new nuclear reactors in a move that could help reduce greenhouse"); 36 | 37 | News n5 = new News("Ryan Browne", 38 | "Delivery Hero CEO apologizes to investors after 30% stock plunge, vows to stay the course - CNBC", 39 | "Delivery Hero CEO Niklas Östberg said he's truly sorry for all shareholders"); 40 | 41 | ArrayList news = new ArrayList(); 42 | news.add(n1); 43 | news.add(n2); 44 | news.add(n3); 45 | news.add(n4); 46 | news.add(n5); 47 | 48 | newsMap.put("usa", news); 49 | 50 | return newsMap; 51 | } 52 | 53 | } 54 | 55 | // Assignment: In the same project create a web service which returns the list of Users without passwords :) 56 | // i.e. return users as JSON 57 | -------------------------------------------------------------------------------- /Session19/src/main/java/com/auribises/session19/ServletInitializer.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session19; 2 | 3 | import org.springframework.boot.builder.SpringApplicationBuilder; 4 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 5 | 6 | public class ServletInitializer extends SpringBootServletInitializer { 7 | 8 | @Override 9 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 10 | return application.sources(Session19Application.class); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Session19/src/main/java/com/auribises/session19/Session19Application.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session19; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Session19Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Session19Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Session19/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8080 2 | -------------------------------------------------------------------------------- /Session19/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Welcome to eStore 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 31 | 32 |
33 |

Welcome to eStore Web App

34 |

Shop from electronics to clothing to toys from us

35 |
36 | 37 |
38 |

Login Here:

39 |
40 | 41 |
42 |
43 | 44 | 45 |
46 |
47 | 48 | 49 |
50 | 51 |
52 | 53 | 54 |
55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /Session19/src/main/resources/static/register.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | eStore - Registration 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 28 | 29 |
30 |

Welcome to eStore Web App

31 |

Shop from electronics to clothing to toys from us

32 |
33 | 34 | 35 |
36 |

Register with Your Details:

37 |
38 | 39 |
40 |
41 | 42 | 43 |
44 |
45 | 46 | 47 |
48 |
49 | 50 | 51 |
52 |
53 | 54 | 55 |
56 | 57 |
58 | 59 |
60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /Session19/src/main/resources/templates/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Success 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 |
17 |

Something Went Wrong !!

18 |

19 |

20 | 21 |

22 |
23 | 24 | -------------------------------------------------------------------------------- /Session19/src/main/resources/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Home 6 | 7 | 8 |
9 |

10 |

11 | 12 | -------------------------------------------------------------------------------- /Session19/src/main/resources/templates/success.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Success 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 |
17 | 18 |

19 |

20 | 21 |

22 |
23 | 24 | -------------------------------------------------------------------------------- /Session19/src/main/resources/templates/welcome.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Welcome 6 | 7 | 8 |
9 |

WELCOME TO SPRING BOOT TEMPLATES

10 |
11 | 12 | -------------------------------------------------------------------------------- /Session19/src/test/java/com/auribises/session19/Session19ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session19; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class Session19ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Session2/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session2/.DS_Store -------------------------------------------------------------------------------- /Session20A/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session20A/.DS_Store -------------------------------------------------------------------------------- /Session20A/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /Session20A/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session20A/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Session20A/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /Session20A/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.6.3 9 | 10 | 11 | com.auribises 12 | Session20A 13 | 0.0.1-SNAPSHOT 14 | war 15 | Session20A 16 | Demo project for Spring Boot 17 | 18 | 11 19 | 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-data-jpa 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | 31 | mysql 32 | mysql-connector-java 33 | runtime 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-tomcat 38 | provided 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-starter-test 43 | test 44 | 45 | 46 | 47 | 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-maven-plugin 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /Session20A/src/main/java/com/auribises/session20a/ServletInitializer.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session20a; 2 | 3 | import org.springframework.boot.builder.SpringApplicationBuilder; 4 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 5 | 6 | public class ServletInitializer extends SpringBootServletInitializer { 7 | 8 | @Override 9 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 10 | return application.sources(Session20AApplication.class); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Session20A/src/main/java/com/auribises/session20a/Session20AApplication.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session20a; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Session20AApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Session20AApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Session20A/src/main/java/com/auribises/session20a/controller/AppController.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session20a.controller; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.PathVariable; 10 | import org.springframework.web.bind.annotation.PostMapping; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RequestParam; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | import com.auribises.session20a.model.Customer; 16 | import com.auribises.session20a.repository.CustomerRepository; 17 | 18 | @RestController 19 | @RequestMapping(path = "/customer-api") 20 | public class AppController { 21 | 22 | @Autowired 23 | CustomerRepository repository; 24 | 25 | @PostMapping(path= "/add") 26 | public ResponseEntity addCustomer(@RequestParam String name, @RequestParam String email, @RequestParam String phone) { 27 | 28 | Customer customer = new Customer(null, name, email, phone); 29 | repository.save(customer); 30 | 31 | return new ResponseEntity(customer, HttpStatus.OK); 32 | 33 | } 34 | 35 | @GetMapping(path="/customers") 36 | public ResponseEntity> getCustomers(){ 37 | 38 | ArrayList customers = new ArrayList(); 39 | repository.findAll().forEach((customer) -> customers.add(customer)); 40 | 41 | return new ResponseEntity>(customers, HttpStatus.OK); 42 | 43 | } 44 | 45 | @GetMapping(path = "/update/{id}") 46 | public ResponseEntity updateCustomer(@PathVariable("id") Integer id){ 47 | 48 | Customer customer = new Customer(id, "John Jackson", "john.jackson@example.com", "9898090911"); 49 | repository.save(customer); 50 | 51 | return new ResponseEntity(customer, HttpStatus.OK); 52 | 53 | } 54 | 55 | @GetMapping(path = "/delete/{id}") 56 | public ResponseEntity deleteCustomer(@PathVariable("id") Integer id){ 57 | 58 | Customer customer = new Customer(); 59 | customer.setId(id); 60 | repository.delete(customer); 61 | 62 | return new ResponseEntity(customer, HttpStatus.OK); 63 | 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /Session20A/src/main/java/com/auribises/session20a/model/Customer.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session20a.model; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | 8 | @Entity 9 | public class Customer { 10 | 11 | @Id 12 | @GeneratedValue(strategy = GenerationType.AUTO) 13 | Integer id; 14 | 15 | String name; 16 | String email; 17 | String phone; 18 | 19 | public Customer() { 20 | // TODO Auto-generated constructor stub 21 | } 22 | 23 | public Customer(Integer id, String name, String email, String phone) { 24 | this.id = id; 25 | this.name = name; 26 | this.email = email; 27 | this.phone = phone; 28 | } 29 | 30 | public Integer getId() { 31 | return id; 32 | } 33 | 34 | public void setId(Integer id) { 35 | this.id = id; 36 | } 37 | 38 | public String getName() { 39 | return name; 40 | } 41 | 42 | public void setName(String name) { 43 | this.name = name; 44 | } 45 | 46 | public String getEmail() { 47 | return email; 48 | } 49 | 50 | public void setEmail(String email) { 51 | this.email = email; 52 | } 53 | 54 | public String getPhone() { 55 | return phone; 56 | } 57 | 58 | public void setPhone(String phone) { 59 | this.phone = phone; 60 | } 61 | 62 | @Override 63 | public String toString() { 64 | return "Customer [id=" + id + ", name=" + name + ", email=" + email + ", phone=" + phone + "]"; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /Session20A/src/main/java/com/auribises/session20a/repository/CustomerRepository.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session20a.repository; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | 5 | import com.auribises.session20a.model.Customer; 6 | 7 | public interface CustomerRepository extends CrudRepository{ 8 | // CustomerRepository can now be used to perform CRUD Operations on Customer 9 | } 10 | -------------------------------------------------------------------------------- /Session20A/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8080 2 | spring.jpa.hibernate.ddl-auto=update 3 | spring.datasource.url=jdbc:mysql://localhost/estoredb 4 | spring.datasource.username=root 5 | spring.datasource.password= 6 | spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -------------------------------------------------------------------------------- /Session20A/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Welcome to eStore 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 28 | 29 |
30 |

Welcome to Customer Management App

31 |

Manage Your Customers with Ease

32 |
33 | 34 |
35 |

ADD CUSTOMERS HERE

36 |
37 | 38 |
39 |
40 | 41 | 42 |
43 |
44 | 45 | 46 |
47 |
48 | 49 | 50 |
51 | 52 |
53 | 54 | 55 |
56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /Session20A/src/test/java/com/auribises/session20a/Session20AApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session20a; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class Session20AApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Session20B/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session20B/.DS_Store -------------------------------------------------------------------------------- /Session20B/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /Session20B/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session20B/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Session20B/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /Session20B/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.6.3 9 | 10 | 11 | com.auribises 12 | Session20B 13 | 0.0.1-SNAPSHOT 14 | war 15 | Session20B 16 | Demo project for Spring Boot 17 | 18 | 11 19 | 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-data-mongodb 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-tomcat 33 | provided 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-test 38 | test 39 | 40 | 41 | 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-maven-plugin 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /Session20B/src/main/java/com/auribises/session20b/ServletInitializer.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session20b; 2 | 3 | import org.springframework.boot.builder.SpringApplicationBuilder; 4 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 5 | 6 | public class ServletInitializer extends SpringBootServletInitializer { 7 | 8 | @Override 9 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 10 | return application.sources(Session20BApplication.class); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Session20B/src/main/java/com/auribises/session20b/Session20BApplication.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session20b; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Session20BApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Session20BApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Session20B/src/main/java/com/auribises/session20b/controller/AppController.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session20b.controller; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.PathVariable; 10 | import org.springframework.web.bind.annotation.PostMapping; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RequestParam; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | import com.auribises.session20b.model.Customer; 16 | import com.auribises.session20b.repository.CustomerRepository; 17 | 18 | @RestController 19 | @RequestMapping(path = "/mongo-customer-api") 20 | public class AppController { 21 | 22 | @Autowired 23 | CustomerRepository repository; 24 | 25 | @PostMapping(path= "/add") 26 | public ResponseEntity addCustomer(@RequestParam String name, @RequestParam String email, @RequestParam String phone) { 27 | 28 | Customer customer = new Customer(null, name, email, phone); 29 | repository.save(customer); 30 | 31 | return new ResponseEntity(customer, HttpStatus.OK); 32 | 33 | } 34 | 35 | @GetMapping(path="/customers") 36 | public ResponseEntity> getCustomers(){ 37 | 38 | ArrayList customers = new ArrayList(); 39 | repository.findAll().forEach((customer) -> customers.add(customer)); 40 | 41 | return new ResponseEntity>(customers, HttpStatus.OK); 42 | 43 | } 44 | 45 | @GetMapping(path = "/update/{id}") 46 | public ResponseEntity updateCustomer(@PathVariable("id") String id){ 47 | 48 | Customer customer = new Customer(id, "John Jackson", "john.jackson@example.com", "9898090911"); 49 | repository.save(customer); 50 | 51 | return new ResponseEntity(customer, HttpStatus.OK); 52 | 53 | } 54 | 55 | @GetMapping(path = "/delete/{id}") 56 | public ResponseEntity deleteCustomer(@PathVariable("id") String id){ 57 | 58 | Customer customer = new Customer(); 59 | customer.setId(id); 60 | repository.delete(customer); 61 | 62 | return new ResponseEntity(customer, HttpStatus.OK); 63 | 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /Session20B/src/main/java/com/auribises/session20b/model/Customer.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session20b.model; 2 | 3 | import org.springframework.data.annotation.Id; 4 | 5 | public class Customer { 6 | 7 | @Id 8 | String id; 9 | 10 | String name; 11 | String email; 12 | String phone; 13 | 14 | public Customer() { 15 | // TODO Auto-generated constructor stub 16 | } 17 | 18 | public Customer(String id, String name, String email, String phone) { 19 | this.id = id; 20 | this.name = name; 21 | this.email = email; 22 | this.phone = phone; 23 | } 24 | 25 | public String getId() { 26 | return id; 27 | } 28 | 29 | public void setId(String id) { 30 | this.id = id; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | 41 | public String getEmail() { 42 | return email; 43 | } 44 | 45 | public void setEmail(String email) { 46 | this.email = email; 47 | } 48 | 49 | public String getPhone() { 50 | return phone; 51 | } 52 | 53 | public void setPhone(String phone) { 54 | this.phone = phone; 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return "Customer [id=" + id + ", name=" + name + ", email=" + email + ", phone=" + phone + "]"; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /Session20B/src/main/java/com/auribises/session20b/repository/CustomerRepository.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session20b.repository; 2 | 3 | import org.springframework.data.mongodb.repository.MongoRepository; 4 | 5 | import com.auribises.session20b.model.Customer; 6 | 7 | public interface CustomerRepository extends MongoRepository{ 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Session20B/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8080 2 | spring.data.mongodb.uri=mongodb+srv://atpl:atpl@cluster0.eh8zx.gcp.mongodb.net/myFirstDatabase?retryWrites=true&w=majority 3 | spring.data.mongodb.database=estore -------------------------------------------------------------------------------- /Session20B/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Welcome to eStore 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 28 | 29 |
30 |

Welcome to Customer Management App [MONGO DB]

31 |

Manage Your Customers with Ease

32 |
33 | 34 |
35 |

ADD CUSTOMERS HERE

36 |
37 | 38 |
39 |
40 | 41 | 42 |
43 |
44 | 45 | 46 |
47 |
48 | 49 | 50 |
51 | 52 |
53 | 54 | 55 |
56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /Session20B/src/test/java/com/auribises/session20b/Session20BApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.auribises.session20b; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class Session20BApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Session3/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session3/.DS_Store -------------------------------------------------------------------------------- /Session3/src/Arrays.java: -------------------------------------------------------------------------------- 1 | 2 | public class Arrays { 3 | 4 | public static void main(String[] args) { 5 | 6 | int assignment1Marks = 90; 7 | int assignment2Marks = 80; 8 | int assignment3Marks = 85; 9 | int assignment4Marks = 72; 10 | int assignment5Marks = 64; 11 | 12 | // So, whenever we have lot of data to be processed, we need to use 13 | // Multi value Container :) 14 | // Array -> which says use homogeneous data 15 | 16 | // instead of creating 5 variables, we created a single variable marks 17 | // and stored 5 values :) 18 | int marks[] = {90, 80, 85, 72, 64}; 19 | 20 | System.out.println("assignment1Marks is: "+assignment1Marks); // primitive type will give value as output 21 | System.out.println("marks is: "+marks); // reference type will give hashcode as output 22 | 23 | // assignment1Marks -> is a variable which stores value 24 | // marks -> is a reference variable which stores the hashcode of the Array 25 | // and Array will be created inside the heap memory at run time 26 | 27 | /*System.out.println(marks[0]); 28 | System.out.println(marks[1]); 29 | System.out.println(marks[2]); 30 | System.out.println(marks[3]); 31 | System.out.println(marks[4]);*/ 32 | 33 | /*for(int idx=0;idx white 8 | // 1 -> black 9 | 10 | char whiteSquare = '\u25A0'; 11 | char blackSquare = '\u25A1'; 12 | 13 | /*System.out.print(whiteSquare+" "+blackSquare+" "); 14 | System.out.print(whiteSquare+" "+blackSquare+" "); 15 | System.out.print(whiteSquare+" "+blackSquare+" "); 16 | System.out.print(whiteSquare+" "+blackSquare+" ");*/ 17 | 18 | // Loops or Iterations 19 | // When in the code we need to do the same thing n-number of times 20 | 21 | 22 | int idx = 1; // starting point 23 | 24 | // checks condition at entry 25 | /*while(idx<=4) { // ending point 26 | System.out.print(whiteSquare+" "+blackSquare+" "); // the statement to be repeated again and again i.e. n number of times 27 | idx++; // expression with which we will move from starting point to the ending point 28 | }*/ 29 | 30 | // whenever the condition is wrong, the loop will be executed on a min of once :) 31 | /*do { 32 | System.out.print(whiteSquare+" "+blackSquare+" "); 33 | idx++; 34 | }while(idx<=4); // check condition at exit 35 | */ 36 | 37 | for(int i=1;i<=4;i++) { 38 | System.out.print(whiteSquare+" "+blackSquare+" "); 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Session3/src/NestedLoops.java: -------------------------------------------------------------------------------- 1 | 2 | public class NestedLoops { 3 | 4 | public static void main(String[] args) { 5 | 6 | myloop: // label to the i loop 7 | for(int i=1; i<=3; i++) { 8 | System.out.println(">> i is: "+i); 9 | 10 | // j loop is externally executed 3 times 11 | // j loop is internally executed 5 times 12 | for(int j=1; j<=5; j++) { 13 | System.out.print(j+" "); 14 | 15 | if(j==3) { 16 | break myloop; // break the outer loop 17 | } 18 | 19 | } 20 | 21 | System.out.println(); 22 | } 23 | 24 | System.out.println(); 25 | System.out.println(); 26 | 27 | /* 28 | 29 | Considering Chessboard :) 30 | 31 | 1 0 1 0 1 0 1 0 32 | 0 1 0 1 0 1 0 1 33 | 1 0 1 0 1 0 1 0 34 | 0 1 0 1 0 1 0 1 35 | 1 0 1 0 1 0 1 0 36 | 0 1 0 1 0 1 0 1 37 | 1 0 1 0 1 0 1 0 38 | 0 1 0 1 0 1 0 1 39 | 40 | 41 | */ 42 | 43 | /*for(int i=0;i<8;i++) { 44 | 45 | for(int j=0;j<8;j++) { 46 | 47 | if(i%2==0) { 48 | System.out.print((j+1)%2+" "); 49 | }else { 50 | System.out.print(j%2+" "); 51 | } 52 | } 53 | 54 | System.out.println(); 55 | }*/ 56 | 57 | char whiteSquare = '\u25A0'; 58 | char blackSquare = '\u25A1'; 59 | 60 | char queen = '\u2655'; 61 | 62 | for(int i=0;i<8;i++) { 63 | 64 | for(int j=0;j<8;j++) { 65 | 66 | if(i%2==0) { 67 | //System.out.print((j+1)%2+" "); 68 | //char square = (j+1)%2==0 ? blackSquare : whiteSquare; 69 | char square = (j+1)%2==0 ? blackSquare : queen; 70 | System.out.print(square+" "); 71 | }else { 72 | //System.out.print(j%2+" "); 73 | char square = j%2==0 ? blackSquare : whiteSquare; 74 | System.out.print(square+" "); 75 | } 76 | } 77 | 78 | System.out.println(); 79 | } 80 | 81 | // Assignment: 1. Ask an input from the user to place 4 queens 82 | // eg: user can say 1, 1 or may like 3, 1 83 | // 1, 1 -> place the queen on 1st row, 1st column and 3, 1 -> 3rd row, 1st column 84 | // it depends on the user, how many queens user wish to place on chessboard, with a max limit of 4 85 | // 2. Validate no queen can be placed in the same row or same column as of other queen 86 | 87 | 88 | 89 | 90 | 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /Session4/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session4/.DS_Store -------------------------------------------------------------------------------- /Session4/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Session4/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | -------------------------------------------------------------------------------- /Session4/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Session4 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /Session4/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=16 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=16 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning 13 | org.eclipse.jdt.core.compiler.release=enabled 14 | org.eclipse.jdt.core.compiler.source=16 15 | -------------------------------------------------------------------------------- /Session4/src/ArraySyntaxes.java: -------------------------------------------------------------------------------- 1 | 2 | public class ArraySyntaxes { 3 | 4 | public static void main(String[] args) { 5 | 6 | // Implicit Array Creation 7 | // compiler will automatically use new int[] on our behalf 8 | // Synatx1 9 | int array1[] = {10, 20, 30, 40, 50}; 10 | 11 | // Syntax2 12 | int[] array2 = {10, 20, 30, 40, 50}; 13 | 14 | // Explicit Array Creation 15 | // Synatx3 16 | int array3[] = new int[]{10, 20, 30, 40, 50}; 17 | 18 | // Syntax4 19 | int[] array4 = new int[]{10, 20, 30, 40, 50}; 20 | 21 | System.out.println("array1 is: "+array1); // HashCode 22 | System.out.println("array2 is: "+array2); // HashCode 23 | System.out.println("array3 is: "+array3); // HashCode 24 | System.out.println("array4 is: "+array4); // HashCode 25 | 26 | // array1, array2, array3 and array4 are reference variables 27 | // they will contain the hashcode for array 28 | 29 | // Syntax5 30 | int a1[], a2; // a1 is reference to array and a2 is a normal int 31 | int[] a3, a4; // a3 and a4 are both reference to an array 32 | 33 | a1 = new int[5]; 34 | a2 = 100; 35 | 36 | a3 = new int[5]; 37 | a4 = new int[10]; 38 | 39 | // for a1, a3 and a4 -> size is on the basis of which array is created with default values as 0 40 | 41 | // update data in a4 1st index 42 | a4[1] = 9; 43 | 44 | for(int element: a4) { 45 | System.out.print(element+" "); 46 | } 47 | 48 | 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /Session4/src/AssignmentOnArrays.java: -------------------------------------------------------------------------------- 1 | 2 | public class AssignmentOnArrays { 3 | 4 | public static void main(String[] args) { 5 | 6 | int[] pixel1 = {255, 0, 0}; // red :) 7 | int[] pixel2 = {123, 76, 44}; 8 | int[] pixel3 = {32, 120, 0}; 9 | int[] pixel4 = {123, 12, 120}; 10 | int[] pixel5 = {189, 18, 0}; 11 | int[] pixel6 = {187, 56, 130}; 12 | int[] pixel7 = {140, 76, 120}; 13 | int[] pixel8 = {90, 123, 90}; 14 | int[] pixel9 = {200, 145, 105}; 15 | 16 | // Image is an Array -> 3D 17 | int[][][] image = { 18 | {pixel1, pixel2, pixel3}, 19 | {pixel4, pixel5, pixel6}, 20 | {pixel7, pixel8, pixel9} 21 | }; 22 | 23 | // Assignment 1: Rotate the Pixels to the Right by 90 degree :) 24 | // 2: Rotate the Pixels to the Left by 180 degrees 25 | // 3: Grayscale the image -> eg: pixel1 = {255, 0, 0}; 26 | // we will add 255+0+0/3 -> 85 27 | // now pixel1 will be -> {85, 85, 85}, so d it for all the pixels 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Session4/src/GC.java: -------------------------------------------------------------------------------- 1 | 2 | public class GC { 3 | 4 | public static void main(String[] args) { 5 | 6 | int[] array = {10, 20, 30, 40, 50}; 7 | String name = new String("John Watson"); 8 | 9 | // arrays and strings are reference types 10 | // above, both will be created in the HEAP 11 | 12 | // from the heap, Garbage Collector deletes the unused objects automatically 13 | 14 | // GC is a program which runs in the JVM 15 | // GC checks after a certain interval of time if any object is unused or not 16 | // If unused remove from the memory 17 | 18 | // execute if you wish to release the unused objects from heap :) 19 | System.gc(); 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Session4/src/Strings.java: -------------------------------------------------------------------------------- 1 | 2 | public class Strings { 3 | 4 | public static void main(String[] args) { 5 | 6 | // Interned String 7 | String name1 = "John Watson"; // this remains in the memory till program is not finished 8 | 9 | // Object String 10 | String name2 = new String("Fionna Flynn"); // this can be deleted form the memory by garbage collector 11 | 12 | // name1 and name2 are known as reference variables 13 | 14 | // we create interned strings, which we know will be required throughout the application 15 | // eg: String appName = "WhatsApp"; 16 | 17 | 18 | // When we print Strings, reference variables rather than showing the hashcodes 19 | // they show the data directly 20 | System.out.println("name1 is: "+name1); 21 | System.out.println("name2 is: "+name2); 22 | 23 | // Let us print the name1 and name2 with execution of a method called toString() 24 | System.out.println("name1.toString() is: "+name1.toString()); 25 | System.out.println("name2.toString() is: "+name2.toString()); 26 | 27 | // i.e. when we print reference variable of String, 28 | // toString will be executed and it shoes the data rather than hashcodes 29 | 30 | // Lastly, toString gets executed automatically whenever we print reference variable of String :) 31 | 32 | System.gc(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Session4/src/ValueVsReference.java: -------------------------------------------------------------------------------- 1 | 2 | public class ValueVsReference { 3 | 4 | public static void main(String[] args) { 5 | 6 | int a = 10; 7 | int b = a; // Value Copy :) 8 | 9 | b += 5; // increment b by 5 10 | 11 | System.out.println("a is: "+a); 12 | System.out.println("b is: "+b); 13 | 14 | // Here a and b are different storage containers 15 | 16 | int[] a1 = {1, 2, 3, 4, 5}; 17 | System.out.println("a1 is: "+a1); 18 | 19 | int[] a2 = a1; // Reference Copy :) 20 | System.out.println("a2 is: "+a2); 21 | 22 | // a1 and a2 are different reference variables, but they hold the same hashcode :) 23 | // Hence, we have only 1 array in the Heap which is shared by 2 references a1 and a2 24 | 25 | // Let a2 modify the 2nd index in array 26 | a2[2] = 9; 27 | 28 | // Now, let us read the entire a1 29 | System.out.println("a1 contents: "); 30 | for(int element: a1) { 31 | System.out.print(element+" "); 32 | } 33 | 34 | System.out.println(); 35 | 36 | for(int idx=0;idx Representing the data 7 | int usaActiveCases = 635462; 8 | int usaRecoveredCases = 73544521; 9 | int usaNewCases = 41324; 10 | 11 | int indiaActiveCases = 454643; 12 | int indiaRecoveredCases = 6253432; 13 | int indiaNewCases = 88781; 14 | 15 | // Simplify the data storage with Arrays 16 | // i.e. when we have lot of data with homogeneous profile, we must use arrays :) 17 | int[] usaCases = {635462, 73544521, 41324}; 18 | int[] indiaCases = {454643, 6253432, 88781}; 19 | int[] ukCases = {88734, 23909, 275345}; 20 | 21 | 22 | int punjab = 1545; 23 | int himachal = 748; 24 | int up = 869; 25 | int goa = 86989; 26 | 27 | int total = punjab + himachal + up + goa; //..... 28 | 29 | int[] activeCasesInIndiaStatewise = {1545, 748, 869, 86989, 2364, 23234, 984, 122, 565}; 30 | 31 | int totalActiveCases = 0; 32 | for(int element : activeCasesInIndiaStatewise) { 33 | totalActiveCases += element; 34 | } 35 | 36 | System.out.println("totalActiveCases: "+totalActiveCases); 37 | 38 | double[] data = {2.2, 3.3, 4.4}; 39 | for(double anyName: data) { 40 | //... 41 | } 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Session5/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session5/.DS_Store -------------------------------------------------------------------------------- /Session5/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Session5/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | -------------------------------------------------------------------------------- /Session5/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Session5 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /Session5/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=16 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=16 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning 13 | org.eclipse.jdt.core.compiler.release=enabled 14 | org.eclipse.jdt.core.compiler.source=16 15 | -------------------------------------------------------------------------------- /Session5/src/ImmutableStrings.java: -------------------------------------------------------------------------------- 1 | 2 | public class ImmutableStrings { 3 | 4 | public static void main(String[] args) { 5 | 6 | // Strings are IMMUTABLE. Not Just in Java but in all programming languages. 7 | 8 | //int i = 10; // 10 -> is literal and is constant !! 9 | 10 | String quote = "be exceptional"; // similarly, we cannot modify "be exceptional" literal 11 | // if we wish to manipulate a string, we get a new string in the memory 12 | String upperCaseQuote = quote.toUpperCase(); 13 | System.out.println("quote is: "+quote); 14 | System.out.println("upperCaseQuote is: "+upperCaseQuote); 15 | 16 | String names = "john, jennie, jim, jack, joe"; 17 | String replacedNames = names.replace('j', 'k'); 18 | System.out.println("names are: "+names); 19 | System.out.println("replacedNames are: "+replacedNames); 20 | 21 | // All in All, if we manipulate a String, we get a new String in memory :) 22 | 23 | // This is a no good statement :( 24 | quote = quote.toUpperCase(); // Strings are not mutable by this expression :( 25 | 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Session5/src/Methods.java: -------------------------------------------------------------------------------- 1 | 2 | public class Methods { 3 | 4 | // Function is created inside the class 5 | // In Java, we call the function as a Method 6 | 7 | // return type: it can be any possible data type i.e. primitive or reference 8 | // this is to return something at the end of function 9 | // we can specify it as void, if no data has to be returned 10 | // here in our case below it is int 11 | 12 | // name -> f 13 | // ideally a meaningful name following the camel case 14 | // i.e. startWithLowerAndThenUpperCase 15 | 16 | // definition -> what function should do { } 17 | 18 | // return statement is the last statement in our function 19 | // i.e. wherever return statement will occur in the function that will terminate the function 20 | 21 | //int f(int x, int y) { 22 | static int f(int x, int y) { 23 | 24 | //return 0; // end the function i.e. terminate it here 25 | 26 | //int result = x*x + y*y + 2*x*y; 27 | //return result; 28 | 29 | return (x*x + y*y + 2*x*y); 30 | } 31 | 32 | public static void main(String[] args) { 33 | 34 | // f(x, y) = x*x + y*y + 2*x*y 35 | // f(1, 2) = 1*1 2*2 + 2*1*2 => 9 36 | 37 | // Methods can be: 38 | // 1. non static 39 | // 2. static 40 | 41 | // Executing a non static method: 42 | // we need the object's reference for that class 43 | /*Methods refVar = new Methods(); // Object :) 44 | int result = refVar.f(10, 20); 45 | System.out.println("Result is: "+result);*/ 46 | 47 | // Executing a static method: 48 | //int result = Methods.f(10, 20); 49 | 50 | // in case static method and main belongs to the same class, we can skip the class name as well 51 | int result = f(10, 20); 52 | System.out.println("Result is: "+result); 53 | 54 | 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /Session5/src/MethodsInMemory.java: -------------------------------------------------------------------------------- 1 | class IncrementDecrement{ 2 | 3 | static int increment(int num) { 4 | return ++num; 5 | } 6 | 7 | 8 | static int decrement(int num) { 9 | return --num; 10 | } 11 | 12 | } 13 | 14 | 15 | public class MethodsInMemory { 16 | 17 | static void squareOfNumber(int number) { 18 | 19 | number = IncrementDecrement.increment(number); 20 | 21 | System.out.println("[SqON] started"); 22 | 23 | System.out.println("[SqON] number before is: "+number); // 11 24 | 25 | //number = number * number; // square the number and update the value of number 26 | number *= number; // same as above :) // 121 27 | 28 | System.out.println("[SqON] number after is: "+number); // 121 29 | 30 | System.out.println("[SqON] finished"); 31 | } 32 | 33 | // main is executed by JVM, whenever we run our program :) 34 | public static void main(String[] args) { 35 | 36 | System.out.println("[main] started"); 37 | 38 | int data = 10; 39 | System.out.println("[main] data before is: "+data); 40 | 41 | squareOfNumber(data); // Value Copy Operation :) 42 | 43 | System.out.println("[main] data after is: "+data); 44 | 45 | 46 | System.out.println("[main] finished"); 47 | 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /Session5/src/MethodsInMemoryWithReferences.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class MethodsInMemoryWithReferences { 5 | 6 | 7 | static void squareOfNumbers(int[] numbers) { // array as input 8 | System.out.println("[SqON] started"); 9 | 10 | System.out.println("[SqON] numbers is: "+numbers); 11 | System.out.println("[SqON] numbers before is: "+Arrays.toString(numbers)); 12 | 13 | for(int i=0;i USE StringBuffer :) 15 | // StringBuffer is thread-safe 16 | StringBuffer buffer = new StringBuffer("John"); 17 | buffer.append(" Watson"); 18 | System.out.println("buffer is: "+buffer); 19 | 20 | // StringBuffer cannot be created in an interned way 21 | // It will always be created as an Object 22 | //StringBuffer b1 = "Hello"; // error 23 | 24 | // Mutable Version of String in Java 25 | // A bit faster as compared to StringBuffer 26 | // StringBuilder is not thread-safe 27 | StringBuilder builder = new StringBuilder("Fionna"); 28 | builder.append(" Flynn"); 29 | System.out.println("builder is: "+builder); 30 | 31 | // Assignment: Explore the built in methods which are very much similar to Strings for StringBuffer and StringBuilder 32 | // Explore the way how capacity would work for StringBuilder ? 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Session5/src/StringBuiltInMethods.java: -------------------------------------------------------------------------------- 1 | 2 | public class StringBuiltInMethods { 3 | 4 | public static void main(String[] args) { 5 | 6 | String names = "john, jennie, jim, jack, joe"; 7 | 8 | int length = names.length(); 9 | System.out.println("Length of names is: "+length); 10 | 11 | int idx = names.indexOf('h'); 12 | System.out.println("idx of h is: "+idx); 13 | 14 | idx = names.lastIndexOf('o'); 15 | System.out.println("idx of o from the end is: "+idx); 16 | 17 | idx = names.indexOf("jim"); // it will give the index from where, jim's j starts :) 18 | System.out.println("jim index is: "+idx); // 14 19 | 20 | //String name = names.substring(idx); // 14 | from index 14 to end 21 | String name = names.substring(14, 17); // 14, 15, 16 22 | System.out.println(name); 23 | 24 | //char ch = names.charAt(idx); 25 | char ch = names.charAt(length-1); 26 | System.out.println("ch is: "+ch); // e 27 | 28 | char[] chArr = names.toCharArray(); 29 | int count = 0; 30 | for(char chr : chArr) { 31 | System.out.print(chr+" "); 32 | if(chr == 'j') { 33 | count++; 34 | } 35 | } 36 | System.out.println(); 37 | System.out.println("j appears "+count+" times"); 38 | 39 | String[] strArr = names.split(","); 40 | for(String str : strArr) { 41 | System.out.println(str.trim()); // any extra spaces from the front and end will be removed 42 | } 43 | 44 | String email = "john@example.com"; 45 | if(email.contains("@") && email.contains(".com")) { 46 | System.out.println("A Valid Email"); 47 | }else { 48 | System.out.println("Invalid Email"); 49 | } 50 | 51 | String songName = "hello.mp3"; 52 | if(songName.endsWith(".mp3")) { // startsWith 53 | System.out.println("We can play this audio file"); 54 | }else { 55 | System.out.println("invalid audio file"); 56 | } 57 | 58 | // Assignment: Explore more methods on String Class 59 | // Create an array of phone numbers with String data type 60 | // eg: String[] contacts = {"+91 99999 11111", "+1 444 110 6690" //.....}' 61 | // Now take a search keyword as input from user and filter the contacts accordingly using contains or startsWith or endsWith methods 62 | // Create this solution using the methods i.e. either static or non static of your choice 63 | 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /Session5/src/StringComparison.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class StringComparison { 4 | 5 | public static void main(String[] args) { 6 | 7 | // Interned Strings 8 | // They refer to the literals :) 9 | String s1 = "John"; 10 | String s2 = "John"; 11 | 12 | // String Objects 13 | // refers to the String objects in the heap which contains the literal 14 | String s3 = new String("John"); 15 | String s4 = new String("John"); 16 | 17 | // == operator will compare only references and not data 18 | 19 | if(s1 == s2) { 20 | System.out.println("s1 == s2"); 21 | }else { 22 | System.out.println("s1 != s2"); 23 | } 24 | 25 | if(s3 == s4) { 26 | System.out.println("s3 == s4"); 27 | }else { 28 | System.out.println("s3 != s4"); 29 | } 30 | 31 | if(s1 == s3) { 32 | System.out.println("s1 == s3"); 33 | }else { 34 | System.out.println("s1 != s3"); 35 | } 36 | 37 | String password = "john@123"; 38 | 39 | Scanner scanner = new Scanner(System.in); 40 | 41 | System.out.println("Enter a Password: "); 42 | String userPassword = scanner.nextLine(); 43 | 44 | scanner.close(); 45 | 46 | //if(password == userPassword) { // false -> compares reference variables with address inside them and not the String data 47 | //if(password.equals(userPassword)) { // true -> equals methods compares the data 48 | //if(password.equalsIgnoreCase(userPassword)) { // -> true | ignore case sensitivity 49 | 50 | //if(password.compareTo(userPassword) == 0) { // compareTo returns int -> if 0 then Strings are equal 51 | if(password.compareToIgnoreCase(userPassword) == 0) { 52 | System.out.println("Welcome to Home"); 53 | }else { 54 | System.out.println("Password MisMatched"); 55 | } 56 | 57 | /*if("john@123" == userPassword) { 58 | // :( 59 | }else { 60 | // :) 61 | }*/ 62 | 63 | // Assignment: Explore contentEquals() method in String 64 | 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /Session6/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session6/.DS_Store -------------------------------------------------------------------------------- /Session6/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Session6/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | -------------------------------------------------------------------------------- /Session6/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Session6 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /Session6/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=16 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=16 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning 13 | org.eclipse.jdt.core.compiler.release=enabled 14 | org.eclipse.jdt.core.compiler.source=16 15 | -------------------------------------------------------------------------------- /Session6/src/ConstructorChaining.java: -------------------------------------------------------------------------------- 1 | class Customer{ 2 | 3 | String name; 4 | String phone; 5 | String email; 6 | boolean isPrime; 7 | 8 | String membershipRenewalDueDate; 9 | boolean musicAccess; 10 | boolean videoAccess; 11 | 12 | Customer(){ 13 | // .. initialize with some default data 14 | } 15 | 16 | private Customer(boolean isPrime){ 17 | 18 | this.isPrime = isPrime; 19 | 20 | if(isPrime) { 21 | membershipRenewalDueDate = "26th Jan, 2023"; 22 | musicAccess = true; 23 | videoAccess = true; 24 | } 25 | } 26 | 27 | Customer(String name, String phone, String email, boolean isPrime){ 28 | 29 | this(isPrime); // execute the above constructor 30 | 31 | this.name = name; 32 | this.phone = phone; 33 | this.email = email; 34 | 35 | } 36 | 37 | void showCustomer() { 38 | System.out.println("Customer Details"); 39 | System.out.println(name+" "+phone+" "+email); 40 | if(isPrime) { 41 | System.out.println("Prime Benefits: "); 42 | System.out.println("Membership Renews on "+membershipRenewalDueDate); 43 | System.out.println("Video Access: "+videoAccess); 44 | System.out.println("Music Access: "+videoAccess); 45 | } 46 | System.out.println(); 47 | } 48 | 49 | } 50 | 51 | 52 | public class ConstructorChaining { 53 | 54 | public static void main(String[] args) { 55 | 56 | Customer c1 = new Customer("John", "+91 99999 11111", "john@example.com", false); 57 | Customer c2 = new Customer("Fionna", "+91 98765 43210", "fionna@example.com", true); 58 | 59 | c1.showCustomer(); 60 | c2.showCustomer(); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /Session6/src/Encapsulation.java: -------------------------------------------------------------------------------- 1 | class PayTmMobileRecharge{ 2 | 3 | private String mobileNumber; 4 | private String operator; 5 | private int amount; 6 | 7 | PayTmMobileRecharge(){ 8 | mobileNumber = ""; 9 | operator = ""; 10 | amount = 10; 11 | } 12 | 13 | void showPayTmMobileRecharge() { 14 | System.out.println(mobileNumber+" with operator "+operator+" will be recharged for "+amount); 15 | } 16 | 17 | // Setter 18 | void setMobileNumber(String phone) { 19 | if(phone.isEmpty() || phone.length() < 10 || !phone.startsWith("+91")) { 20 | System.out.println("Please enter a valid phone number"); 21 | }else { 22 | mobileNumber = phone; 23 | } 24 | } 25 | 26 | // Getter 27 | String getMobileNumber() { 28 | return mobileNumber; 29 | } 30 | 31 | void setOperator(String op) { 32 | 33 | String operators = "airtel, vodafone, jio, bsnl, idea, mtnl"; 34 | 35 | if(operators.contains(op.toLowerCase())) { 36 | operator = op; 37 | }else { 38 | System.out.println("Please enter a valid Operator"); 39 | } 40 | } 41 | 42 | String getOperator() { 43 | return operator; 44 | } 45 | 46 | void setAmount(int amt) { 47 | 48 | if(amt >=10 && amount <=20000) { 49 | amount = amt; 50 | }else { 51 | System.out.println("Please enter a Amount"); 52 | } 53 | } 54 | 55 | int getAmount() { 56 | return amount; 57 | } 58 | } 59 | 60 | 61 | public class Encapsulation { 62 | 63 | public static void main(String[] args) { 64 | 65 | PayTmMobileRecharge recharge = new PayTmMobileRecharge(); 66 | System.out.println("recharge is: "+recharge); 67 | 68 | // Direct Access to attributes can lead to invalid data by user :) 69 | 70 | // if we mark them private, their scope is now limited only in the boudary of class 71 | //recharge.mobileNumber = "-91 ha ha he he"; 72 | //recharge.operator = "wow"; 73 | //recharge.amount = -200; 74 | 75 | recharge.setMobileNumber("+1 4441 6609 12"); 76 | recharge.setOperator("rogers"); 77 | recharge.setAmount(-200); 78 | 79 | System.out.println(); 80 | 81 | recharge.showPayTmMobileRecharge(); 82 | 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /Session6/src/MethodOverloading.java: -------------------------------------------------------------------------------- 1 | 2 | class Authenticate{ 3 | 4 | void login(String email, String password) { 5 | System.out.println("Logging in with email and password"); 6 | } 7 | 8 | void login(String phone, int otp) { 9 | System.out.println("Logging in with phone and otp"); 10 | } 11 | 12 | void login(String googleEmail) { 13 | System.out.println("Logging in with Google"); 14 | } 15 | 16 | } 17 | 18 | 19 | public class MethodOverloading { 20 | 21 | 22 | /* 23 | 24 | // Polymorphism 25 | Method Overloading -> More than 1 forms for the method 26 | 27 | Rules 28 | 1. Method name is same 29 | 2. Inputs should be unique 30 | 2.1 number of inputs 31 | 2.2 type of inputs 32 | 2.3 sequence of inputs 33 | 3. Return type has no role to play 34 | 35 | */ 36 | 37 | static void add(int a, int b) { 38 | int sum = a + b; 39 | System.out.println("sum of 2 nos is: "+sum); 40 | } 41 | 42 | // duplicate the method: below is error 43 | /*static int add(int num1, int num2) { 44 | int sum = num1 + num2; 45 | return sum; 46 | }*/ 47 | 48 | // number of inputs 49 | static void add(int a, int b, int c) { 50 | int sum = a + b + c; 51 | System.out.println("sum of 3 nos is: "+sum); 52 | } 53 | 54 | // data type of inputs 55 | static void add(double a, double b) { 56 | double sum = a + b; 57 | System.out.println("sum of 2 double nos is: "+sum); 58 | } 59 | 60 | // Sequence of inputs 61 | static void add(int a, double b) { 62 | double sum = a + b; 63 | System.out.println("sum of 2 double nos is: "+sum); 64 | } 65 | 66 | static void add(double a, int b) { 67 | double sum = a + b; 68 | System.out.println("sum of 2 double nos is: "+sum); 69 | } 70 | 71 | public static void main(String[] args) { 72 | 73 | add(10, 20); 74 | add(10, 20, 30); 75 | add(20.22, 30.33); 76 | add(10, 2.2); 77 | add(2.2, 22); 78 | 79 | Authenticate auth = new Authenticate(); 80 | auth.login("john@example.com", "pass123"); 81 | auth.login("+91 99999 11111", 2234); 82 | auth.login("fionna@gmail.com"); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /Session6/src/POJO.java: -------------------------------------------------------------------------------- 1 | 2 | // POJO -> Plain Old Java Object 3 | // Spring FW -> Bean 4 | // Industrially in a standard way it is -> Model 5 | class Patient{ 6 | 7 | private String name; 8 | private int age; 9 | private String disease; 10 | 11 | Patient() { 12 | } 13 | 14 | Patient(String name, int age, String disease) { 15 | this.name = name; 16 | this.age = age; 17 | this.disease = disease; 18 | } 19 | 20 | String getName() { 21 | return name; 22 | } 23 | 24 | void setName(String name) { 25 | this.name = name; 26 | } 27 | 28 | int getAge() { 29 | return age; 30 | } 31 | 32 | void setAge(int age) { 33 | this.age = age; 34 | } 35 | 36 | String getDisease() { 37 | return disease; 38 | } 39 | 40 | void setDisease(String disease) { 41 | this.disease = disease; 42 | } 43 | 44 | } 45 | 46 | 47 | public class POJO { 48 | 49 | public static void main(String[] args) { 50 | // TODO Auto-generated method stub 51 | 52 | } 53 | 54 | } 55 | 56 | // Assignment: Create an Object either Restraunt Object or Product from Amazon 57 | // list all the attributes and then create objects :) 58 | -------------------------------------------------------------------------------- /Session6/src/ThisKeyword.java: -------------------------------------------------------------------------------- 1 | class Student{ 2 | 3 | // Attributes 4 | int roll; 5 | String name; 6 | 7 | Student(){ 8 | System.out.println("this is: "+this); 9 | } 10 | 11 | // here as of now, attributes of object are same as that of inputs for constructor 12 | // so we cannot distinguish between lhs and rhs 13 | /*Student(int roll, String name){ 14 | roll = roll; 15 | name = name; 16 | }*/ 17 | 18 | // for the solution: 19 | Student(int roll, String name){ 20 | 21 | // now here LHS this.roll belongs to the object's attribute and rhs is of Student Constructor 22 | this.roll = roll; 23 | this.name = name; 24 | } 25 | 26 | // this is a reference variable which refers to the Current Object 27 | } 28 | 29 | 30 | public class ThisKeyword { 31 | 32 | public static void main(String[] args) { 33 | 34 | //Student s1 = new Student(101, "John"); 35 | Student s1 = new Student(); 36 | System.out.println("s1 is: "+s1); 37 | 38 | System.out.println(); 39 | 40 | 41 | Student s2 = new Student(); 42 | System.out.println("s2 is: "+s2); 43 | 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /Session7/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session7/.DS_Store -------------------------------------------------------------------------------- /Session7/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Session7/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | -------------------------------------------------------------------------------- /Session7/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Session7 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /Session7/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=16 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=16 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning 13 | org.eclipse.jdt.core.compiler.release=enabled 14 | org.eclipse.jdt.core.compiler.source=16 15 | -------------------------------------------------------------------------------- /Session7/src/InheritanceTypes.java: -------------------------------------------------------------------------------- 1 | class CA{ 2 | 3 | } 4 | 5 | // Single Level Inheritance -> MMT Flight Booking Use Case 6 | class CB extends CA{ 7 | 8 | } 9 | 10 | // Multi Level Inheritance -> Develop a Use Case for this 11 | class CC extends CB{ 12 | 13 | } 14 | 15 | class CD{ 16 | 17 | } 18 | 19 | // Multiple Inheritance -> Not Supported and Not Required 20 | /*class CE extends CA, CD{ 21 | 22 | }*/ 23 | 24 | // Hierarchy -> CA has 2 children CB and CF -> Develop a Use Case for this 25 | class CF extends CA{ 26 | 27 | } 28 | 29 | // Hybrid -> combination of above all 30 | 31 | public class InheritanceTypes { 32 | 33 | public static void main(String[] args) { 34 | 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Session7/src/WhatIsInheritance.java: -------------------------------------------------------------------------------- 1 | // What is Inheritance 2 | // Parent Child Relationship 3 | 4 | 5 | class Parent{ 6 | 7 | String fname; 8 | String lname; 9 | //private int wealth; 10 | int wealth; 11 | 12 | Parent(){ 13 | System.out.println("[Parent] Object Constructed"); 14 | fname = "John"; 15 | lname = "Watson"; 16 | wealth = 100000; 17 | } 18 | 19 | void show() { 20 | System.out.println("[Parent] Details: "+fname+" "+lname+" "+wealth); 21 | } 22 | } 23 | 24 | // Create Relationship of Parent and Child between 2 classes 25 | // using extends keyword in Java 26 | class Child extends Parent{ 27 | 28 | String fname; 29 | int wealth; 30 | String companyName; 31 | 32 | Child(){ 33 | System.out.println("[Child] Object Constructed"); 34 | fname = "Fionna"; 35 | wealth = 200000; 36 | companyName = "ABC Ltd"; 37 | } 38 | 39 | // ReDefining the same method, which is in the Parent, inside the child clas 40 | // OVERRIDING 41 | void show() { 42 | super.show(); // super as a reference variable available in Child, to access the Parent's Property 43 | System.out.println("[Child] Details: "+fname+" "+lname+" "+wealth+" "+companyName); 44 | } 45 | } 46 | 47 | // Inheritance Rules: 48 | // Rule#1 : Before the object of Child, Object of Parent is constructed 49 | // Rule#2 : Child, can access anything in Parent, if child does not have it. If child has the same property, it will access of its own 50 | // Rule#3 : Child cannot access anything marked as private in Parent 51 | 52 | public class WhatIsInheritance { 53 | 54 | public static void main(String[] args) { 55 | 56 | //Parent pRef = new Parent(); 57 | //pRef.show(); 58 | 59 | Child cRef = new Child(); 60 | 61 | System.out.println(); 62 | System.out.println("cRef is: "+cRef); 63 | 64 | // Previously, child here has no attribute wealth, it will update in the Parent Object 65 | // Now, as child also has the wealth attribute, it will subtract from its own attribute 66 | cRef.wealth -= 5000; 67 | 68 | System.out.println(); 69 | cRef.show(); 70 | 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /Session8/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session8/.DS_Store -------------------------------------------------------------------------------- /Session8/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Session8/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | -------------------------------------------------------------------------------- /Session8/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Session8 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /Session8/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=16 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=16 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning 13 | org.eclipse.jdt.core.compiler.release=enabled 14 | org.eclipse.jdt.core.compiler.source=16 15 | -------------------------------------------------------------------------------- /Session8/src/AbstractClassAgain.java: -------------------------------------------------------------------------------- 1 | 2 | class YoutubeChannel{ 3 | 4 | String name; 5 | Notification notification; 6 | 7 | YoutubeChannel(){ 8 | name = "auribises"; 9 | } 10 | 11 | void uploadVideo(String videoName) { 12 | System.out.println("Video Uploaded Successfully !!"); 13 | notification.notifyUser("Video Uploaded: "+videoName); 14 | } 15 | 16 | void sucbsribe(Notification notification) { 17 | this.notification = notification; 18 | } 19 | } 20 | 21 | abstract class Notification{ 22 | abstract void notifyUser(String message); 23 | } 24 | 25 | //here we get parent, child relation 26 | // Polymorphic Statement can be implemented i.e. Ref Var of Notification can refere to the User Object 27 | class User extends Notification{ 28 | 29 | String name; 30 | String email; 31 | 32 | User(){ 33 | name = "john"; 34 | email = "john@gmail.com"; 35 | } 36 | 37 | void notifyUser(String message) { 38 | System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~"); 39 | System.out.println("Dear, "+name); 40 | System.out.println("A New Notification Received"); 41 | System.out.println("Message: "+message); 42 | System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~"); 43 | } 44 | 45 | } 46 | 47 | public class AbstractClassAgain { 48 | 49 | public static void main(String[] args) { 50 | 51 | User uRef = new User(); 52 | 53 | YoutubeChannel channel = new YoutubeChannel(); 54 | channel.sucbsribe(uRef); // Polymorphic Statment 55 | 56 | channel.uploadVideo("Learning Java With Ishant"); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /Session8/src/AbstractClassChallenges.java: -------------------------------------------------------------------------------- 1 | abstract class PayPal{ 2 | abstract void onSuccess(); 3 | abstract void onFailure(); 4 | } 5 | 6 | abstract class PayTM{ 7 | abstract void onSuccess(); 8 | abstract void onFailure(); 9 | } 10 | 11 | abstract class RPay{ 12 | abstract void onSuccess(); 13 | abstract void onFailure(); 14 | } 15 | 16 | // We have a limitation for Zomato, not to extend more than 1 abstract class 17 | // as per the rule multiple inheritance is not supported 18 | /*class Zomato extends PayPal, PayTM, RPay{ 19 | 20 | }*/ 21 | 22 | // So this is now possible with interfaces !! 23 | 24 | 25 | public class AbstractClassChallenges { 26 | 27 | public static void main(String[] args) { 28 | // TODO Auto-generated method stub 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Session8/src/AbstractionWithInterfaces.java: -------------------------------------------------------------------------------- 1 | interface GPay{ 2 | 3 | // default keyword can be used to create a method in interface 4 | default void payFromGPay(int amount) { 5 | System.out.println("[GPay] Payment Done for amount: "+amount); 6 | onPaymentSuccess(); 7 | } 8 | 9 | void onPaymentSuccess(); 10 | void onFailed(); 11 | } 12 | 13 | interface PhonePe{ 14 | 15 | // default keyword can be used to create a method in interface 16 | default void payFromPhonePe(int amount) { 17 | System.out.println("[PhonePe] Payment Done for amount: "+amount); 18 | onSuccess(); 19 | } 20 | 21 | void onSuccess(); 22 | void onFailed(); 23 | } 24 | 25 | // Inheritance on Interfaces 26 | // Interfaces can inherit in multiple way 27 | interface SwiggyPaymentMethods extends GPay, PhonePe{ 28 | 29 | } 30 | 31 | class SwiggyPayments implements SwiggyPaymentMethods{ //implements GPay, PhonePe{ // multiple implementation 32 | 33 | public void onPaymentSuccess() { 34 | System.out.println("[Swiggy] Payment Received from GPay"); 35 | System.out.println("[Swiggy] We will deliver your order soon"); 36 | } 37 | 38 | public void onFailed() { 39 | System.out.println("[Swiggy] Payment Failed"); 40 | System.out.println("[Swiggy] Please use other payment method"); 41 | } 42 | 43 | public void onSuccess() { 44 | System.out.println("[Swiggy] Payment Received from PhonePe"); 45 | System.out.println("[Swiggy] We will deliver your order soon"); 46 | } 47 | 48 | } 49 | 50 | 51 | 52 | public class AbstractionWithInterfaces { 53 | 54 | public static void main(String[] args) { 55 | 56 | //SwiggyPayments payments = new SwiggyPayments(); 57 | //payments.payFromGPay(1000); 58 | //payments.payFromPhonePe(500); 59 | 60 | SwiggyPaymentMethods methods = new SwiggyPayments(); 61 | //methods.payFromGPay(1000); 62 | methods.payFromPhonePe(500); 63 | 64 | 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /Session8/src/FinalKeyword.java: -------------------------------------------------------------------------------- 1 | final class PaymentGateway{ // final class cannot be inherited 2 | 3 | //final void pay(int amount) { // final method cannot be overrided 4 | void pay(int amount) { 5 | System.out.println("[PaymentGateway]: Payment done successfully for amount "+amount); 6 | } 7 | 8 | } 9 | 10 | class MyAppPaymentsPage{// extends PaymentGateway{ 11 | 12 | /*void pay(int amount) { 13 | amount+=50; 14 | System.out.println("[MyAppPaymentsPage]: Thank you for order of amount "+amount); 15 | }*/ 16 | 17 | void placeOrderAndPay(int amount) { 18 | PaymentGateway gateway = new PaymentGateway(); 19 | gateway.pay(amount); 20 | } 21 | } 22 | 23 | 24 | public class FinalKeyword { 25 | 26 | public static void main(String[] args) { 27 | 28 | final String appName = "eStore"; 29 | 30 | // constants appName cannot be modified 31 | //appName = "eStore - Shop Anywhere"; 32 | 33 | MyAppPaymentsPage payment = new MyAppPaymentsPage(); 34 | //payment.pay(3000); 35 | 36 | payment.placeOrderAndPay(2500); 37 | 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /Session8/src/InterfacesAgain.java: -------------------------------------------------------------------------------- 1 | 2 | interface Inf1{ 3 | 4 | int number = 10; // => by default => public static final int number = 10; 5 | 6 | // public static final 7 | String appName = "Customer Management System"; 8 | 9 | default void show() { 10 | System.out.println("This is show of Inf1"); 11 | } 12 | 13 | static void hello() { 14 | System.out.println("This is hello from Inf1"); 15 | } 16 | 17 | void bye(); 18 | 19 | } 20 | 21 | class AB implements Inf1{ 22 | 23 | public void bye() { 24 | System.out.println("This is Bye from AB"); 25 | } 26 | 27 | void thanks() { 28 | System.out.println("Thank You All"); 29 | } 30 | } 31 | 32 | 33 | public class InterfacesAgain { 34 | 35 | public static void main(String[] args) { 36 | 37 | Inf1 ref = new AB(); 38 | ref.show(); 39 | ref.bye(); 40 | 41 | //ref.hello(); // static methods not accessible with reference 42 | //ref.thanks(); // methods inside the object not accessible by interface reference 43 | 44 | System.out.println("number is: "+ref.number); // allowed :) 45 | System.out.println("number is: "+Inf1.number); // ideal way as number is by default static -> must be accessed with interface name 46 | 47 | // static methods are accessible only with interface name :) 48 | Inf1.hello(); 49 | 50 | // Down - Casting 51 | AB aRef = (AB)ref; // copied the hash code from reference variable of the interface referring to AB object in AB ref 52 | aRef.thanks(); 53 | 54 | } 55 | 56 | } 57 | 58 | // Assignment: Code what we coded today :) 59 | -------------------------------------------------------------------------------- /Session8/src/WhatIsAbstractClass.java: -------------------------------------------------------------------------------- 1 | // After marking the class as abstract 2 | // we cannot create its objects ? 3 | abstract class CallBacks{ 4 | 5 | CallBacks() { 6 | System.out.println("CallBacks Constructed"); 7 | } 8 | 9 | // abstract methods: 10 | // 1. they can be created with abstract keyword 11 | // 2. they can only be created inside the abstract class 12 | // 3. they are the rules, which child must define 13 | abstract void onSuccess(); 14 | abstract void onFailure(); 15 | 16 | void show() { 17 | System.out.println("Hello from show of CallBacks"); 18 | } 19 | } 20 | 21 | class MyApp extends CallBacks{ 22 | 23 | MyApp(){ 24 | System.out.println("MyApp Constructed"); 25 | } 26 | 27 | void onSuccess() { 28 | System.out.println("[MyApp] Payment is Successfully Received"); 29 | } 30 | 31 | void onFailure() { 32 | System.out.println("[MyApp] Payment Failed"); 33 | } 34 | 35 | } 36 | 37 | public class WhatIsAbstractClass { 38 | 39 | public static void main(String[] args) { 40 | 41 | MyApp app = new MyApp(); 42 | app.onSuccess(); 43 | app.onFailure(); 44 | 45 | // abstract class objects cannot be created 46 | //CallBacks ref = new CallBacks(); // error 47 | 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /Session8/src/WhatIsInterface.java: -------------------------------------------------------------------------------- 1 | abstract class CA{ 2 | 3 | CA(){ 4 | 5 | } 6 | 7 | abstract void show(); 8 | 9 | void hello() { 10 | System.out.println("This is hello"); 11 | } 12 | } 13 | 14 | // For Abstraction :) 15 | 16 | interface Inf{ 17 | 18 | // Interfaces cannot have constructors 19 | 20 | /*Inf(){ 21 | 22 | }*/ 23 | 24 | // Interfaces has nothing to do with objects :) 25 | 26 | void show(); // by default -> public abstract void show(); 27 | 28 | // raw method definition i.e. non static methods not allowed :) 29 | /*void hello() { 30 | System.out.println("This is hell"); 31 | }*/ 32 | } 33 | 34 | class CB implements Inf{ 35 | 36 | public void show() { 37 | System.out.println("This is show of Inf"); 38 | } 39 | 40 | 41 | void bye() { 42 | System.out.println("This is done :)"); 43 | } 44 | } 45 | 46 | 47 | public class WhatIsInterface { 48 | 49 | public static void main(String[] args) { 50 | 51 | // Polymorphic Statement 52 | // Reference Variable of Interface can refere to the object of the class which implements it 53 | Inf ref = new CB(); 54 | ref.show(); 55 | 56 | //ref.bye(); // error 57 | 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /Session8/src/WhyAbstractClasses.java: -------------------------------------------------------------------------------- 1 | 2 | final class RazorPay{ 3 | 4 | boolean isBankInterfaceUp = false; 5 | RazorPayCallBacks callbacks; // reference variable of the RazorPayCallBacks 6 | 7 | 8 | void pay(int amount) { 9 | 10 | if(isBankInterfaceUp) { 11 | System.out.println("[RazorPay] Payment Done for amount: "+amount); 12 | callbacks.onPaymentSuccess("Payment Received Successfully"); 13 | }else { 14 | System.out.println("[RazorPay] Payment Failed for amount: "+amount); 15 | callbacks.onPaymentFailed("Payment Failed"); 16 | } 17 | } 18 | 19 | // Polymorphic Statement 20 | void on(RazorPayCallBacks callbacks) { // RazorPayCallBacks callbacks = this; 21 | this.callbacks = callbacks; 22 | } 23 | } 24 | 25 | abstract class RazorPayCallBacks{ 26 | abstract void onPaymentSuccess(String message); 27 | abstract void onPaymentFailed(String message); 28 | } 29 | 30 | 31 | 32 | class ZomatoPaymentsPage extends RazorPayCallBacks{ 33 | 34 | void payForOrder(int amount) { 35 | RazorPay payRef = new RazorPay(); // execute RazorPay Code 36 | // this -> reference to the current object of ZomatoPaymentsPage 37 | payRef.on(this); // let us pass the reference to the current object of ZomatoPaymentsPage 38 | payRef.pay(amount); 39 | } 40 | 41 | void onPaymentSuccess(String message) { 42 | System.out.println("[ZOMATO] Payment Received"); 43 | System.out.println("[ZOMATO] Your Order will be delivered soon"); 44 | } 45 | 46 | void onPaymentFailed(String message) { 47 | System.err.println("[ZOMATO] Payment Failed"); 48 | System.err.println("[ZOMATO] Please try with some other payment method"); 49 | } 50 | 51 | } 52 | 53 | public class WhyAbstractClasses { 54 | 55 | public static void main(String[] args) { 56 | 57 | ZomatoPaymentsPage page = new ZomatoPaymentsPage(); 58 | //System.out.println(page); 59 | 60 | page.payForOrder(2000); 61 | 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /Session9/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session9/.DS_Store -------------------------------------------------------------------------------- /Session9/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Session9/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | -------------------------------------------------------------------------------- /Session9/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Session9 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /Session9/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=16 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=16 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning 13 | org.eclipse.jdt.core.compiler.release=enabled 14 | org.eclipse.jdt.core.compiler.source=16 15 | -------------------------------------------------------------------------------- /Session9/src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session9/src/.DS_Store -------------------------------------------------------------------------------- /Session9/src/AnonymousClass.java: -------------------------------------------------------------------------------- 1 | /*abstract class Notification{ 2 | abstract void notifyUser(); 3 | abstract void sayHello(String name); 4 | }*/ 5 | 6 | interface Notification{ 7 | void notifyUser(); 8 | void sayHello(String name); 9 | } 10 | 11 | /*class SuperAdminUser implements Notification{ 12 | public void notifyUser() { 13 | System.out.println("A new notification received"); 14 | } 15 | }*/ 16 | 17 | 18 | public class AnonymousClass { 19 | 20 | public static void main(String[] args) { 21 | 22 | //SuperAdminUser user = new SuperAdminUser(); // Direct Object Construction 23 | // user.notifyUser(); 24 | 25 | // Polymorphic Statement 26 | //Notification notifcation = new SuperAdminUser(); 27 | //notifcation.notifyUser(); 28 | 29 | // Anonymous class 30 | // When we wish to have a single object for a class which implements interface 31 | Notification notification = new Notification() { 32 | 33 | public void notifyUser() { 34 | System.out.println("A new notification received"); 35 | } 36 | 37 | public void sayHello(String name) { 38 | System.out.println("Hello, "+name); 39 | } 40 | 41 | }; 42 | // Create an anonymous class, then create the object of anonymous class and return the hashcode to the reference variable 43 | System.out.println("notification is: "+notification); 44 | notification.notifyUser(); 45 | 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Session9/src/LambdaExpressions.java: -------------------------------------------------------------------------------- 1 | // Functional Interface: 2 | // An interface with just 1 single abstract method 3 | 4 | @FunctionalInterface 5 | interface Taxes{ 6 | double computeTaxes(int amount); 7 | 8 | default void hello() { 9 | System.out.println("Hello"); 10 | } 11 | 12 | static void wow() { 13 | System.out.println("wow"); 14 | } 15 | } 16 | 17 | public class LambdaExpressions { 18 | 19 | public static void main(String[] args) { 20 | 21 | // Anonymous Class 22 | /*Taxes refVar = new Taxes() { 23 | public double computeTaxes(int amount) { 24 | return amount*0.18; 25 | } 26 | }; 27 | */ 28 | 29 | // Lambda Expression: works only for functional interfaces :) 30 | /*Taxes refVar = (int amount) -> { 31 | return amount*0.18; 32 | };*/ 33 | 34 | // ignore data type for inputs 35 | /*Taxes refVar = (amount) -> { 36 | return amount*0.18; 37 | };*/ 38 | 39 | Taxes refVar = (amount) -> amount<=1000 ? amount*0.18 : amount*0.22; 40 | 41 | System.out.println("Taxes on 1000 are: "+refVar.computeTaxes(1000)); 42 | System.out.println("Taxes on 2000 are: "+refVar.computeTaxes(2000)); 43 | 44 | refVar.hello(); 45 | Taxes.wow(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Session9/src/com/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session9/src/com/.DS_Store -------------------------------------------------------------------------------- /Session9/src/com/auribises/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishantk/LPU-JavaEE-2022-2/0d433dac15a8043878dfd102b45d9e3f9ec7d3a3/Session9/src/com/auribises/.DS_Store -------------------------------------------------------------------------------- /Session9/src/com/auribises/one/App.java: -------------------------------------------------------------------------------- 1 | package com.auribises.one; 2 | 3 | public class App { 4 | 5 | public static void main(String[] args) { 6 | 7 | One oRef = new One(); 8 | Two tRef = new Two(); 9 | 10 | // oRef.pvtShow(); // error 11 | oRef.defShow(); 12 | oRef.protShow(); 13 | oRef.pubShow(); 14 | 15 | System.out.println(); 16 | 17 | // tRef.pvtShow(); // error 18 | tRef.defShow(); 19 | tRef.protShow(); 20 | tRef.pubShow(); 21 | 22 | } 23 | 24 | } 25 | 26 | // private: which can only be accessed inside the class boundary 27 | -------------------------------------------------------------------------------- /Session9/src/com/auribises/one/One.java: -------------------------------------------------------------------------------- 1 | package com.auribises.one; 2 | 3 | // public class 4 | public class One { 5 | 6 | // we can have both attributes and methods marked as private, default, protected or public 7 | 8 | private void pvtShow() { 9 | System.out.println("[One] This is private show"); 10 | } 11 | 12 | void defShow() { 13 | System.out.println("[One] This is default show"); 14 | } 15 | 16 | protected void protShow() { 17 | System.out.println("[One] This is protected show"); 18 | } 19 | 20 | public void pubShow() { 21 | System.out.println("[One] This is public show"); 22 | } 23 | 24 | } 25 | 26 | // default class 27 | class Two{ 28 | 29 | private void pvtShow() { 30 | System.out.println("[Two] This is private show"); 31 | } 32 | 33 | void defShow() { 34 | System.out.println("[Two] This is default show"); 35 | } 36 | 37 | protected void protShow() { 38 | System.out.println("[Two] This is protected show"); 39 | } 40 | 41 | public void pubShow() { 42 | System.out.println("[Two] This is public show"); 43 | } 44 | 45 | 46 | } 47 | 48 | // error: we cannot create private or protected class :) 49 | /* 50 | private class Three{ 51 | 52 | } 53 | 54 | protected class Four{ 55 | 56 | } 57 | */ 58 | 59 | // More then 1 public class not allowed 60 | /*public class Five{ 61 | 62 | }*/ -------------------------------------------------------------------------------- /Session9/src/com/auribises/two/App.java: -------------------------------------------------------------------------------- 1 | package com.auribises.two; 2 | 3 | import com.auribises.one.One; // One is public 4 | 5 | // we cannot import default as it is accessible only within the package 6 | //import com.auribises.one.Two; // Two is default 7 | 8 | // private: accessible only in the class boundary 9 | // default: accessible only in the package boundary 10 | // protected: accessible only in the package boundary 11 | // public: accessible anywhere and everywhere 12 | 13 | // Package Level Inheritance 14 | class CA extends One{ 15 | 16 | void show() { 17 | //pvtShow(); // not accessible within the child 18 | //defShow(); // not accessible within the child 19 | protShow(); // accessible within the child class boundary 20 | pubShow(); 21 | } 22 | 23 | } 24 | 25 | public class App { 26 | 27 | public static void main(String[] args) { 28 | 29 | //One oRef = new One(); 30 | // oRef.pvtShow(); // error 31 | // oRef.defShow(); // error 32 | // oRef.protShow(); // error 33 | //oRef.pubShow(); // OK 34 | 35 | CA cRef = new CA(); 36 | // cRef.pvtShow(); // error 37 | // cRef.defShow(); // error 38 | // cRef.protShow(); // error 39 | // cRef.pubShow(); // OK 40 | 41 | cRef.show(); 42 | } 43 | 44 | } 45 | --------------------------------------------------------------------------------