From 0d8e9c440e469ebfa44891b14c24581f4ce65751 Mon Sep 17 00:00:00 2001 From: Nirav Radadiya Date: Tue, 22 Mar 2022 11:53:59 -0300 Subject: [PATCH 1/3] Refactored Code --- Collections/.project | 11 ++ .../collectionsutils/CollectionsDemo.java | 94 +++++++++++------- .../threadsafe/EmployeeRunnable.java | 12 +-- .../collections/threadsafe/MainProgram.java | 69 ++++++++++--- .../threadsafe/StudentRunnable.java | 17 ++-- EncryptionDecryption/.project | 11 ++ EncryptionDecryption/bin/.gitignore | 1 - .../com/cdac/encrypt/aes/AESEncryption.class | Bin 3725 -> 1361 bytes .../com/cdac/encrypt/aes/encryptdecrypt.class | Bin 0 -> 3179 bytes .../bin/snippet/Snippet.class | Bin 0 -> 262 bytes .../com/cdac/encrypt/aes/AESEncryption.java | 26 +++-- EncryptionDecryption/src/snippet/Snippet.java | 6 +- ExceptionHandling/.project | 11 ++ FileIO/.project | 11 ++ Generics/.project | 11 ++ InterviewPrograms/.project | 11 ++ .../src/com/java/strings/CountVowels.java | 74 +++++++++++--- JavaEnums/.project | 11 ++ Networking/.project | 11 ++ Reflections/.project | 11 ++ Threads/.project | 11 ++ 21 files changed, 316 insertions(+), 93 deletions(-) delete mode 100644 EncryptionDecryption/bin/.gitignore create mode 100644 EncryptionDecryption/bin/com/cdac/encrypt/aes/encryptdecrypt.class create mode 100644 EncryptionDecryption/bin/snippet/Snippet.class diff --git a/Collections/.project b/Collections/.project index c461daf..5ea0f58 100644 --- a/Collections/.project +++ b/Collections/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1647954731126 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/Collections/src/com/cdac/collections/collectionsutils/CollectionsDemo.java b/Collections/src/com/cdac/collections/collectionsutils/CollectionsDemo.java index 954db7a..8b5f045 100644 --- a/Collections/src/com/cdac/collections/collectionsutils/CollectionsDemo.java +++ b/Collections/src/com/cdac/collections/collectionsutils/CollectionsDemo.java @@ -8,8 +8,8 @@ import java.util.Map; import java.util.Set; -public class CollectionsDemo { - +public class CollectionsDemo +{ public static void main(String[] args) { ArrayList list = new ArrayList<>(); list.add("One"); @@ -51,14 +51,14 @@ public static void main(String[] args) { String min = Collections.min(list); System.out.println("Min Element in the List : "+min); - List iList = new ArrayList<>(); - iList.add(10); - iList.add(20); - iList.add(40); - iList.add(30); + List indexList = new ArrayList<>(); //iList name is not understadable can be converted to List 2 or IndexList + indexList.add(10); + indexList.add(20); + indexList.add(40); + indexList.add(30); //Binary Search in List Collection - int index = Collections.binarySearch(iList, 190); + int index = Collections.binarySearch(indexList, 190); System.out.println("Binary Search of 190 index is : "+index); //Copy one list to another list @@ -71,36 +71,60 @@ public static void main(String[] args) { newList.add(14); newList.add(15); //newList should have minimum size as iList - Collections.copy(newList, iList); + Collections.copy(newList, indexList); System.out.println("Copying the list from another list : "+newList); - //Creating Immutable Collection - Set emptySet = Collections.emptySet(); - List emptyList = Collections.emptyList(); - Map emptyMap = Collections.emptyMap(); - System.out.println("Creating immutable collection (list, set, map)"); - System.out.println("Empty Set : "+emptySet.size()); - //emptySet.add("Try"); //not allowed its immutable - - //replacing all the elements with the new value - Collections.replaceAll(iList, 10, 100); - System.out.println("Replacing all the 10 in the list with 100 :"); - System.out.println(iList); - - //shuffling the list - Collections.shuffle(iList); - System.out.println("Shuffle the Elements in the List : "); - System.out.println(iList); + + + methodCalling(indexList); //Calling all methods from one place - //Creating singleton Collection Set, List, Map - Set singletonSet = Collections.singleton("Java"); - System.out.println("Creating singleton Collection : "); - System.out.println(singletonSet); -// singletonSet.add("Hello"); //not supported its immutable + } + + static void methodCalling(List indexList) + { + immutableCollection(); // Extracted Method + replaceAndShuffle(indexList); // Extracted Method + singletonCollection(); // Extracted Method + synchronizedCollection(); // Extracted Method + } + static void immutableCollection() + { + //Creating Immutable Collection + Set emptySet = Collections.emptySet(); + List emptyList = Collections.emptyList(); + Map emptyMap = Collections.emptyMap(); + System.out.println("Creating immutable collection (list, set, map)"); + System.out.println("Empty Set : "+emptySet.size()); + //emptySet.add("Try"); //not allowed its immutable + } + + static void replaceAndShuffle(List indexList) + { + //replacing all the elements with the new value + Collections.replaceAll(indexList, 10, 100); + System.out.println("Replacing all the 10 in the list with 100 :"); + System.out.println(indexList); + + //shuffling the list + Collections.shuffle(indexList); + System.out.println("Shuffle the Elements in the List : "); + System.out.println(indexList); + } + + static void singletonCollection() + { + //Creating singleton Collection Set, List, Map + Set singletonSet = Collections.singleton("Java"); + //singletonSet.add("Hello"); //not supported its immutable + System.out.println("Creating singleton Collection : "); + System.out.println(singletonSet); + } - //Creating synchronized Collection List, Set, Map - Map map = new HashMap<>(); - map = Collections.synchronizedMap(map); - System.out.println("Creating synchronizing Collection : "); + static void synchronizedCollection() + { + //Creating synchronized Collection List, Set, Map + Map map = new HashMap<>(); + map = Collections.synchronizedMap(map); + System.out.println("Creating synchronizing Collection : "); } } \ No newline at end of file diff --git a/Collections/src/com/cdac/collections/threadsafe/EmployeeRunnable.java b/Collections/src/com/cdac/collections/threadsafe/EmployeeRunnable.java index 4670969..b528193 100644 --- a/Collections/src/com/cdac/collections/threadsafe/EmployeeRunnable.java +++ b/Collections/src/com/cdac/collections/threadsafe/EmployeeRunnable.java @@ -2,7 +2,8 @@ import java.util.ArrayList; -public class EmployeeRunnable implements Runnable{ +public class EmployeeRunnable +{ ArrayList names; @@ -10,9 +11,6 @@ public EmployeeRunnable(ArrayList list) { this.names = list; } - @Override - public void run() { - for(int i=0;i<100;i++) - names.add("Employee :: "+i); - } -} \ No newline at end of file + +} +//run method moved to MainProgram.java \ No newline at end of file diff --git a/Collections/src/com/cdac/collections/threadsafe/MainProgram.java b/Collections/src/com/cdac/collections/threadsafe/MainProgram.java index 29775ed..583212f 100644 --- a/Collections/src/com/cdac/collections/threadsafe/MainProgram.java +++ b/Collections/src/com/cdac/collections/threadsafe/MainProgram.java @@ -1,22 +1,65 @@ package com.cdac.collections.threadsafe; - import java.util.ArrayList; +// import com.cdac.collections.bean.Student; +// Applying move method run to main program, decreases the complexity of tread running +public class MainProgram implements Runnable +{ + public static void main(String[] args) throws CloneNotSupportedException { -import com.cdac.collections.bean.Student; - -public class MainProgram { - public static void main(String[] args) throws CloneNotSupportedException { - ArrayList list = new ArrayList<>(); - EmployeeRunnable employeeRunnable = new EmployeeRunnable(list); - StudentRunnable studentRunnable = new StudentRunnable(list); - - Thread t1 = new Thread(employeeRunnable); - Thread t2 = new Thread(studentRunnable); + Thread t1 = new Thread(); + Thread t2 = new Thread(); t1.start(); t2.start(); + ArrayList list = new ArrayList<>(); + EmployeeRunnable employeeRunnable = new EmployeeRunnable(list); + StudentRunnable studentRunnable = new StudentRunnable(list); - + + } + public void run() + { + ArrayList Employeenames = null; + ArrayList Studentnames = null; + for(int i=0;i<100;i++) + { + Employeenames.add("Employee :: "+i); + } + for(int j =100; j<200;j++) + { + Studentnames.add("Student :: "+j); + } } -} \ No newline at end of file + +} +// class EmployeeRunnable implements Runnable +// { + +// ArrayList names; + +// public EmployeeRunnable(ArrayList list) { +// this.names = list; +// } + +// @Override +// public void run() { +// for(int i=0;i<100;i++) +// names.add("Employee :: "+i); +// } +// } + +// class StudentRunnable implements Runnable +// { + +// ArrayList names; + +// public StudentRunnable(ArrayList list) { +// this.names = list; +// } +// @Override +// public void run() { +// for(int i=100;i<200;i++) +// names.add("Student :: "+i); +// } + diff --git a/Collections/src/com/cdac/collections/threadsafe/StudentRunnable.java b/Collections/src/com/cdac/collections/threadsafe/StudentRunnable.java index 918a0c5..192b510 100644 --- a/Collections/src/com/cdac/collections/threadsafe/StudentRunnable.java +++ b/Collections/src/com/cdac/collections/threadsafe/StudentRunnable.java @@ -2,17 +2,12 @@ import java.util.ArrayList; -public class StudentRunnable implements Runnable{ - +public class StudentRunnable +{ ArrayList names; - - public StudentRunnable(ArrayList list) { + public StudentRunnable(ArrayList list) + { this.names = list; } - @Override - public void run() { - for(int i=100;i<200;i++) - names.add("Student :: "+i); - } - -} \ No newline at end of file +} +//run method moved to MainProgram.java \ No newline at end of file diff --git a/EncryptionDecryption/.project b/EncryptionDecryption/.project index 2197d2e..18368b6 100644 --- a/EncryptionDecryption/.project +++ b/EncryptionDecryption/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1647954731142 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/EncryptionDecryption/bin/.gitignore b/EncryptionDecryption/bin/.gitignore deleted file mode 100644 index d728ce5..0000000 --- a/EncryptionDecryption/bin/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/snippet/ diff --git a/EncryptionDecryption/bin/com/cdac/encrypt/aes/AESEncryption.class b/EncryptionDecryption/bin/com/cdac/encrypt/aes/AESEncryption.class index 86148c98c542a0320022dfd23aa82214efb050b1..b328de9ac4fc51578c58b451904041f156cfec77 100644 GIT binary patch delta 729 zcmZ9KT~8BH5Qd+#3*Bv5wQO5Up};~#r3$4Af<@)q&w?OEgNYZ7Z3w2eglts2;TL$( z?6p5aFA9-_YvY~wM*oR%wp%qZCpk0o&O3A7Ip@6Z{}zdS{q^|-m}IjNnQxr*gu)h` zgc{%9q`DRM>b~Pv-nx!kcPh0Pd;7btNzALN(QtyK!C6J75lzI}xpJjNvFIV?eNdT! zKKc#Pis;MI>r$>-s%_^s-MyXKw#5L0-Vf!N35G0&$#@}cDm20cgY({kme4OU>TPL` zy5zmnviUJ`2IGoYtIYS~Iw!NO~K3a>Qg((X|o?uapZ; zggn>$0aFnY%vf9(72SH$%rk3ogPY!jKKne+oW(qY3e&9zdVTt$#S$4gs6D31iXtB5 zoyT=&IhfulI3{-#Ry(eg1@Y_eS=^W7zUWIayZHZw%zELDwD&ALe83P2UETyV@#HaN zHzdl5Rbo4{hnOE*>4@xp8qUxqyA=?`o{}icX~BcypLEEAx*aXr_Nr|k5x1jFdXI3P ze&U>+ZE{)c@d5cQ`|2T6M@%;~of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pTttF1W9yJ5=!1z_A^J@X-x8ctbJpp6NiRh49ehv4ck3Or;^qsfwCH!Fmjd zT(+{XQ2*@R_>JSdCvI)X<X^t9 zyX;u0WZJ_8-El-0RecvY^An4Mv=-z8tp!ohJ~)etb}C2KjT~7N97Toj(Zk;@T%|ZF z95;2WVCxM|0(cjHLvnK~Vw`K90JdWXR}t*QF7AlK|Dm}Sj#jL7Jk~Z5YpY>zthI^< zYdC!VCK9n!6~{T=M&Dele+2_IJX*zjs~F}!=aWe(ds@g!nK8<6&zGq0o|7jh8vA$M zJjOx?oea{s5Z&8M=XTJ&eQ4!VbvOFahR3i6v)GFgcSSfIp39iR`?w0CfcFy@CK7pM zI1BL9NlbGVWUzc)dBG|n;wli)ZQ^JZPhUk?j32u}7XoxI!z)0H^K9WknUy}K4LHQz zBMkKs2HVcS5;%-bCh{oX9ZAX`qw^`A>cRya$5ZH86}FB~ND>6_B%Z}58QL`Acn;4~ z=LI?Y6lb5Nl~x4*M;8Jr;wmpfMaAVaDxPT}CVWQt1Q4V6Yq^ORu5(;Xo<31{+jxO@exOuoF{Q!Eub>6-~-gZ{; ziw1F(>oWF-nZ9d&N)NC~fiq;^S(elo`T95?X zJ-yBv4^X;|NxZ>5kvjf|wxHr#8-eGG(GTJc(pO-dj@^_&Z1RG*jrd$=4ZrEAqQ*#8 z@cSD6xH^bGzk?w5&?%5CA+l);W*ERMT{_PI=41eI4?bB`s{^=)+X4KQ>H_#1{?0MR R*_&+Q|6n+;bNnYF{|Dz9dK3Tv diff --git a/EncryptionDecryption/bin/com/cdac/encrypt/aes/encryptdecrypt.class b/EncryptionDecryption/bin/com/cdac/encrypt/aes/encryptdecrypt.class new file mode 100644 index 0000000000000000000000000000000000000000..ba1137f2f5749075fd5a56b4dd3689555caecf80 GIT binary patch literal 3179 zcma)8X;%|h7=CVmOfrs3qk^DTEQl;>T!5-rD`8Otlp3J5ap{nZ5Dl3$Gf`=4S8Mlu zxBF^szqp(eIQ1NVKz~%*=iW(>)%q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hABu+AcQw-@e6EIZ*)gFBKbxs0{gzdv`%)*Cj_?>HryQ>^?*O|_Fu74o-9~hqV AIsgCw literal 0 HcmV?d00001 diff --git a/EncryptionDecryption/bin/snippet/Snippet.class b/EncryptionDecryption/bin/snippet/Snippet.class new file mode 100644 index 0000000000000000000000000000000000000000..d3e0080c42a80935678db40fc18502212b3d28ac GIT binary patch literal 262 zcmZ8by%ND-5Zud;5J7kY9SUi5jK+*AL&503#5a7INKAzHQkhYB01su{hf1@1yEk{c z&)59{U*abv(*4Sbf=nMeq}G5kV@lU9gN28JC30L}jX+63kwIL$GG~R=O}z z^I)UGe?pbX#rY7)VlARn5;|cXi*zFjrS;FW%Dp-f+Tma9nBcDRa}mqA(#PJf&QLc& r7o5wb!Av@j(P0&QG++;Is9xDH;4 org.eclipse.jdt.core.javanature + + + 1647954731166 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/FileIO/.project b/FileIO/.project index 178ff18..46e10c7 100644 --- a/FileIO/.project +++ b/FileIO/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1647954731181 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/Generics/.project b/Generics/.project index 35f7874..9b430bc 100644 --- a/Generics/.project +++ b/Generics/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1647954731191 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/InterviewPrograms/.project b/InterviewPrograms/.project index faaf7d1..a765cf4 100644 --- a/InterviewPrograms/.project +++ b/InterviewPrograms/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1647954731205 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/InterviewPrograms/src/com/java/strings/CountVowels.java b/InterviewPrograms/src/com/java/strings/CountVowels.java index 278b85f..0dd4a2a 100644 --- a/InterviewPrograms/src/com/java/strings/CountVowels.java +++ b/InterviewPrograms/src/com/java/strings/CountVowels.java @@ -31,30 +31,74 @@ * by, cry, crypt, fry, gym, psych, spy */ -public class CountVowels { +public class CountVowels extends countVow { public static void main(String[] args) { // String line = "Java Interview Programs"; // String line = "Hello World!"; String line = "Rhythm"; - int count = 0; + System.out.println("Given String is :"+line); line = line.toLowerCase(); - for(char ch : line.toCharArray()){ - switch (ch) { - case 'a': - case 'e': - case 'i': - case 'o': - case 'u': - count++; - break; - default: - break; - } - } + + countVow c = new CountVowels(); + c.count(line); System.out.println("Number of Vowels are :"+count); } + + @Override + void count(String line) { + // TODO Auto-generated method stub + + } +} + +//extract class +abstract class countVow +{ + static int count = 0; + abstract void count(String line); + +} +class a extends countVow +{ + @Override + public void count(String line) + { + count++; + } +} +class e extends countVow +{ + @Override + public void count(String line) + { + count++; + } +} +class i extends countVow +{ + @Override + public void count(String line) + { + count++; + } +} +class o extends countVow +{ + @Override + public void count(String line) + { + count++; + } +} +class u extends countVow +{ + @Override + public void count(String line) + { + count++; + } } /* OUTPUT diff --git a/JavaEnums/.project b/JavaEnums/.project index 36a5aea..3e26146 100644 --- a/JavaEnums/.project +++ b/JavaEnums/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1647954731215 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/Networking/.project b/Networking/.project index bf949aa..2ddd01c 100644 --- a/Networking/.project +++ b/Networking/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1647954731223 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/Reflections/.project b/Reflections/.project index d5dae35..92518f1 100644 --- a/Reflections/.project +++ b/Reflections/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1647954731243 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/Threads/.project b/Threads/.project index 35e7365..bf2e10d 100644 --- a/Threads/.project +++ b/Threads/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1647954731264 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + From 380d541eedbabf17a78a2b75b8d910db332fc12a Mon Sep 17 00:00:00 2001 From: Nirav Radadiya Date: Tue, 22 Mar 2022 12:03:18 -0300 Subject: [PATCH 2/3] Refactored Code --- .../src/com/java/strings/CountVowels.java | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/InterviewPrograms/src/com/java/strings/CountVowels.java b/InterviewPrograms/src/com/java/strings/CountVowels.java index 0dd4a2a..6c89d13 100644 --- a/InterviewPrograms/src/com/java/strings/CountVowels.java +++ b/InterviewPrograms/src/com/java/strings/CountVowels.java @@ -32,24 +32,21 @@ */ public class CountVowels extends countVow { - public static void main(String[] args) { + public static void main(String[] args) + { // String line = "Java Interview Programs"; -// String line = "Hello World!"; - String line = "Rhythm"; - - + String line = "Hello World!"; + // String line = "Rhythm"; System.out.println("Given String is :"+line); line = line.toLowerCase(); - countVow c = new CountVowels(); c.count(line); - System.out.println("Number of Vowels are :"+count); } - @Override - void count(String line) { - // TODO Auto-generated method stub - + int count(String line) + { + System.out.println("Number of Vowels are :"+count); + return 0; } } @@ -57,47 +54,46 @@ void count(String line) { abstract class countVow { static int count = 0; - abstract void count(String line); - + abstract int count(String line); } class a extends countVow { @Override - public void count(String line) + public int count(String line) { - count++; + return count++; } } class e extends countVow { @Override - public void count(String line) + public int count(String line) { - count++; + return count++; } } class i extends countVow { @Override - public void count(String line) + public int count(String line) { - count++; + return count++; } } class o extends countVow { @Override - public void count(String line) + public int count(String line) { - count++; + return count++; } } class u extends countVow { @Override - public void count(String line) + public int count(String line) { - count++; + return count++; } } /* From ce5f417dbfac751ff60e474119b39832896048e6 Mon Sep 17 00:00:00 2001 From: Nirav Radadiya Date: Tue, 22 Mar 2022 12:12:30 -0300 Subject: [PATCH 3/3] Refactored Code 2 --- .../src/com/java/strings/CountVowels.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/InterviewPrograms/src/com/java/strings/CountVowels.java b/InterviewPrograms/src/com/java/strings/CountVowels.java index 6c89d13..a71d3c3 100644 --- a/InterviewPrograms/src/com/java/strings/CountVowels.java +++ b/InterviewPrograms/src/com/java/strings/CountVowels.java @@ -35,8 +35,8 @@ public class CountVowels extends countVow { public static void main(String[] args) { // String line = "Java Interview Programs"; - String line = "Hello World!"; - // String line = "Rhythm"; + // String line = "Hello World!"; + String line = "Rhythm"; System.out.println("Given String is :"+line); line = line.toLowerCase(); countVow c = new CountVowels(); @@ -61,7 +61,7 @@ class a extends countVow @Override public int count(String line) { - return count++; + return count++; // refactored with Replace conditional with polymorphism } } class e extends countVow @@ -69,7 +69,7 @@ class e extends countVow @Override public int count(String line) { - return count++; + return count++; // refactored with Replace conditional with polymorphism } } class i extends countVow @@ -77,7 +77,7 @@ class i extends countVow @Override public int count(String line) { - return count++; + return count++; // refactored with Replace conditional with polymorphism } } class o extends countVow @@ -85,7 +85,7 @@ class o extends countVow @Override public int count(String line) { - return count++; + return count++; // refactored with Replace conditional with polymorphism } } class u extends countVow @@ -93,7 +93,7 @@ class u extends countVow @Override public int count(String line) { - return count++; + return count++; // refactored with Replace conditional with polymorphism } } /*