From e0d1a006bc1b24185140316e929bd10bcdfa31b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9C=5Bgithub=5D=E2=80=9D?= Date: Wed, 1 Oct 2025 23:03:24 +0530 Subject: [PATCH 1/4] Added do-while loop documentation in loop section --- content/java/concepts/loops/loops.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/content/java/concepts/loops/loops.md b/content/java/concepts/loops/loops.md index 101d72d41ce..d1ae788cfc8 100644 --- a/content/java/concepts/loops/loops.md +++ b/content/java/concepts/loops/loops.md @@ -43,6 +43,33 @@ The output would be: 8 ``` +## Do-While Loop + +The `do-while` loop is similar to a `while` loop, but the code block **executes at least once**, even if the condition is false. This makes it useful when you want the loop to run **at least one time** before checking the condition. + +```pseudo +do { + // Code block to be executed +} while (condition); +``` +In this example, the code in the loop will run at least once, and then continue running as long as variable i is less than 10: + +```java +int i = 5; + +do { + System.out.println(i); + i++; +} while (i < 0); + +``` + +The output would be: +```shell +5 +``` + + ## For Loop A `for` loop iterates over a range of values. Its declaration is made up of the following three parts, each separated by a semicolon: From a2a4d213d739caa12a0bdefbf060c61261f09172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9C=5Bgithub=5D=E2=80=9D?= Date: Wed, 1 Oct 2025 23:23:00 +0530 Subject: [PATCH 2/4] Fix markdownlint errors in loops.md --- content/java/concepts/loops/loops.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content/java/concepts/loops/loops.md b/content/java/concepts/loops/loops.md index d1ae788cfc8..5b0e7e17929 100644 --- a/content/java/concepts/loops/loops.md +++ b/content/java/concepts/loops/loops.md @@ -52,6 +52,7 @@ do { // Code block to be executed } while (condition); ``` + In this example, the code in the loop will run at least once, and then continue running as long as variable i is less than 10: ```java @@ -65,11 +66,11 @@ do { ``` The output would be: + ```shell 5 ``` - ## For Loop A `for` loop iterates over a range of values. Its declaration is made up of the following three parts, each separated by a semicolon: From c8c3ff4c088e4a0aa1c06e1283a96b54f4c88d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9C=5Bgithub=5D=E2=80=9D?= Date: Thu, 2 Oct 2025 22:35:14 +0530 Subject: [PATCH 3/4] Add folder in concepts section of Java named as Access Modifiers --- .../access-modifiers/access-modifiers.md | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 content/java/concepts/access-modifiers/access-modifiers.md diff --git a/content/java/concepts/access-modifiers/access-modifiers.md b/content/java/concepts/access-modifiers/access-modifiers.md new file mode 100644 index 00000000000..0fafb1264e2 --- /dev/null +++ b/content/java/concepts/access-modifiers/access-modifiers.md @@ -0,0 +1,54 @@ +--- +Title: 'Access Modifiers' +Description: 'In Java, access modifiers control who can access classes, methods, or variables, helping protect data and enforce encapsulation. They allow you to hide details, share functionality safely, and organize code for better maintenance.' +Subject: + - 'Computer Science' +Tags: + - 'Access-Modifiers' + - 'OOP' +CatalogContent: + - 'learn-java' + - 'paths/computer-science' +--- + +# Java Access Modifiers + +In Java, **access modifiers** control **who can use a class, method, or variable**. +They are important for **data protection**, **encapsulation**, and **safe code design**. + +There are **four types of access modifiers**: + + +## 1. Public + + - `public` is visible to everyone – inside or outside the package. + - Use it when a class or method should be accessible by any other class. + - Think of it as **“open for all”**. + + +## 2. Private + - `private` is visible only within the same class. + - Use it to hide data or methods from other classes. + - Helps protect your data and enforce encapsulation. + + +## 3. Protected + - `protected` is visible within the same package and to subclasses in other packages. + - Use it when you want to share functionality with child classes but not everyone. + - Useful in inheritance scenarios. + + +## 4. Default (Package-Private) + - Default (no modifier) is visible only within the same package. + - Use it for internal package-level access that should not be exposed outside. + - Helps organize related classes without exposing them publicly. + + +# Comparison Table + +| Modifier | Inside Class | Same Package | Subclass (Other Package) | Other Packages | +|--------------|-------------------|-------------------|-----------------------------------|--------------------------| +| **public** | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | +| **private** | ✅ Yes | ❌ No | ❌ No | ❌ No | +| **protected** | ✅ Yes | ✅ Yes | ✅ Yes | ❌ No | +| **default** | ✅ Yes | ✅ Yes | ❌ No | ❌ No | From 779a04a660f69f2da4ce9a4196db227e4e267f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9C=5Bgithub=5D=E2=80=9D?= Date: Thu, 2 Oct 2025 22:51:41 +0530 Subject: [PATCH 4/4] Fix markdown formatting and frontmatter for access-modifiers.md --- .../access-modifiers/access-modifiers.md | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/content/java/concepts/access-modifiers/access-modifiers.md b/content/java/concepts/access-modifiers/access-modifiers.md index 0fafb1264e2..88661af0914 100644 --- a/content/java/concepts/access-modifiers/access-modifiers.md +++ b/content/java/concepts/access-modifiers/access-modifiers.md @@ -1,19 +1,19 @@ ---- +--- Title: 'Access Modifiers' Description: 'In Java, access modifiers control who can access classes, methods, or variables, helping protect data and enforce encapsulation. They allow you to hide details, share functionality safely, and organize code for better maintenance.' Subject: - - 'Computer Science' + - 'Computer Science' Tags: - - 'Access-Modifiers' - - 'OOP' + - 'Access-Modifiers' + - 'OOP' CatalogContent: - - 'learn-java' - - 'paths/computer-science' + - 'learn-java' + - 'paths/computer-science' --- # Java Access Modifiers -In Java, **access modifiers** control **who can use a class, method, or variable**. +In Java, **access modifiers** control **who can use a class, method, or variable**. They are important for **data protection**, **encapsulation**, and **safe code design**. There are **four types of access modifiers**: @@ -21,30 +21,33 @@ There are **four types of access modifiers**: ## 1. Public - - `public` is visible to everyone – inside or outside the package. - - Use it when a class or method should be accessible by any other class. - - Think of it as **“open for all”**. +- `public` is visible to everyone – inside or outside the package. +- Use it when a class or method should be accessible by any other class. +- Think of it as **“open for all”**. ## 2. Private - - `private` is visible only within the same class. - - Use it to hide data or methods from other classes. - - Helps protect your data and enforce encapsulation. + +- `private` is visible only within the same class. +- Use it to hide data or methods from other classes. +- Helps protect your data and enforce encapsulation. ## 3. Protected - - `protected` is visible within the same package and to subclasses in other packages. - - Use it when you want to share functionality with child classes but not everyone. - - Useful in inheritance scenarios. + +- `protected` is visible within the same package and to subclasses in other packages. +- Use it when you want to share functionality with child classes but not everyone. +- Useful in inheritance scenarios. ## 4. Default (Package-Private) - - Default (no modifier) is visible only within the same package. - - Use it for internal package-level access that should not be exposed outside. - - Helps organize related classes without exposing them publicly. + +- Default (no modifier) is visible only within the same package. +- Use it for internal package-level access that should not be exposed outside. +- Helps organize related classes without exposing them publicly. -# Comparison Table +## Comparison Table | Modifier | Inside Class | Same Package | Subclass (Other Package) | Other Packages | |--------------|-------------------|-------------------|-----------------------------------|--------------------------|