From ef0fd267c20a8fb00753c18fa2470e7f91581dc0 Mon Sep 17 00:00:00 2001 From: Pradeep Kumar Date: Wed, 30 Nov 2022 09:45:43 +0530 Subject: [PATCH 1/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0df8330..868f30f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Java Basics -*Click if you like the project. Pull Request are highly appreciated.* +> *Click ★ if you like the project. Your contributions are heartily ♡ welcome.*
From 17ba7f2ca1dcb4e4d4ea1826202fd2ae71219bab Mon Sep 17 00:00:00 2001 From: Dnyanesh Nimbalkar <78072155+Dnyaneshvn@users.noreply.github.com> Date: Sat, 3 Dec 2022 23:28:06 +0530 Subject: [PATCH 2/9] deleted extra syntax --- core-java/arrays/package-info.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/core-java/arrays/package-info.java b/core-java/arrays/package-info.java index 42241cb..2c0f888 100644 --- a/core-java/arrays/package-info.java +++ b/core-java/arrays/package-info.java @@ -1,8 +1,6 @@ -/** - * - */ -/** - * @author U6044324 - * Nov 5, 2018 - */ -package arrays; \ No newline at end of file + +/* + @author U6044324 + Nov 5, 2018 +*/ +package arrays; From f39b25450e92ce67e7aebc17940a404a544334ba Mon Sep 17 00:00:00 2001 From: Pradeep Kumar Date: Sun, 19 Feb 2023 10:56:26 +0530 Subject: [PATCH 3/9] Update README.md --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 868f30f..3570c76 100644 --- a/README.md +++ b/README.md @@ -6,16 +6,16 @@ ## Related Topics -* *[Multithreading Basics](multithreading-questions.md)* -* *[Collections Basics](collections-questions.md)* -* *[JDBC Basics](JDBC-questions.md)* +* *[Multithreading](multithreading-questions.md)* +* *[Collections](collections-questions.md)* +* *[Java Database Connectivity (JDBC)](JDBC-questions.md)* * *[Java Programs](java-programs.md)* * *[Java String Methods](java-string-methods.md)* -* *[JSP Basics](jsp-questions.md)* -* *[Servlets Basics](servlets-questions.md)* +* *[Jakarta Server Pages (JSP)](jsp-questions.md)* +* *[Servlets](servlets-questions.md)* * *[Java Multiple Choice Questions](java-multiple-choice-questions-answers.md)* -* *[Spring Basics](https://github.com/learning-zone/spring-basics)* -* *[Hibernate Basics](https://github.com/learning-zone/hibernate-basics)* +* *[Spring Framework Basics](https://github.com/learning-zone/spring-basics)* +* *[Hibernate](https://github.com/learning-zone/hibernate-basics)* * *[Java Design Pattern](https://github.com/learning-zone/java-design-patterns)*
From d1ea04d344ef3eea922fe058f4efd5c7f44e52ab Mon Sep 17 00:00:00 2001 From: Pradeep Kumar Date: Sun, 19 Feb 2023 10:59:49 +0530 Subject: [PATCH 4/9] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3570c76..380fef3 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,9 @@ * *[Jakarta Server Pages (JSP)](jsp-questions.md)* * *[Servlets](servlets-questions.md)* * *[Java Multiple Choice Questions](java-multiple-choice-questions-answers.md)* -* *[Spring Framework Basics](https://github.com/learning-zone/spring-basics)* -* *[Hibernate](https://github.com/learning-zone/hibernate-basics)* * *[Java Design Pattern](https://github.com/learning-zone/java-design-patterns)* +* *[Hibernate](https://github.com/learning-zone/hibernate-basics)* +* *[Spring Framework Basics](https://github.com/learning-zone/spring-basics)*
From 8ab4deb1030b4d863f8d8048b892d34f18dfaebe Mon Sep 17 00:00:00 2001 From: Srinjoy Pal <144480997+srinjoy07pal@users.noreply.github.com> Date: Mon, 25 Dec 2023 20:37:51 +0530 Subject: [PATCH 5/9] Update BinarySearch.java binary search explained in a better way using functions --- core-java/basics/BinarySearch.java | 62 ++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/core-java/basics/BinarySearch.java b/core-java/basics/BinarySearch.java index d30ba02..c8d6694 100644 --- a/core-java/basics/BinarySearch.java +++ b/core-java/basics/BinarySearch.java @@ -1,19 +1,47 @@ -package basics; -import java.util.Arrays; - -public class BinarySearch { - - public static void main(String[] args) { - - int arr[] = {10, 20, 15, 22, 35}; - Arrays.sort(arr); - - int key = 35; - int res = Arrays.binarySearch(arr, key); - if(res >= 0){ - System.out.println(key + " found at index = "+ res); - } else { - System.out.println(key + " not found"); - } +// Java implementation of iterative Binary Search + +import java.io.*; + +class BinarySearch { + + // Returns index of x if it is present in arr[]. + int binarySearch(int arr[], int x) + { + int l = 0, r = arr.length - 1; + while (l <= r) { + int m = l + (r - l) / 2; + + // Check if x is present at mid + if (arr[m] == x) + return m; + + // If x greater, ignore left half + if (arr[m] < x) + l = m + 1; + + // If x is smaller, ignore right half + else + r = m - 1; + } + + // If we reach here, then element was + // not present + return -1; + } + + // Driver code + public static void main(String args[]) + { + BinarySearch ob = new BinarySearch(); + int arr[] = { 2, 3, 4, 10, 40 }; + int n = arr.length; + int x = 10; + int result = ob.binarySearch(arr, x); + if (result == -1) + System.out.println( + "Element is not present in array"); + else + System.out.println("Element is present at " + + "index " + result); } } From b9b06afc2c6014e8cbff007992d34216c7e3ea3f Mon Sep 17 00:00:00 2001 From: NischalKothari Date: Thu, 28 Dec 2023 17:42:48 +0530 Subject: [PATCH 6/9] More Efficient Bubble Sort Code --- java-programs/BubbleSort.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/java-programs/BubbleSort.java b/java-programs/BubbleSort.java index 2f1ee8f..15b1d88 100644 --- a/java-programs/BubbleSort.java +++ b/java-programs/BubbleSort.java @@ -7,16 +7,22 @@ public class BubbleSort { public void bubbleSort(int[] arr) { + boolean swap; int n = arr.length; int tmp = 0; for (int i = 0; i < n ; i++) { - for (int j = 1; j < n-1; j++) { + swap = false; + for (int j = 1; j < n-i; j++) { if (arr[j-1] > arr[j]) { - tmp = arr[j - 1]; - arr[j-1] = arr[j]; - arr[j] = tmp; + tmp = arr[j]; + arr[j] = arr[j-1]; + arr[j-1] = tmp; + swap = true; } } + if (!swap){ + break; + } } } From 4ccb582c7204ca58bdbd0683a5ab463204fe2508 Mon Sep 17 00:00:00 2001 From: Anup Maharjan <52039155+Anup6452@users.noreply.github.com> Date: Tue, 6 Aug 2024 18:23:11 +0545 Subject: [PATCH 7/9] Remove duplicate question --- java-multiple-choice-questions-answers.md | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/java-multiple-choice-questions-answers.md b/java-multiple-choice-questions-answers.md index 9bb173c..33e86f6 100644 --- a/java-multiple-choice-questions-answers.md +++ b/java-multiple-choice-questions-answers.md @@ -41,6 +41,8 @@ D. int num1 = 0, num2 = 0; ``` A. double num1, int num2 = 0; ``` +**Explanation**: A. Option A does not compile because Java does not allow declaring different types as part of the same declaration. + ## Q. What is the output of following program? ```java public class Test { @@ -214,15 +216,6 @@ Output a : 2 J : 2 ``` -## Q. Which of the following declarations does not compile? -A. double num1, int num2 = 0; -B. int num1, num2; -C. int num1, num2 = 0; -D. int num1 = 0, num2 = 0; -``` -A. double num1, int num2 = 0; -``` -**Explanation**: A. Option A does not compile because Java does not allow declaring different types as part of the same declaration. ## Q. What is the output of the following? ```java From cd7bbb61f8f8a96de9710c6687f120c91d8275e7 Mon Sep 17 00:00:00 2001 From: Kaustubh Pandey <146510603+kautubh01@users.noreply.github.com> Date: Tue, 27 Aug 2024 22:35:11 +0530 Subject: [PATCH 8/9] Update BoundedTypesGenerics02.java --- core-java/basics/BoundedTypesGenerics02.java | 39 ++++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/core-java/basics/BoundedTypesGenerics02.java b/core-java/basics/BoundedTypesGenerics02.java index 7657f86..a1ad4e4 100644 --- a/core-java/basics/BoundedTypesGenerics02.java +++ b/core-java/basics/BoundedTypesGenerics02.java @@ -1,29 +1,28 @@ -package basics; - interface SampleInterface { - public void displayClass(); + void displayClass(); } + class BoundTest { - private T objRef; - public BoundTest(T obj) { - this.objRef = obj; - } - - public void doRunTest(){ - this.objRef.displayClass(); - } -} + private T objRef; + public BoundTest(T obj) { + this.objRef = obj; + } + + public void doRunTest() { + objRef.displayClass(); + } +} class SampleClass implements SampleInterface { - public void displayClass() { - System.out.println("Inside supper Class A"); - } + public void displayClass() { + System.out.println("Inside super Class A"); + } } -class BoundedTypesGenerics02 { - public static void main(String a[]) { - BoundTest b = new BoundTest<>(new SampleClass()); - b.doRunTest(); - } +public class BoundedTypesGenerics02 { + public static void main(String[] args) { + BoundTest b = new BoundTest<>(new SampleClass()); + b.doRunTest(); + } } From 968a729f2577549397f7ad75f0f3bb5ef79bf1c4 Mon Sep 17 00:00:00 2001 From: Kaustubh Pandey <146510603+kautubh01@users.noreply.github.com> Date: Tue, 27 Aug 2024 22:42:13 +0530 Subject: [PATCH 9/9] Update EnumConstructorExample.java --- core-java/basics/EnumConstructorExample.java | 25 +++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/core-java/basics/EnumConstructorExample.java b/core-java/basics/EnumConstructorExample.java index b3e0cfe..6600380 100644 --- a/core-java/basics/EnumConstructorExample.java +++ b/core-java/basics/EnumConstructorExample.java @@ -1,24 +1,21 @@ -package basics; - enum TrafficSignal { RED("STOP"), GREEN("GO"), ORANGE("SLOW DOWN"); - - private String action; - public String getAction() { - return this.action; - } - private TrafficSignal(String action) { + + private final String action; + + TrafficSignal(String action) { this.action = action; } + + public String getAction() { + return action; + } } -public class EnumConstructorExample { +public class EnumConstructorExample { public static void main(String[] args) { - - TrafficSignal[] signals = TrafficSignal.values(); - - for(TrafficSignal signal: signals){ - System.out.println("name: "+ signal.name() + " action: " + signal.getAction()); + for (TrafficSignal signal : TrafficSignal.values()) { + System.out.println("name: " + signal.name() + " action: " + signal.getAction()); } } }