diff --git a/Collections/.project b/Collections/.project index c461daf..7747fd9 100644 --- a/Collections/.project +++ b/Collections/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1648176090312 + + 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..148adfe 100644 --- a/Collections/src/com/cdac/collections/collectionsutils/CollectionsDemo.java +++ b/Collections/src/com/cdac/collections/collectionsutils/CollectionsDemo.java @@ -9,7 +9,6 @@ import java.util.Set; public class CollectionsDemo { - public static void main(String[] args) { ArrayList list = new ArrayList<>(); list.add("One"); @@ -51,14 +50,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 +70,57 @@ 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/list/LinkedListDemo.java b/Collections/src/com/cdac/collections/list/LinkedListDemo.java index a2176ae..50a8f61 100644 --- a/Collections/src/com/cdac/collections/list/LinkedListDemo.java +++ b/Collections/src/com/cdac/collections/list/LinkedListDemo.java @@ -22,9 +22,9 @@ public static void main(String[] args) { osList.addLast("WebOS"); //GET ELEMENT - String firstElt = osList.getFirst(); - String lastElt = osList.getLast(); - String eltAtZero = osList.get(0); + String FirstElement = osList.getFirst(); + String LastElement = osList.getLast(); + String elementAtZero = osList.get(0); //GET ELEMENTS USING PEEK AND POLL //PEEK MEANS RETRIEVES THE ELEMENTS BUT DOES NOT REMOVE THE ELEMENT @@ -54,13 +54,13 @@ public static void main(String[] args) { } //Removes first Element - String elt = osList.remove(); + String Element = osList.remove(); //Removes element at given index - elt = osList.remove(2); + Element = osList.remove(2); //Removes First Element - elt = osList.removeFirst(); + Element = osList.removeFirst(); //Removes Last Element osList.removeLast(); diff --git a/EncryptionDecryption/.project b/EncryptionDecryption/.project index 2197d2e..153f5ee 100644 --- a/EncryptionDecryption/.project +++ b/EncryptionDecryption/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1648176090459 + + 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 86148c9..b328de9 100644 Binary files a/EncryptionDecryption/bin/com/cdac/encrypt/aes/AESEncryption.class and b/EncryptionDecryption/bin/com/cdac/encrypt/aes/AESEncryption.class differ 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 0000000..ba1137f Binary files /dev/null and b/EncryptionDecryption/bin/com/cdac/encrypt/aes/encryptdecrypt.class differ diff --git a/EncryptionDecryption/bin/snippet/Snippet.class b/EncryptionDecryption/bin/snippet/Snippet.class new file mode 100644 index 0000000..d3e0080 Binary files /dev/null and b/EncryptionDecryption/bin/snippet/Snippet.class differ diff --git a/EncryptionDecryption/src/com/cdac/encrypt/aes/AESEncryption.java b/EncryptionDecryption/src/com/cdac/encrypt/aes/AESEncryption.java index b0db7ce..7169df9 100644 --- a/EncryptionDecryption/src/com/cdac/encrypt/aes/AESEncryption.java +++ b/EncryptionDecryption/src/com/cdac/encrypt/aes/AESEncryption.java @@ -14,25 +14,33 @@ */ public class AESEncryption { - public static void main(String[] args) { - final String strToEncrypt = "My text to encrypt"; + public static void main(String[] args) + { + final String strToEncrypt = "My text to encrypt"; final String strPssword = "f2fc2007-b24b-4ab5-b62f-8dba873d0341"; - AESEncryption.setKey(strPssword); - AESEncryption.encrypt(strToEncrypt.trim()); + encryptdecrypt.setKey(strPssword); + //encryptdecrypt is called from main funcation + encryptdecrypt.encrypt(strToEncrypt.trim()); System.out.println("String to Encrypt: " + strToEncrypt); - System.out.println("Encrypted: " + AESEncryption.getEncryptedString()); - final String strToDecrypt = AESEncryption.getEncryptedString(); - AESEncryption.decrypt(strToDecrypt.trim()); + System.out.println("Encrypted: " + encryptdecrypt.getEncryptedString()); + final String strToDecrypt = encryptdecrypt.getEncryptedString(); + encryptdecrypt.decrypt(strToDecrypt.trim()); System.out.println("String To Decrypt : " + strToDecrypt); - System.out.println("Decrypted : " + AESEncryption.getDecryptedString()); + System.out.println("Decrypted : " + encryptdecrypt.getDecryptedString()); } +} +//class encryptdecrypt increases the readability of the code. So, it is extracted to another new class. +//funcationality remains the same besides having refactoring +class encryptdecrypt +{ private static SecretKeySpec secretKey; private static byte[] key; private static String decryptedString; private static String encryptedString; - public static void setKey(String myKey) { + public static void setKey(String myKey) + { MessageDigest sha = null; try { key = myKey.getBytes("UTF-8"); diff --git a/EncryptionDecryption/src/snippet/Snippet.java b/EncryptionDecryption/src/snippet/Snippet.java index 7aaeb24..55f52ff 100644 --- a/EncryptionDecryption/src/snippet/Snippet.java +++ b/EncryptionDecryption/src/snippet/Snippet.java @@ -1,6 +1,6 @@ package snippet; public class Snippet { - Divisors are + //Divisors are } diff --git a/ExceptionHandling/.project b/ExceptionHandling/.project index d1a8803..f39f516 100644 --- a/ExceptionHandling/.project +++ b/ExceptionHandling/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1648176090490 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/FileIO/.project b/FileIO/.project index 178ff18..c38298b 100644 --- a/FileIO/.project +++ b/FileIO/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1648176090550 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/Generics/.project b/Generics/.project index 35f7874..7efcc66 100644 --- a/Generics/.project +++ b/Generics/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1648176090569 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/InterviewPrograms/.project b/InterviewPrograms/.project index faaf7d1..5e72962 100644 --- a/InterviewPrograms/.project +++ b/InterviewPrograms/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1648176090588 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/JavaEnums/.project b/JavaEnums/.project index 36a5aea..a133341 100644 --- a/JavaEnums/.project +++ b/JavaEnums/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1648176090621 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/Networking/.project b/Networking/.project index bf949aa..bebdc59 100644 --- a/Networking/.project +++ b/Networking/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1648176090659 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/Reflections/.project b/Reflections/.project index d5dae35..7fd31bc 100644 --- a/Reflections/.project +++ b/Reflections/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1648176090681 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/Threads/.project b/Threads/.project index 35e7365..d0a4e13 100644 --- a/Threads/.project +++ b/Threads/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1648176090709 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + +