├── .DS_Store ├── Lecture ├── .DS_Store ├── Arrays │ ├── Main.class │ └── Main.java ├── EmployeeMgt │ ├── CalcSalary.java │ ├── Employee.java │ └── Main.java ├── Exception │ ├── ExceptionDemo1.class │ ├── ExceptionDemo1.java │ ├── Main.class │ ├── Main.java │ └── MyException.class ├── Executor │ ├── Callable Example │ │ ├── CallableExample.class │ │ ├── Main.class │ │ └── Main.java │ ├── Callable Example2 │ │ ├── CallableTask.class │ │ ├── Main.class │ │ └── Main.java │ ├── Fixed Thread Pool │ │ ├── Algorithm Name : LSTM.jl │ │ ├── ExecutorDemo.class │ │ ├── ExecutorDemo.java │ │ ├── Task.class │ │ ├── Task1.class │ │ └── Task2.class │ └── Single Thread Executor │ │ └── ExecutorDemo.java ├── Inheritance │ ├── Abstract │ │ ├── Car.java │ │ ├── Main.java │ │ └── RTO.java │ ├── Casting │ │ ├── DynamicBinding.java │ │ └── UpCasting.java │ ├── Interface │ │ ├── Car.java │ │ ├── Demo.java │ │ └── StudentDAO.java │ ├── Main.java │ ├── Overriding │ │ ├── Activa.java │ │ ├── Main.java │ │ ├── Scooty.java │ │ └── Two.java │ └── SuperDemo.java ├── InnerClass │ ├── Type 1 - Class inside Class │ │ ├── Case1 - Normal Inner Class 1 │ │ │ └── Outter.java │ │ ├── Case1 - Normal Inner Class 2 │ │ │ └── Outter.java │ │ ├── Type 2 - Method Local Inner Class │ │ │ └── Outter.java │ │ ├── Type 3 - Anonymous Inner Class │ │ │ └── Main.java │ │ └── Type 4 - Static Nested Class │ │ │ └── Main.java │ ├── Type 2 - Interface Inside Class │ │ ├── OutterDemo1.java │ │ └── OutterDemo2.java │ ├── Type 3 - Class Inside Interface │ │ └── Demo1.java │ └── Type 4 - Interface Inside Interface │ │ └── Main.java ├── Lambda │ ├── ConsumerDemo.class │ ├── ConsumerDemo.java │ ├── Demo1.class │ ├── Demo1.java │ ├── Movie.class │ ├── MyCompare.class │ ├── ThreadDemo.class │ └── ThreadDemo.java ├── Object │ ├── CompareObjectv1 │ │ ├── Main.java │ │ ├── Main2.java │ │ └── Student.java │ ├── ObjectClassDemo.java │ ├── SingleTone.java │ ├── Varlength.java │ ├── p1 │ │ └── Student.java │ └── p2 │ │ └── Student.java ├── Static │ └── StaticDemo1.java ├── String&StringBuffer │ ├── StringBuffer │ │ ├── Main.class │ │ └── Main.java │ ├── StringDemo.java │ ├── StringDemo1.java │ └── StringToggleCase.java ├── StudentMgt │ ├── Grade.java │ ├── Main.java │ └── Student.java └── Threading │ ├── Demo2.class │ ├── Demo2.java │ ├── Main.class │ ├── Main.java │ ├── MyThread.class │ └── MyThreadDemo.class ├── Practicals ├── Practical Set 1 │ └── Main.java ├── Practical Set 2 │ ├── Array.java │ ├── Main.java │ └── p2 │ │ └── Main.java ├── Practical Set 3 │ ├── p31 │ │ ├── BankAccount.java │ │ └── Main.java │ ├── p32 │ │ ├── Main.java │ │ └── Time.java │ └── p33 │ │ └── Employee.java ├── Practical Set 4 │ ├── p41 │ │ ├── Cricket.java │ │ ├── Main.java │ │ └── Match.java │ ├── p42 │ │ ├── Caesar_Cipher.java │ │ ├── Cipher.java │ │ ├── Demo.class │ │ ├── Demo.java │ │ └── Substitution_Cipher.java │ ├── p43.java │ ├── p44.java │ ├── p45.java │ └── p51.java └── Practical Set 5 │ └── p52.java └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nayanrami/ADITPWJ/3ad442d315d6d0828a14c17120f42decea81e516/.DS_Store -------------------------------------------------------------------------------- /Lecture/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nayanrami/ADITPWJ/3ad442d315d6d0828a14c17120f42decea81e516/Lecture/.DS_Store -------------------------------------------------------------------------------- /Lecture/Arrays/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nayanrami/ADITPWJ/3ad442d315d6d0828a14c17120f42decea81e516/Lecture/Arrays/Main.class -------------------------------------------------------------------------------- /Lecture/Arrays/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | int data[] = { 10, 50, 3, 8, 74, 9, 6, 71, 36 }; 6 | Arrays.sort(data); 7 | 8 | for (int i : data) { 9 | System.out.println(i); 10 | } 11 | 12 | int value = Arrays.binarySearch(data, 74); 13 | System.out.println("Key Value : " + value); 14 | } 15 | } -------------------------------------------------------------------------------- /Lecture/EmployeeMgt/CalcSalary.java: -------------------------------------------------------------------------------- 1 | package Lecture.EmployeeMgt; 2 | 3 | public class CalcSalary { 4 | Employee employee; 5 | 6 | public CalcSalary(Employee employee) { 7 | this.employee = employee; 8 | } 9 | 10 | public Employee getSalary() { 11 | double workinghr[] = employee.getWorkingHr(); 12 | double payperhr = employee.getPayPerHr(); 13 | double salary = 0; 14 | for (double working : workinghr) { 15 | salary = salary + (working * payperhr); 16 | } 17 | employee.setFinalSal(salary); 18 | return employee; 19 | } 20 | } -------------------------------------------------------------------------------- /Lecture/EmployeeMgt/Employee.java: -------------------------------------------------------------------------------- 1 | package Lecture.EmployeeMgt; 2 | 3 | class Employee { 4 | private long id; 5 | private String name; 6 | private String designation; 7 | private double payperhr; 8 | private double worknghr[]; 9 | private double finalsal;; 10 | 11 | public void setFinalSal(double salary) { 12 | this.finalsal = salary; 13 | } 14 | 15 | public double getFinalSal() { 16 | return finalsal; 17 | } 18 | 19 | public void setId(long id) { 20 | this.id = id; 21 | } 22 | 23 | public long getId() { 24 | return id; 25 | } 26 | 27 | public void setName(String name) { 28 | this.name = name; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setDesignation(String designation) { 36 | this.designation = designation; 37 | } 38 | 39 | public String getDesignation() { 40 | return designation; 41 | } 42 | 43 | public void setPayPerHr(double payperhr) { 44 | this.payperhr = payperhr; 45 | } 46 | 47 | public double getPayPerHr() { 48 | return payperhr; 49 | } 50 | 51 | public void setWorkngHr(double[] worknghr) { 52 | this.worknghr = worknghr; 53 | } 54 | 55 | public double[] getWorkingHr() { 56 | return worknghr; 57 | } 58 | 59 | public String toString() { 60 | String str = "Id" + id + "\nName" + name + "\nDesignation" + designation + "\nPay Per Hr: " + payperhr; 61 | for (double wh : worknghr) { 62 | System.out.println(wh); 63 | } 64 | System.out.println("Final Salary : " + finalsal); 65 | return str; 66 | } 67 | } -------------------------------------------------------------------------------- /Lecture/EmployeeMgt/Main.java: -------------------------------------------------------------------------------- 1 | package Lecture.EmployeeMgt; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Employee employee = new Employee(); 6 | employee.setId(1); 7 | employee.setName("Nayan"); 8 | employee.setPayPerHr(100.40); 9 | employee.setDesignation("Assistant Professor"); 10 | employee.setWorkngHr(new double[] { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 }); 11 | CalcSalary calcSalary = new CalcSalary(employee); 12 | calcSalary.getSalary(); 13 | 14 | System.out.println(employee); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Lecture/Exception/ExceptionDemo1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nayanrami/ADITPWJ/3ad442d315d6d0828a14c17120f42decea81e516/Lecture/Exception/ExceptionDemo1.class -------------------------------------------------------------------------------- /Lecture/Exception/ExceptionDemo1.java: -------------------------------------------------------------------------------- 1 | class MyException extends Exception { 2 | String msg; 3 | 4 | public MyException() { 5 | } 6 | 7 | public MyException(String msg) { 8 | this.msg = msg; 9 | } 10 | 11 | public String toString() { 12 | return msg; 13 | } 14 | } 15 | 16 | class ExceptionDemo1 { 17 | public static void main(String args[]) throws MyException { 18 | String username = "adit"; 19 | String password = "adit1"; 20 | 21 | if (username.equals(password)) { 22 | System.out.println("Welcome " + username); 23 | } else { 24 | throw new MyException("Invalid Username / Password"); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Lecture/Exception/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nayanrami/ADITPWJ/3ad442d315d6d0828a14c17120f42decea81e516/Lecture/Exception/Main.class -------------------------------------------------------------------------------- /Lecture/Exception/Main.java: -------------------------------------------------------------------------------- 1 | class Main { 2 | public static void main(String[] args) { 3 | Main main = new Main(); 4 | main.m1(); 5 | } 6 | 7 | void m1() { 8 | System.out.println("M1 Start.."); 9 | m2(); 10 | System.out.println("M1 End.."); 11 | } 12 | 13 | void m2() { 14 | System.out.println("M2 Start.."); 15 | try { 16 | m3(); 17 | } catch (Exception e) { 18 | e.printStackTrace(); 19 | } 20 | System.out.println("M2 End.."); 21 | } 22 | 23 | void m3() { 24 | System.out.println("M3 Start.."); 25 | int c = 10 / 0; 26 | m4(); 27 | System.out.println("M3 End.."); 28 | } 29 | 30 | void m4() { 31 | System.out.println("M4 Start.."); 32 | 33 | System.out.println("M4 End.."); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /Lecture/Exception/MyException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nayanrami/ADITPWJ/3ad442d315d6d0828a14c17120f42decea81e516/Lecture/Exception/MyException.class -------------------------------------------------------------------------------- /Lecture/Executor/Callable Example/CallableExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nayanrami/ADITPWJ/3ad442d315d6d0828a14c17120f42decea81e516/Lecture/Executor/Callable Example/CallableExample.class -------------------------------------------------------------------------------- /Lecture/Executor/Callable Example/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nayanrami/ADITPWJ/3ad442d315d6d0828a14c17120f42decea81e516/Lecture/Executor/Callable Example/Main.class -------------------------------------------------------------------------------- /Lecture/Executor/Callable Example/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.concurrent.Callable; 2 | import java.util.concurrent.ExecutionException; 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | import java.util.concurrent.Future; 6 | 7 | class CallableExample implements Callable{ 8 | 9 | private String msg; 10 | 11 | public CallableExample(String msg){ 12 | this.msg = msg; 13 | } 14 | 15 | @Override 16 | public String call() throws Exception { 17 | Thread.sleep(1000); 18 | return "Hello "+msg; 19 | } 20 | 21 | } 22 | 23 | public class Main { 24 | public static void main(String[] args) throws InterruptedException, ExecutionException { 25 | ExecutorService service = Executors.newFixedThreadPool(5); 26 | Future future = service.submit(new CallableExample("Nayan")); 27 | System.out.println(future.get()); 28 | service.shutdown(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Lecture/Executor/Callable Example2/CallableTask.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nayanrami/ADITPWJ/3ad442d315d6d0828a14c17120f42decea81e516/Lecture/Executor/Callable Example2/CallableTask.class -------------------------------------------------------------------------------- /Lecture/Executor/Callable Example2/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nayanrami/ADITPWJ/3ad442d315d6d0828a14c17120f42decea81e516/Lecture/Executor/Callable Example2/Main.class -------------------------------------------------------------------------------- /Lecture/Executor/Callable Example2/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.List; 2 | import java.util.concurrent.Callable; 3 | import java.util.concurrent.ExecutionException; 4 | import java.util.concurrent.Executor; 5 | import java.util.concurrent.ExecutorService; 6 | import java.util.concurrent.Executors; 7 | import java.util.concurrent.Future; 8 | 9 | class CallableTask implements Callable{ 10 | private String msg; 11 | public CallableTask(String msg){ 12 | this.msg = msg; 13 | } 14 | public String call(){ 15 | return "Hello "+ msg; 16 | } 17 | } 18 | 19 | 20 | public class Main { 21 | public static void main(String[] args) throws InterruptedException, ExecutionException { 22 | 23 | List tasklist = List.of(new CallableTask("Nayan"), 24 | new CallableTask("Vikali"), new CallableTask("Het")); 25 | 26 | ExecutorService service = Executors.newFixedThreadPool(1); 27 | List> results = service.invokeAll(tasklist); 28 | for (Future future : results) { 29 | System.out.println(future.get()); 30 | } 31 | service.shutdown(); 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Lecture/Executor/Fixed Thread Pool/Algorithm Name : LSTM.jl: -------------------------------------------------------------------------------- 1 | Algorithm Name : LSTM 2 | optimizer = Adam(learning_rate=0.00001) 3 | epochs=500, 4 | batch_size=256, 5 | Train Test Split : 6 | X : (100000, 200) 7 | y : (100000,) 8 | X_train : (80000, 1, 200) 9 | X_test : (20000, 1, 200) 10 | y_train : (80000,) 11 | y_test : (20000,) 12 | X : (100000, 200) 13 | 14 | Experiement 1: Feature Selection Algorithm : L1 Regularization (Lasso) with Logistic Regression 15 | loss: 0.2658 - accuracy: 0.8676 16 | Test Loss: 0.26583826541900635 17 | Test Accuracy: 0.8676499724388123 18 | precision recall f1-score support 19 | 20 | 0 0.79 0.95 0.86 8744 21 | 1 0.96 0.80 0.87 11256 22 | 23 | accuracy 0.87 20000 24 | macro avg 0.87 0.88 0.87 20000 25 | weighted avg 0.88 0.87 0.87 20000 26 | 27 | Experiment 2 : Feature Selection Algorithm : RandomForestClassifier 28 | loss: 0.2446 - accuracy: 0.8792 29 | Test Loss: 0.2446327656507492 30 | Test Accuracy: 0.8792499899864197 31 | precision recall f1-score support 32 | 33 | 0 0.80 0.97 0.87 8744 34 | 1 0.97 0.81 0.88 11256 35 | 36 | accuracy 0.88 20000 37 | macro avg 0.88 0.89 0.88 20000 38 | weighted avg 0.89 0.88 0.88 20000 39 | 40 | Experiment 3 : Feature Selection Algorithm : SelectKBest 41 | loss: 0.2717 - accuracy: 0.8633 42 | Test Loss: 0.2717222273349762 43 | Test Accuracy: 0.8632500171661377 44 | precision recall f1-score support 45 | 46 | 0 0.77 0.98 0.86 8744 47 | 1 0.98 0.77 0.86 11256 48 | 49 | accuracy 0.86 20000 50 | macro avg 0.87 0.88 0.86 20000 51 | weighted avg 0.89 0.86 0.86 20000 52 | 53 | Experiment 4 : With All Features 54 | loss: 0.2547 - accuracy: 0.8774 55 | Test Loss: 0.2546609342098236 56 | Test Accuracy: 0.8773999810218811 57 | precision recall f1-score support 58 | 59 | 0 0.79 0.97 0.87 8744 60 | 1 0.97 0.80 0.88 11256 61 | 62 | accuracy 0.88 20000 63 | macro avg 0.88 0.89 0.88 20000 64 | weighted avg 0.90 0.88 0.88 20000 65 | 66 | Experiment 5 : Logistic Regression 67 | loss: 0.3010 - accuracy: 0.8515 68 | Test Loss: 0.30098870396614075 69 | Test Accuracy: 0.8514500260353088 70 | precision recall f1-score support 71 | 72 | 0 0.76 0.97 0.85 8744 73 | 1 0.97 0.76 0.85 11256 74 | 75 | accuracy 0.85 20000 76 | macro avg 0.86 0.86 0.85 20000 77 | weighted avg 0.88 0.85 0.85 20000 -------------------------------------------------------------------------------- /Lecture/Executor/Fixed Thread Pool/ExecutorDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nayanrami/ADITPWJ/3ad442d315d6d0828a14c17120f42decea81e516/Lecture/Executor/Fixed Thread Pool/ExecutorDemo.class -------------------------------------------------------------------------------- /Lecture/Executor/Fixed Thread Pool/ExecutorDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * A D PATEL INSTITUTE OF TECHNOLOGY 4 | * DEPARTMENT OF INFORMATION TECHNOLOGY 5 | * PROGRAMMING WITH JAVA 6 | * EXECUTOR FRAMEWORK 7 | * 8 | */ 9 | 10 | import java.util.concurrent.ExecutorService; 11 | import java.util.concurrent.Executors; 12 | 13 | class Task extends Thread{ 14 | private int number; 15 | public Task(int number){ 16 | this.number = number; 17 | } 18 | public void run(){ 19 | System.out.println("Task "+number+" Started"); 20 | for(int i=number; i c1 = m -> System.out.println(m.name = " Release Today 1"); 15 | Consumer c2 = m -> System.out.println(m.name = " Release Today 2"); 16 | Consumer c3 = m -> System.out.println(m.name = " Release Today 3"); 17 | 18 | c1.accept(new Movie("Test")); 19 | c1.andThen(c3).accept(new Movie("Hero2")); 20 | 21 | Supplier otp = () -> { 22 | return String.valueOf((int) (Math.random() * 10000)); 23 | }; 24 | 25 | System.out.println(otp.get()); 26 | } 27 | } -------------------------------------------------------------------------------- /Lecture/Lambda/Demo1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nayanrami/ADITPWJ/3ad442d315d6d0828a14c17120f42decea81e516/Lecture/Lambda/Demo1.class -------------------------------------------------------------------------------- /Lecture/Lambda/Demo1.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Collection; 3 | import java.util.Collections; 4 | import java.util.Comparator; 5 | import java.util.List; 6 | import java.util.stream.Collectors; 7 | 8 | class Demo1 { 9 | public static void main(String[] args) { 10 | List list = new ArrayList(); 11 | list.add(10); 12 | list.add(4); 13 | list.add(3); 14 | list.add(22); 15 | list.add(9); 16 | list.add(60); 17 | 18 | Comparator c = (item1, item2) -> (item1 > item2) ? 1 : (item1 < item2) ? -1 : 0; 19 | 20 | Collections.sort(list, c); 21 | Collections.sort(list, new MyCompare()); 22 | System.out.println(list); 23 | list.stream().forEach(System.out::println); 24 | 25 | List l2 = list.stream().filter(a -> a % 2 == 0).collect(Collectors.toList()); 26 | System.out.println(l2); 27 | } 28 | } 29 | 30 | class MyCompare implements Comparator { 31 | 32 | @Override 33 | public int compare(Integer o1, Integer o2) { 34 | 35 | return (o1 < o2) ? 1 : (o1 > 02) ? -1 : 0; 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /Lecture/Lambda/Movie.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nayanrami/ADITPWJ/3ad442d315d6d0828a14c17120f42decea81e516/Lecture/Lambda/Movie.class -------------------------------------------------------------------------------- /Lecture/Lambda/MyCompare.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nayanrami/ADITPWJ/3ad442d315d6d0828a14c17120f42decea81e516/Lecture/Lambda/MyCompare.class -------------------------------------------------------------------------------- /Lecture/Lambda/ThreadDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nayanrami/ADITPWJ/3ad442d315d6d0828a14c17120f42decea81e516/Lecture/Lambda/ThreadDemo.class -------------------------------------------------------------------------------- /Lecture/Lambda/ThreadDemo.java: -------------------------------------------------------------------------------- 1 | public class ThreadDemo { 2 | public static void main(String[] args) { 3 | 4 | Thread thread = new Thread(() -> { 5 | for (int i = 0; i < 10; i++) { 6 | System.out.println(Thread.currentThread().getName()); 7 | 8 | } 9 | }); 10 | thread.start(); 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Lecture/Object/CompareObjectv1/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | public static void main(String[] args) { 4 | Student student1 = new Student(); 5 | Student student2 = new Student(); 6 | 7 | student1.id = 1; 8 | student1.name = "nayan"; 9 | 10 | student2.id = 1; 11 | student2.name = "nayan"; 12 | 13 | System.out.println("Student 1" + student1); 14 | System.out.println("Student 2" + student2); 15 | 16 | if (student1 == student2) { 17 | System.out.println("Same Student"); 18 | } else { 19 | System.out.println("Student 1 == Student 2 Fail"); 20 | } 21 | 22 | if (student1.equals(student2)) { 23 | System.out.println("Same Student"); 24 | } else { 25 | System.out.println("Student1.equals(Student2) Fail"); 26 | } 27 | 28 | if (student1.id == student2.id && student1.equals(student2.name)) { 29 | System.out.println("Same Student"); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Lecture/Object/CompareObjectv1/Main2.java: -------------------------------------------------------------------------------- 1 | class Main2 { 2 | public static void main(String[] args) { 3 | String msg = "Welcome To ADIT"; 4 | 5 | char om[] = msg.toCharArray(); 6 | char cm[] = new char[om.length]; 7 | 8 | for (int i = 0; i < om.length; i++) { 9 | char ch; 10 | if (Character.isLowerCase(om[i])) { 11 | ch = Character.toUpperCase(om[i]); 12 | } else { 13 | ch = Character.toLowerCase(om[i]); 14 | } 15 | cm[i] = ch; 16 | } 17 | String newmsg = String.valueOf(cm); 18 | System.out.println("Original Message : " + msg); 19 | System.out.println("New Message : " + newmsg); 20 | 21 | StringBuffer bf = new StringBuffer(newmsg); 22 | System.out.println(bf.reverse()); 23 | } 24 | } -------------------------------------------------------------------------------- /Lecture/Object/CompareObjectv1/Student.java: -------------------------------------------------------------------------------- 1 | public class Student { 2 | int id; 3 | String name; 4 | } 5 | -------------------------------------------------------------------------------- /Lecture/Object/ObjectClassDemo.java: -------------------------------------------------------------------------------- 1 | import java.util.EnumMap; 2 | 3 | class ObjectClassDemo { 4 | public static void main(String[] args) { 5 | 6 | Employee employee = new Employee(1, "Nayan", "it.nayanmali@adit.ac.in"); 7 | System.out.println(employee); 8 | 9 | } 10 | } 11 | 12 | class Employee { 13 | private int id; 14 | private String name; 15 | private String email; 16 | 17 | Employee(int id, String name, String email) { 18 | this.id = id; 19 | this.name = name; 20 | this.email = email; 21 | } 22 | 23 | public String toString() { 24 | return "[id " + id + " name: " + name + " email:" + email + "]"; 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /Lecture/Object/SingleTone.java: -------------------------------------------------------------------------------- 1 | public class SingleTone { 2 | public static void main(String[] args) { 3 | Demo demo1 = Demo.createObject(); 4 | Demo demo2 = Demo.createObject(); 5 | Demo demo3 = Demo.createObject(); 6 | Demo demo4 = Demo.createObject(); 7 | Demo demo5 = Demo.createObject(); 8 | 9 | demo1.getMessage(); 10 | demo2.getMessage(); 11 | demo3.getMessage(); 12 | demo4.getMessage(); 13 | demo5.getMessage(); 14 | } 15 | } 16 | 17 | class Demo { 18 | private static Demo demo = null; 19 | 20 | private Demo() { 21 | System.out.println("Object Created..."); 22 | } 23 | 24 | static Demo createObject() { 25 | if (demo == null) 26 | demo = new Demo(); 27 | 28 | return demo; 29 | } 30 | 31 | void getMessage() { 32 | System.out.println("Single Tone Object"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Lecture/Object/Varlength.java: -------------------------------------------------------------------------------- 1 | public class Varlength { 2 | public static void main(String... args) { 3 | Varlength aVarlength = new Varlength(); 4 | System.out.println(aVarlength.sum(10, 20, 30)); 5 | 6 | } 7 | 8 | public int sum(int... value) { 9 | int sum = 0; 10 | for (int k : value) { 11 | sum = sum + k; 12 | } 13 | return sum; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Lecture/Object/p1/Student.java: -------------------------------------------------------------------------------- 1 | class Student { 2 | int id; 3 | String name; 4 | String address; 5 | } 6 | 7 | class Main { 8 | public static void main(String[] args) { 9 | // Create Student Objects 10 | Student student1 = new Student(); 11 | Student student2 = new Student(); 12 | // Accessing Student Object states 13 | 14 | student1.id = 10; 15 | student2.id = 10; 16 | 17 | student1.name = "Nayan"; 18 | student2.name = "Keyur"; 19 | 20 | student1.address = "Padra"; 21 | student2.address = "Valsad"; 22 | 23 | System.out.println("Student 1 Information "); 24 | System.out.println("Id " + student1.id); 25 | System.out.println("Name " + student1.name); 26 | System.out.println("Address " + student1.address); 27 | 28 | System.out.println("Student 2 Information "); 29 | System.out.println("Id " + student2.id); 30 | System.out.println("Name " + student2.name); 31 | System.out.println("Address " + student2.address); 32 | 33 | } 34 | } -------------------------------------------------------------------------------- /Lecture/Object/p2/Student.java: -------------------------------------------------------------------------------- 1 | class Student { 2 | int id; 3 | String name; 4 | String address; 5 | 6 | // Default Constructor 7 | public Student() { 8 | 9 | } 10 | 11 | // Parameterized Constructor 12 | public Student(int id, String name, String address) { 13 | this.id = id; 14 | this.name = name; 15 | this.address = address; 16 | } 17 | 18 | // Set Value using method 19 | public void setStudent(int id, String name, String address) { 20 | this.id = id; 21 | this.name = name; 22 | this.address = address; 23 | } 24 | 25 | public void display() { 26 | System.out.println("\nId : " + id); 27 | System.out.println("Name : " + name); 28 | System.out.println("Address : " + address); 29 | } 30 | } 31 | 32 | class Main { 33 | public static void main(String[] args) { 34 | // Create Student Objects and pass object value through set method 35 | Student student1 = new Student(); 36 | student1.setStudent(10, "Nayan", "PADRA"); 37 | student1.display(); 38 | 39 | // Create Student Objects and pass object value through constructor 40 | 41 | Student student2 = new Student(20, "Keyur", "VALSAD"); 42 | student1.display(); 43 | 44 | // Create Student Object without name and call method 45 | new Student(30, "Ravi", "Anand").display(); 46 | 47 | } 48 | } -------------------------------------------------------------------------------- /Lecture/Static/StaticDemo1.java: -------------------------------------------------------------------------------- 1 | public class StaticDemo1 { 2 | public static void main(String[] args) { 3 | Counter counter1 = new Counter(); 4 | Counter counter2 = new Counter(); 5 | Counter counter3 = new Counter(); 6 | 7 | counter1.x = 10; 8 | counter2.x = 20; 9 | counter3.x = 30; 10 | 11 | System.out.println("Counter 1 Instance Variable : X = " + counter1.x); 12 | System.out.println("Counter 2 Instance Variable : X = " + counter2.x); 13 | System.out.println("Counter 3 Instance Variable : X = " + counter3.x); 14 | 15 | // Assign Value to static variable 16 | counter1.y = 10; 17 | counter2.y = 10; 18 | counter3.y = 10; 19 | 20 | System.out.println("Counter 1 Static Variable : Y = " + counter1.y); 21 | System.out.println("Counter 2 Static Variable : Y = " + counter2.y); 22 | System.out.println("Counter 3 Static Variable : Y = " + counter3.y); 23 | 24 | // Assign Value to Static variable without reference Class.Variable 25 | Counter.y = 50; 26 | System.out.println("Counter Class Static Variable : Y = " + Counter.y); 27 | 28 | // final variable can not be modified 29 | System.out.println("Counter 1 final variable k " + counter1.k); 30 | System.out.println("Counter 2 final variable k " + counter2.k); 31 | System.out.println("Counter 3 final variable k " + counter3.k); 32 | 33 | // calling instance method 34 | counter1.m1(); 35 | counter2.m1(); 36 | counter3.m1(); 37 | 38 | // calling instance method Class.method 39 | 40 | Counter.m2(); 41 | } 42 | } 43 | 44 | class Counter { 45 | int x; // instance variable 46 | static int y;// static variable 47 | final int k = 10; // final variable assign value 48 | 49 | /* 50 | * Instance Method 51 | */ 52 | public void m1() { 53 | System.out.println("M1 Instance Method Method"); 54 | } 55 | 56 | public static void m2() { 57 | System.out.println("M2 Static Method"); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Lecture/String&StringBuffer/StringBuffer/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nayanrami/ADITPWJ/3ad442d315d6d0828a14c17120f42decea81e516/Lecture/String&StringBuffer/StringBuffer/Main.class -------------------------------------------------------------------------------- /Lecture/String&StringBuffer/StringBuffer/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String args[]) { 3 | String message = "Welcome To Adit"; 4 | 5 | StringBuffer stringBuffer = new StringBuffer(message); 6 | stringBuffer.append(" From Department of Information Technology"); 7 | System.out.println(stringBuffer); 8 | 9 | System.out.println(stringBuffer.capacity()); 10 | System.out.println(stringBuffer.substring(3)); 11 | System.out.println(stringBuffer.reverse()); 12 | 13 | } 14 | } -------------------------------------------------------------------------------- /Lecture/String&StringBuffer/StringDemo.java: -------------------------------------------------------------------------------- 1 | 2 | public class StringDemo { 3 | public static void main(String[] args) { 4 | String name1 = "nayan"; 5 | String name2 = "Nayan"; 6 | 7 | if (name1.equalsIgnoreCase(name2)) { 8 | System.out.println("Welcome " + name1); 9 | } else { 10 | System.out.println("Sorry"); 11 | } 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lecture/String&StringBuffer/StringDemo1.java: -------------------------------------------------------------------------------- 1 | public class StringDemo1 { 2 | 3 | public static void main(String[] args) { 4 | String message = "1,nayan,adit,nayan@gmail.com,99753894753,89347238947,"; 5 | 6 | System.out.println("Length of String Message : " + message.length()); 7 | System.out.println("\nString Tokenization :"); 8 | String data[] = message.split(","); 9 | for (String token : data) { 10 | System.out.println("Token : " + token); 11 | } 12 | 13 | message = message.replace("H", "B"); 14 | System.out.println("\nReplace H By B : " + message); 15 | 16 | System.out.println("Convert Message To Upper Case: " + message.toUpperCase()); 17 | System.out.println("Convert Message To Lower Case: " + message.toLowerCase()); 18 | 19 | if (message.contains("b")) { 20 | System.out.println("Message Containt 'b' "); 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Lecture/String&StringBuffer/StringToggleCase.java: -------------------------------------------------------------------------------- 1 | class StringToggleCase { 2 | 3 | public static void main(String[] args) { 4 | String message = "Welcome To Adit"; 5 | 6 | char[] message2 = message.toCharArray(); 7 | char[] message3 = new char[message.length()]; 8 | 9 | for (int i = 0; i < message2.length; i++) { 10 | char data; 11 | if (Character.isUpperCase(message2[i])) { 12 | data = Character.toLowerCase(message2[i]); 13 | } else { 14 | data = Character.toUpperCase(message2[i]); 15 | } 16 | message3[i] = data; 17 | } 18 | 19 | String newmsg = String.valueOf(message3); 20 | 21 | System.out.println("Toggle String " + newmsg); 22 | 23 | StringBuffer sb = new StringBuffer(newmsg); 24 | sb.reverse(); 25 | System.out.println(sb); 26 | 27 | } 28 | } -------------------------------------------------------------------------------- /Lecture/StudentMgt/Grade.java: -------------------------------------------------------------------------------- 1 | public class Grade { 2 | private Student student; 3 | 4 | public Grade(Student student) { 5 | this.student = student; 6 | } 7 | 8 | public void result(){ 9 | student. 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Lecture/StudentMgt/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String[] args) { 3 | Student student = new Student(); 4 | student.setMarks(50, 66, 76, 45, 98); 5 | 6 | Grade grade = new Grade(student); 7 | grade.result(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Lecture/StudentMgt/Student.java: -------------------------------------------------------------------------------- 1 | public class Student { 2 | private long enrollmentno; 3 | private double subject1; 4 | private double subject2; 5 | private double subject3; 6 | private double subject4; 7 | private double subject5; 8 | 9 | public void setMarks(double subject1, double subject2, double subject3, double subject4, double subject5) { 10 | this.subject1 = subject1; 11 | this.subject2 = subject2; 12 | this.subject3 = subject3; 13 | this.subject4 = subject4; 14 | this.subject5 = subject5; 15 | } 16 | 17 | public void display() { 18 | System.out.println("Enrollment Number " + enrollmentno); 19 | System.out.println("Subject 1 " + subject1); 20 | System.out.println("Subject 2 " + subject2); 21 | System.out.println("Subject 3 " + subject3); 22 | System.out.println("Subject 4 " + subject4); 23 | System.out.println("Subject 5 " + subject5); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Lecture/Threading/Demo2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nayanrami/ADITPWJ/3ad442d315d6d0828a14c17120f42decea81e516/Lecture/Threading/Demo2.class -------------------------------------------------------------------------------- /Lecture/Threading/Demo2.java: -------------------------------------------------------------------------------- 1 | class Demo2 { 2 | public static void main(String[] args) { 3 | MyThreadDemo demo = new MyThreadDemo(); 4 | Thread thread1 = new Thread(demo); 5 | Thread thread2 = new Thread(demo); 6 | thread1.start(); 7 | thread2.start(); 8 | 9 | } 10 | } 11 | 12 | class MyThreadDemo implements Runnable { 13 | public void run() { 14 | try { 15 | for (int i = 0; i < 10; i++) { 16 | System.out.println("Thread: " + Thread.currentThread().getName() + ":" + i); 17 | } 18 | } catch (Exception e) { 19 | e.printStackTrace(); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Lecture/Threading/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nayanrami/ADITPWJ/3ad442d315d6d0828a14c17120f42decea81e516/Lecture/Threading/Main.class -------------------------------------------------------------------------------- /Lecture/Threading/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | public static void main(String[] args) { 4 | MyThread thread = new MyThread(); 5 | System.out.println(Thread.currentThread().getName()); 6 | thread.start(); 7 | } 8 | } 9 | 10 | class MyThread extends Thread { 11 | public void run() { 12 | Thread.currentThread().setName("My Thread"); 13 | System.out.println(Thread.currentThread().getName()); 14 | System.out.println("Thread Running"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Lecture/Threading/MyThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nayanrami/ADITPWJ/3ad442d315d6d0828a14c17120f42decea81e516/Lecture/Threading/MyThread.class -------------------------------------------------------------------------------- /Lecture/Threading/MyThreadDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nayanrami/ADITPWJ/3ad442d315d6d0828a14c17120f42decea81e516/Lecture/Threading/MyThreadDemo.class -------------------------------------------------------------------------------- /Practicals/Practical Set 1/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String args[]) { 3 | int c; 4 | int a = Integer.parseInt(args[0]); 5 | int b = Integer.parseInt(args[1]); 6 | 7 | c = a + b; 8 | System.out.println("Ans " + c); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Practicals/Practical Set 2/Array.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class Array { 5 | int data[]; 6 | Scanner scanner; 7 | 8 | public Array() { 9 | data = new int[10]; 10 | data[0] = 10; 11 | data[1] = 72; 12 | data[2] = 59; 13 | data[3] = 23; 14 | data[4] = 54; 15 | data[5] = 26; 16 | data[6] = 90; 17 | data[7] = 6; 18 | data[8] = 5; 19 | data[9] = 2; 20 | } 21 | 22 | public Array(int size) { 23 | data = new int[size]; 24 | scanner = new Scanner(System.in); 25 | 26 | for (int i = 0; i < size; i++) { 27 | int value = scanner.nextInt(); 28 | data[i] = value; 29 | } 30 | } 31 | 32 | public Array(int recdata[]) { 33 | data = recdata; 34 | } 35 | 36 | void display() { 37 | System.out.println("Array Values = "); 38 | for (int i = 0; i < data.length; i++) { 39 | System.out.println(data[i]); 40 | } 41 | 42 | } 43 | 44 | public void size() { 45 | System.out.println("Size of Array " + data.length); 46 | } 47 | 48 | public void sorting() { 49 | System.out.println("Sorting Array"); 50 | Arrays.sort(data); 51 | } 52 | 53 | public void maxArray() { 54 | // 55 | } 56 | 57 | public void search(int value) { 58 | int pos = Arrays.binarySearch(data, value); 59 | if (pos > 0) { 60 | System.out.println("Found Element " + pos); 61 | } else { 62 | System.out.println("Element Not Found"); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Practicals/Practical Set 2/Main.java: -------------------------------------------------------------------------------- 1 | class Main { 2 | public static void main(String[] args) { 3 | Array array1 = new Array(new int[] { 19, 28, 54, 34, 64 }); 4 | array1.display(); 5 | 6 | } 7 | } -------------------------------------------------------------------------------- /Practicals/Practical Set 2/p2/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String[] args) { 3 | 4 | String plaintext = args[0]; 5 | int key = Integer.parseInt(args[1]); 6 | 7 | System.out.println("Message : " + plaintext); 8 | System.out.println("Key : " + key); 9 | 10 | Secret secret = new Secret(); 11 | 12 | String ciphertext = secret.encrypt(plaintext, key); 13 | System.out.println("Encrypted Text :" + ciphertext); 14 | 15 | String pt = secret.decrypt(ciphertext, 3); 16 | System.out.println("Decrypted Text : " + pt); 17 | 18 | } 19 | } 20 | 21 | class Secret { 22 | 23 | public String encrypt(String plaintext, int key) { 24 | // convert String to char[] 25 | char[] pt = plaintext.toCharArray(); 26 | // create char[] with size of plaintext 27 | char[] ct = new char[pt.length]; 28 | for (int i = 0; i < pt.length; i++) { 29 | // convert char to integer and add key to it 30 | int value = (int) pt[i] + key; 31 | // convert int to char and add in char[] 32 | ct[i] = (char) value; 33 | } 34 | // convert char[] to String 35 | return String.valueOf(ct); 36 | } 37 | 38 | public String decrypt(String ciphertext, int key) { 39 | char[] pt = ciphertext.toCharArray(); 40 | 41 | char[] ct = new char[pt.length]; 42 | for (int i = 0; i < pt.length; i++) { 43 | int value = (int) pt[i] - key; 44 | ct[i] = (char) value; 45 | } 46 | return String.valueOf(ct); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Practicals/Practical Set 3/p31/BankAccount.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class BankAccount { 4 | private static int acc = 1; 5 | private String name; 6 | private String account_type; 7 | private double balance; 8 | private long account_no; 9 | 10 | void createAccount() { 11 | Scanner scanner = new Scanner(System.in); 12 | 13 | account_no = acc++; 14 | 15 | System.out.println("Your Account No. " + account_no); 16 | System.out.println("Enter Name: "); 17 | name = scanner.nextLine(); 18 | 19 | System.out.println("Enter Account Type: "); 20 | account_type = scanner.nextLine(); 21 | 22 | System.out.println("Enter Balance: "); 23 | balance = scanner.nextDouble(); 24 | } 25 | 26 | void displayAccount() { 27 | System.out.println("Account No : " + account_no); 28 | System.out.println("Account Holder Name : " + name); 29 | System.out.println("Account Type : " + account_type); 30 | System.out.println("Balance : " + balance); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Practicals/Practical Set 3/p31/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | public static void main(String[] args) { 4 | BankAccount bankAccount1 = new BankAccount(); 5 | bankAccount1.createAccount(); 6 | 7 | BankAccount bankAccount2 = new BankAccount(); 8 | bankAccount2.createAccount(); 9 | 10 | BankAccount bankAccount3 = new BankAccount(); 11 | bankAccount3.createAccount(); 12 | 13 | bankAccount1.displayAccount(); 14 | bankAccount2.displayAccount(); 15 | bankAccount3.displayAccount(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Practicals/Practical Set 3/p32/Main.java: -------------------------------------------------------------------------------- 1 | class Main { 2 | public static void main(String[] args) { 3 | Time t1 = new Time(1, 1, 1); 4 | Time t2 = new Time(1, 1, 1); 5 | 6 | Time t3 = t1.sumTime(t2); 7 | System.out.println("Time 3" + t3); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Practicals/Practical Set 3/p32/Time.java: -------------------------------------------------------------------------------- 1 | public class Time { 2 | int hr; 3 | int min; 4 | int sec; 5 | 6 | Time(int hr, int min, int sec) { 7 | this.hr = hr; 8 | this.min = min; 9 | this.sec = sec; 10 | } 11 | 12 | Time() { 13 | 14 | } 15 | 16 | Time sumTime(Time t2) { 17 | Time t3 = new Time(); 18 | 19 | t3.hr = t2.hr + hr; 20 | t3.min = t2.min + min; 21 | t3.sec = t2.sec + sec; 22 | 23 | return t3; 24 | } 25 | 26 | public String toString() { 27 | return "[Hr" + hr + ", Min" + min + ", Sec" + sec + "]"; 28 | } 29 | } -------------------------------------------------------------------------------- /Practicals/Practical Set 3/p33/Employee.java: -------------------------------------------------------------------------------- 1 | public class Employee { 2 | private String name; 3 | private double basicsalary; 4 | private double dearnessallowance; 5 | 6 | Employee(String name, double basicsalary, double dearnessallowance) { 7 | this.name = name; 8 | this.basicsalary = basicsalary; 9 | this.dearnessallowance = dearnessallowance; 10 | } 11 | 12 | public void calculateSalary() { 13 | 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Practicals/Practical Set 4/p41/Cricket.java: -------------------------------------------------------------------------------- 1 | public class Cricket { 2 | private String name; 3 | private double age; 4 | 5 | public String toString() { 6 | return "[name= " + name + " age = " + age + "]"; 7 | } 8 | 9 | public void setName(String name) { 10 | this.name = name; 11 | } 12 | 13 | public void setAge(double age) { 14 | this.age = age; 15 | } 16 | 17 | public String getName() { 18 | return name; 19 | } 20 | 21 | public double getAge() { 22 | return age; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Practicals/Practical Set 4/p41/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | public static void main(String[] args) { 4 | 5 | Match match[] = new Match[5]; 6 | 7 | match[0] = new Match(); 8 | match[0].setName("Sachin"); 9 | match[0].setAge(33); 10 | match[0].setOdi(100); 11 | match[0].setTest(100); 12 | 13 | System.out.println(match[0]); 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Practicals/Practical Set 4/p41/Match.java: -------------------------------------------------------------------------------- 1 | 2 | public class Match extends Cricket { 3 | private int odi; 4 | private int test; 5 | 6 | public String toString() { 7 | System.out.println(super.toString()); 8 | return "[Odi = " + odi + " Test =" + test + "]"; 9 | } 10 | 11 | public void setOdi(int odi) { 12 | this.odi = odi; 13 | } 14 | 15 | public void setTest(int test) { 16 | this.test = test; 17 | } 18 | 19 | public int getOdi() { 20 | return odi; 21 | } 22 | 23 | public int getTest() { 24 | return test; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Practicals/Practical Set 4/p42/Caesar_Cipher.java: -------------------------------------------------------------------------------- 1 | 2 | public class Caesar_Cipher extends CipherDemo { 3 | 4 | @Override 5 | String enryption() { 6 | // TODO Auto-generated method stub 7 | return null; 8 | } 9 | 10 | @Override 11 | String decryption() { 12 | // TODO Auto-generated method stub 13 | return null; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Practicals/Practical Set 4/p42/Cipher.java: -------------------------------------------------------------------------------- 1 | public abstract class CipherDemo { 2 | private String plaintext; 3 | private int key; 4 | 5 | CipherDemo(String plaintext, int key) { 6 | this.plaintext = plaintext; 7 | this.key = key; 8 | } 9 | 10 | abstract String enryption(); 11 | 12 | abstract String decryption(); 13 | } 14 | -------------------------------------------------------------------------------- /Practicals/Practical Set 4/p42/Demo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nayanrami/ADITPWJ/3ad442d315d6d0828a14c17120f42decea81e516/Practicals/Practical Set 4/p42/Demo.class -------------------------------------------------------------------------------- /Practicals/Practical Set 4/p42/Demo.java: -------------------------------------------------------------------------------- 1 | 2 | public class Demo { 3 | public static void main(String[] args) { 4 | String data[][] = { { "A", "K" }, { "B", "J" } }; 5 | for (String s[] : data) { 6 | System.out.println(s[0]); 7 | System.out.println(s[1]); 8 | System.out.println("____________________"); 9 | } 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Practicals/Practical Set 4/p42/Substitution_Cipher.java: -------------------------------------------------------------------------------- 1 | 2 | public class Substitution_Cipher extends CipherDemo { 3 | 4 | @Override 5 | String enryption() { 6 | // TODO Auto-generated method stub 7 | return null; 8 | } 9 | 10 | @Override 11 | String decryption() { 12 | // TODO Auto-generated method stub 13 | return null; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Practicals/Practical Set 4/p43.java: -------------------------------------------------------------------------------- 1 | class Cipher { 2 | String plainText; 3 | int key; 4 | 5 | public Cipher(String plainText, int key) { 6 | this.plainText = plainText; 7 | this.key = key; 8 | } 9 | 10 | // Abstract methods for encryption and decryption 11 | abstract String Encryption(); 12 | abstract String Decryption(); 13 | } 14 | 15 | class Substitution_Cipher extends Cipher { 16 | public Substitution_Cipher(String plainText, int key) { 17 | super(plainText, key); 18 | } 19 | 20 | @Override 21 | String Encryption() { 22 | char[] plainTextChars = plainText.toLowerCase().toCharArray(); 23 | char[] cipherTextChars = new char[plainTextChars.length]; 24 | 25 | for (int i = 0; i < plainTextChars.length; i++) { 26 | char ch = plainTextChars[i]; 27 | if (ch >= 'a' && ch <= 'z') { 28 | int index = ch - 'a'; 29 | cipherTextChars[i] = "qazwsxedcrfvtgbyhnujmikolp".charAt(index); 30 | } else { 31 | cipherTextChars[i] = ch; 32 | } 33 | } 34 | 35 | return new String(cipherTextChars); 36 | } 37 | 38 | @Override 39 | String Decryption() { 40 | char[] cipherTextChars = plainText.toLowerCase().toCharArray(); 41 | char[] plainTextChars = new char[cipherTextChars.length]; 42 | 43 | for (int i = 0; i < cipherTextChars.length; i++) { 44 | char ch = cipherTextChars[i]; 45 | if (ch >= 'a' && ch <= 'z') { 46 | int index = "qazwsxedcrfvtgbyhnujmikolp".indexOf(ch); 47 | plainTextChars[i] = (char) ('a' + index); 48 | } else { 49 | plainTextChars[i] = ch; 50 | } 51 | } 52 | 53 | return new String(plainTextChars); 54 | } 55 | } 56 | 57 | class Caesar_Cipher extends Cipher { 58 | public Caesar_Cipher(String plainText, int key) { 59 | super(plainText, key); 60 | } 61 | 62 | @Override 63 | String Encryption() { 64 | char[] plainTextChars = plainText.toCharArray(); 65 | char[] cipherTextChars = new char[plainTextChars.length]; 66 | 67 | for (int i = 0; i < plainTextChars.length; i++) { 68 | char ch = plainTextChars[i]; 69 | if (Character.isLetter(ch)) { 70 | char base = Character.isUpperCase(ch) ? 'A' : 'a'; 71 | cipherTextChars[i] = (char) ((ch - base + key) % 26 + base); 72 | } else { 73 | cipherTextChars[i] = ch; 74 | } 75 | } 76 | 77 | return new String(cipherTextChars); 78 | } 79 | 80 | @Override 81 | String Decryption() { 82 | // Decryption in Caesar Cipher is the same as encryption with a negative key 83 | return new Caesar_Cipher(plainText, 26 - key).Encryption(); 84 | } 85 | } 86 | 87 | public class Main { 88 | public static void main(String[] args) { 89 | String text = "gcet"; 90 | int key = 3; 91 | 92 | Cipher substitutionCipher = new Substitution_Cipher(text, key); 93 | System.out.println("Substitution Cipher Encryption: " + substitutionCipher.Encryption()); 94 | System.out.println("Substitution Cipher Decryption: " + substitutionCipher.Decryption()); 95 | 96 | Cipher caesarCipher = new Caesar_Cipher(text, key); 97 | System.out.println("Caesar Cipher Encryption: " + caesarCipher.Encryption()); 98 | System.out.println("Caesar Cipher Decryption: " + caesarCipher.Decryption()); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /Practicals/Practical Set 4/p44.java: -------------------------------------------------------------------------------- 1 | interface Property { 2 | double computePrice(); 3 | } 4 | 5 | class Bungalow implements Property { 6 | private String name; 7 | private double constructionArea; 8 | private double landArea; 9 | 10 | public Bungalow(String name, double constructionArea, double landArea) { 11 | this.name = name; 12 | this.constructionArea = constructionArea; 13 | this.landArea = landArea; 14 | } 15 | 16 | @Override 17 | public double computePrice() { 18 | double constructionCost = constructionArea * 500; // Rs. 500/- per sq.feet 19 | double landCost = landArea * 400; // Rs. 400/- per sq.feet for landArea 20 | return constructionCost + landCost; 21 | } 22 | } 23 | 24 | class Flat implements Property { 25 | private String name; 26 | private double constructionArea; 27 | 28 | public Flat(String name, double constructionArea) { 29 | this.name = name; 30 | this.constructionArea = constructionArea; 31 | } 32 | 33 | @Override 34 | public double computePrice() { 35 | double constructionCost = constructionArea * 500; // Rs. 500/- per sq.feet 36 | return constructionCost + 200000; // Additional cost for Flat: Rs. 200,000/- 37 | } 38 | } 39 | 40 | public class Main { 41 | public static void main(String[] args) { 42 | Bungalow bungalow = new Bungalow("Luxury Bungalow", 2500, 1500); 43 | Flat flat = new Flat("Apartment Flat", 1500); 44 | 45 | double bungalowPrice = bungalow.computePrice(); 46 | double flatPrice = flat.computePrice(); 47 | 48 | System.out.println("Bungalow Price: Rs. " + bungalowPrice); 49 | System.out.println("Flat Price: Rs. " + flatPrice); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Practicals/Practical Set 4/p45.java: -------------------------------------------------------------------------------- 1 | public interface GeometricShape { 2 | void describe(); 3 | } 4 | 5 | public interface TwoDShape extends GeometricShape { 6 | double area(); 7 | } 8 | 9 | public interface ThreeDShape extends GeometricShape { 10 | double volume(); 11 | } 12 | 13 | public class Cone implements ThreeDShape { 14 | private double radius; 15 | private double height; 16 | 17 | public Cone(double radius, double height) { 18 | this.radius = radius; 19 | this.height = height; 20 | } 21 | 22 | public double volume() { 23 | return (1.0 / 3.0) * Math.PI * radius * radius * height; 24 | } 25 | 26 | public void describe() { 27 | System.out.println("Cone - Radius: " + radius + " units, Height: " + height + " units"); 28 | } 29 | } 30 | 31 | public class Rectangle implements TwoDShape { 32 | private double width, height; 33 | 34 | public Rectangle(double width, double height) { 35 | this.width = width; 36 | this.height = height; 37 | } 38 | 39 | public double area() { 40 | return width * height; 41 | } 42 | 43 | public void describe() { 44 | System.out.println("Rectangle - Width: " + width + " units, Height: " + height + " units"); 45 | } 46 | } 47 | 48 | public class Sphere implements ThreeDShape { 49 | private double radius; 50 | 51 | public Sphere(double radius) { 52 | this.radius = radius; 53 | } 54 | 55 | public double volume() { 56 | return (4.0 / 3.0) * Math.PI * radius * radius * radius; 57 | } 58 | 59 | public void describe() { 60 | System.out.println("Sphere - Radius: " + radius + " units"); 61 | } 62 | } 63 | 64 | public class TestGeometricShapes { 65 | public static void main(String[] args) { 66 | GeometricShape[] shapes = new GeometricShape[3]; 67 | shapes[0] = new Cone(5.0, 10.0); 68 | shapes[1] = new Rectangle(8.0, 6.0); 69 | shapes[2] = new Sphere(4.0); 70 | 71 | for (GeometricShape shape : shapes) { 72 | shape.describe(); 73 | if (shape instanceof TwoDShape) { 74 | TwoDShape twoDShape = (TwoDShape) shape; 75 | System.out.println("Area: " + twoDShape.area() + " square units"); 76 | } 77 | if (shape instanceof ThreeDShape) { 78 | ThreeDShape threeDShape = (ThreeDShape) shape; 79 | System.out.println("Volume: " + threeDShape.volume() + " cubic units"); 80 | } 81 | System.out.println(); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Practicals/Practical Set 4/p51.java: -------------------------------------------------------------------------------- 1 | /* 2 | nner Class: 3 | Define two nested classes: Processor and RAM inside the outer class: CPU with following 4 | data members 5 | class CPU { 6 | double price; 7 | class Processor{ // nested class 8 | double cores; 9 | double catch() 10 | String manufacturer; 11 | double getCache() 12 | void displayProcesorDetail() 13 | } 14 | protected class RAM{ // nested protected class 15 | // members of protected nested class 16 | double memory; 17 | String manufacturer; 18 | Double clockSpeed; 19 | double getClockSpeed() 20 | void displayRAMDetail() 21 | } 22 | } 23 | 1. Write appropriate Constructor and create instance of Outer and inner class and call the 24 | methods in main function 25 | */ 26 | 27 | class CPU { 28 | double price; 29 | 30 | class Processor { 31 | double cores; 32 | String manufacturer; 33 | 34 | double getCache() { 35 | return 4.0; // Some default cache value for demonstration 36 | } 37 | 38 | void displayProcessorDetail() { 39 | System.out.println("Processor Cores: " + cores); 40 | System.out.println("Processor Manufacturer: " + manufacturer); 41 | System.out.println("Processor Cache: " + getCache() + " MB"); 42 | } 43 | } 44 | 45 | protected class RAM { 46 | double memory; 47 | String manufacturer; 48 | Double clockSpeed; 49 | 50 | double getClockSpeed() { 51 | return 2.4; // Some default clock speed value for demonstration 52 | } 53 | 54 | void displayRAMDetail() { 55 | System.out.println("RAM Memory: " + memory + " GB"); 56 | System.out.println("RAM Manufacturer: " + manufacturer); 57 | System.out.println("RAM Clock Speed: " + getClockSpeed() + " GHz"); 58 | } 59 | } 60 | 61 | CPU(double price) { 62 | this.price = price; 63 | } 64 | 65 | Processor createProcessor(double cores, String manufacturer) { 66 | return new Processor(cores, manufacturer); 67 | } 68 | 69 | RAM createRAM(double memory, String manufacturer) { 70 | return new RAM(memory, manufacturer); 71 | } 72 | } 73 | 74 | public class Main { 75 | public static void main(String[] args) { 76 | CPU cpu = new CPU(500.0); 77 | CPU.Processor processor = cpu.createProcessor(4, "Intel"); 78 | CPU.RAM ram = cpu.createRAM(8, "Kingston"); 79 | 80 | System.out.println("CPU Price: $" + cpu.price); 81 | System.out.println("Processor Details:"); 82 | processor.displayProcessorDetail(); 83 | System.out.println("\nRAM Details:"); 84 | ram.displayRAMDetail(); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /Practicals/Practical Set 5/p52.java: -------------------------------------------------------------------------------- 1 | public class InnerClassDemo { 2 | // Static inner class 3 | static class StaticInner { 4 | void display() { 5 | System.out.println("This is a static inner class."); 6 | } 7 | } 8 | 9 | public void demoLocalInnerClass() { 10 | // Local inner class 11 | class LocalInner { 12 | void display() { 13 | System.out.println("This is a local inner class."); 14 | } 15 | } 16 | 17 | LocalInner localInner = new LocalInner(); 18 | localInner.display(); 19 | } 20 | 21 | public void demoAnonymousInnerClass() { 22 | // Anonymous inner class 23 | Runnable runnable = new Runnable() { 24 | @Override 25 | public void run() { 26 | System.out.println("This is an anonymous inner class."); 27 | } 28 | }; 29 | 30 | Thread thread = new Thread(runnable); 31 | thread.start(); 32 | } 33 | 34 | public static void main(String[] args) { 35 | // Static inner class usage 36 | StaticInner staticInner = new StaticInner(); 37 | staticInner.display(); 38 | 39 | // Local inner class usage 40 | InnerClassDemo outer = new InnerClassDemo(); 41 | outer.demoLocalInnerClass(); 42 | 43 | // Anonymous inner class usage 44 | outer.demoAnonymousInnerClass(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ADITPWJ 2 | Programming With Java Code 3 | --------------------------------------------------------------------------------