Skip to content

Update #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Collections/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1648176090312</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Set;

public class CollectionsDemo {

public static void main(String[] args) {
ArrayList<String> list = new ArrayList<>();
list.add("One");
Expand Down Expand Up @@ -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<Integer> iList = new ArrayList<>();
iList.add(10);
iList.add(20);
iList.add(40);
iList.add(30);
List<Integer> 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
Expand All @@ -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<String> emptySet = Collections.emptySet();
List<String> emptyList = Collections.emptyList();
Map<String, String> 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<String> 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<Integer> indexList)
{
immutableCollection(); // Extracted Method
replaceAndShuffle(indexList); // Extracted Method
singletonCollection(); // Extracted Method
synchronizedCollection(); // Extracted Method
}
static void immutableCollection()
{
//Creating Immutable Collection
Set<String> emptySet = Collections.emptySet();
List<String> emptyList = Collections.emptyList();
Map<String, String> 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<Integer> 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<String> 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<Integer, String> map = new HashMap<>();
map = Collections.synchronizedMap(map);
System.out.println("Creating synchronizing Collection : ");
static void synchronizedCollection()
{
//Creating synchronized Collection List, Set, Map
Map<Integer, String> map = new HashMap<>();
map = Collections.synchronizedMap(map);
System.out.println("Creating synchronizing Collection : ");
}
}
12 changes: 6 additions & 6 deletions Collections/src/com/cdac/collections/list/LinkedListDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions EncryptionDecryption/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1648176090459</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
1 change: 0 additions & 1 deletion EncryptionDecryption/bin/.gitignore

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file added EncryptionDecryption/bin/snippet/Snippet.class
Binary file not shown.
26 changes: 17 additions & 9 deletions EncryptionDecryption/src/com/cdac/encrypt/aes/AESEncryption.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion EncryptionDecryption/src/snippet/Snippet.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package snippet;

public class Snippet {
Divisors are
//Divisors are
}

11 changes: 11 additions & 0 deletions ExceptionHandling/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1648176090490</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
11 changes: 11 additions & 0 deletions FileIO/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1648176090550</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
11 changes: 11 additions & 0 deletions Generics/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1648176090569</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
11 changes: 11 additions & 0 deletions InterviewPrograms/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1648176090588</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
11 changes: 11 additions & 0 deletions JavaEnums/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1648176090621</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
11 changes: 11 additions & 0 deletions Networking/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1648176090659</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
11 changes: 11 additions & 0 deletions Reflections/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1648176090681</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
11 changes: 11 additions & 0 deletions Threads/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1648176090709</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>