Day 19 of Learning Java Continuing my Java journey! On Day 19, I learned about: ✅ Nested Classes in Java ✅ Static Nested Classes ✅ Inner Classes ✅ Local Classes ✅ Anonymous Classes 🔹 Nested Classes A class defined inside another class is called a nested class. It helps in better code organization and encapsulation. 🔹 Static Nested Class Declared using static keyword. Example: class Outer { static class Inner { } } It can be accessed without creating an object of the outer class. 🔹 Inner Class A non-static class inside another class. Example: class Outer { class Inner { } } It requires an object of the outer class. 🔹 Local Class A class defined inside a method. Example: void greet() { class Local { } } 🔹 Anonymous Class A class without a name, usually used for quick implementation of interfaces or abstract classes. special thanks to Aditya Tandon and Rohit Negi sir
Learning Java: Nested Classes and Inner Classes
More Relevant Posts
-
Day 18 of Learning Java Continuing my Java journey! On Day 18, I learned about: ✅ Autoboxing & Unboxing ✅ Abstract Classes (Rules & Concepts) ✅ POJO Classes ✅ Why only one public class per Java file 🔹 Autoboxing & Unboxing Autoboxing: Automatic conversion of primitive → Wrapper class Example: int a = 10; Integer obj = a; Unboxing: Wrapper class → primitive Example: Integer obj = 20; int a = obj; 🔹 Abstract Class (Important Points) • Cannot be instantiated directly • Can contain abstract methods (no body) • Can also contain normal methods • Can have constructors • Can have static methods and variables 🔹 POJO (Plain Old Java Object) A simple Java class that contains: • Private variables • Getter & Setter methods • Constructors Used mainly for data representation. 🔹 Why Only One Public Class Per Java File? Java allows only one public class per file to avoid ambiguity during compilation. The file name must match the public class name because the Java compiler uses that name to locate and compile the class. Example: public class Demo { } File name must be: Demo.java special thanks to Aditya Tandon and Rohit Negi sir
To view or add a comment, sign in
-
-
Day 24 of Learning Java Continuing my Java journey! On Day 24, I learned about: ✅ Interfaces in Java ✅ Interface vs Abstract Class ✅ Multiple Inheritance ✅ Default & Static Methods ✅ Functional & Marker Interfaces 🔹 What is an Interface? An interface defines a contract (what to do), not implementation. It represents behavior (can-do relationship). 🔹 Interface vs Abstract Class Interface: focuses on behavior (can-do) Abstract Class: focuses on hierarchy (is-a) 🔹 Variables in Interface All variables are by default: ✔ public ✔ static ✔ final (Used as constants) 🔹 Multiple Inheritance Java does not support multiple inheritance with classes, but it supports it using interfaces. A class can implement multiple interfaces. 🔹 Default & Static Methods Default Methods: Allow adding methods without breaking old code Static Methods: Belong to the interface, not objects 🔹 Functional Interface Interface with only one abstract method → Used in Lambda Expressions 🔹 Marker Interface Empty interface (no methods) → Used to provide special information to JVM Examples: Serializable, Cloneable,randomacess special thanks to Aditya Tandon and coder army sir
To view or add a comment, sign in
-
-
🚀 Starting My Java Learning Journey – Day 14 🔹 Topic: Final Keyword & Static Keyword in Java In Java, final and static are important keywords used to control behavior of variables, methods, and classes. ✅ Final Keyword The final keyword is used to restrict modification. ✔ final variable → value cannot be changed ✔ final method → cannot be overridden ✔ final class → cannot be inherited ✅ Static Keyword The static keyword is used for memory management and sharing data. ✔ Belongs to the class, not objects. ✔ Shared among all objects. ✔ Can be accessed without creating an object. 💡 Key Points: ✔ final → restricts changes ✔ static → shared among all objects #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #JavaFinal #JavaStatic
To view or add a comment, sign in
-
🚀 Day 7 of My Java Learning Journey Today I learned about Control Flow Statements in Java, focusing on Conditional Statements. 📌 These statements help control the flow of execution based on conditions. 🔹 Types of Conditional Statements I Covered: 🔸 1. if Statement Executes code only if condition is true 🔸 2. if-else Statement Executes one block if true, another if false 🔸 3. else-if Ladder Used to check multiple conditions 🔸 4. Nested if if statement inside another if 💡 Example: int marks = 75; if(marks >= 80){ System.out.println("Excellent"); } else if(marks >= 50){ System.out.println("Pass"); } else { System.out.println("Fail"); } Understanding these concepts is very important for building logic in real-world applications. Building consistency step by step 💪 🔗 Check my code here: https://lnkd.in/gDP4A9r6 If you are also learning Java, let’s connect and grow together 🤝 #Java #JavaDeveloper #Programming #CodingJourney #LearningInPublic #SoftwareDevelopment
To view or add a comment, sign in
-
-
Day 9 – Java Learning Journey Today I continued strengthening my Java fundamentals, focusing on method overriding and important rules in inheritance. Key concepts I explored: • Method Overriding Rules in Java The child class method must have the same method signature as the parent class method. The return type must be the same or covariant (a subclass of the parent return type). The method cannot be static, because static methods belong to the class rather than the object. • Covariant Return Types Java allows a child class method to return a more specific type than the parent class method, making inheritance more flexible. • Static vs Instance Methods I also learned why static methods cannot be overridden and are instead method hidden, which behaves differently from runtime polymorphism. Step by step, continuing to build a stronger foundation in Core Java and OOP concepts. 🚀 #Java #CoreJava #OOP #MethodOverriding #Programming #SoftwareDevelopment #LearningJourney
To view or add a comment, sign in
-
🚀 Day 18/45 – Understanding Packages in Java On Day 18 of my Java learning journey, I explored the concept of Packages, which help organize classes and manage large projects efficiently. Packages act like folders that group related classes together, making code more structured and easier to maintain. 📚 What I Learned Today Today I learned: ✔ What packages are and why they are used ✔ How to create user-defined packages ✔ Folder structure of packages ✔ Using the import keyword to access classes 💻 Practice Work To apply my learning, I implemented: • A simple program inside a custom package • A program using Scanner with import statement 🎯 Key Takeaway Packages are essential for organizing code in real-world applications. They improve readability, maintainability, and scalability of programs.Learning how to structure code properly is an important step toward becoming a better developer. #Java #Programming #LearningInPublic #CodingJourney #SoftwareDevelopment #OOP
To view or add a comment, sign in
-
🚀 Starting My Java Learning Journey – Day 8 🔹 Topic: Methods in Java A method is a block of code that performs a specific task. Methods help make programs organized, reusable, and easier to read. returnType – type of value the method returns (use void if it returns nothing) methodName – name of the method parameters – input values the method takes 📌 Example Program public class Main { // Method to add two numbers static int addNumbers(int a, int b) { return a + b; } public static void main(String[] args) { int sum = addNumbers(10, 20); System.out.println("Sum: " + sum); } } Output: Sum: 30 💡 Key Points: Methods avoid code repetition Methods can take inputs (parameters) and return outputs Helps in modular programming #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #JavaMethods
To view or add a comment, sign in
-
🚀 Learning Java – Understanding the Static Keyword Today I completed the "Static" concept in Java on TAP Academy. In Java, the keyword static is used for variables, methods, blocks, and nested classes. It means the member belongs to the class, not to individual objects. 1️⃣ Static Variable (Class Variable) A variable declared with static is shared by all objects of the class. Only one copy exists in memory. 2️⃣ Static Method A method declared as static can be called without creating an object. It can only directly access static variables and static methods. 3️⃣ Static Block Used for initializing static variables. It runs only once when the class is loaded. 4️⃣ Static Nested Class A class declared inside another class with static. It can access only static members of the outer class. #Java #Programming #Learning #TAPAcademy #SoftwareDevelopment #BTechStudent
To view or add a comment, sign in
-
-
Boost Your Java Skills with This Quick Tutorial! Are you learning Java or looking to sharpen your programming skills? Check out my latest video on Nested do while loop! In this video, you will learn: ✅ The basics of Nested do while loop ✅ How to write clean and efficient code ✅ Real-world examples and practical use cases ✅ Tips to avoid common mistakes Whether you are a beginner, a student, or an aspiring Java developer, this tutorial will make easy to understand and implement. 📺 Watch here: https://lnkd.in/gR-N6HbQ 💡 Don’t forget to like, share, and comment your thoughts! Your feedback helps me create more useful tutorials. #Java #JavaProgramming #Coding #LearnJava #Programming #SoftwareDevelopment #TechTips #JavaForBeginners
Nested Do While Loop in Java | Simple Explanation with Examples
https://www.youtube.com/
To view or add a comment, sign in
-
🚀 Starting My Java Learning Journey – Day 9 🔹 Topic: Method Overloading in Java Method Overloading is a feature in Java that allows a class to have multiple methods with the same name but different parameters. It helps improve code readability and flexibility. 📌 Ways to Achieve Method Overloading 1️⃣ Different number of parameters 2️⃣ Different data types of parameters 📌 Example Program public class Main { // Method with two int parameters static int add(int a, int b) { return a + b; } // Method with three int parameters static int add(int a, int b, int c) { return a + b + c; } public static void main(String[] args) { System.out.println(add(5, 10)); System.out.println(add(5, 10, 15)); } } Output: 15 30 💡 Key Points: ✔ Method overloading allows multiple methods with the same name ✔ Methods must differ in number or type of parameters ✔ Helps make programs more flexible and readable #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #MethodOverloading
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
well done, keep going.🔥