🚀 Day 15 of Learning Java Full Stack Development — Abstract Classes & Abstract Methods in Java 👋 Hello Everyone! Today marks another exciting milestone in my Java learning journey! I explored one of the most important concepts in Object-Oriented Programming (OOP) — Abstract Classes & Abstract Methods in Java. ➤ Abstract Class: An abstract class in Java is a special type of class that is declared using the abstract keyword. In Java, a class is called an abstract class if it contains at least one abstract method. ➤ Abstract Method: An abstract method is a method that is declared without a body — meaning it only contains the method name and signature, but no implementation. It is defined using the abstract keyword and must be declared inside an abstract class or an interface. 👉 Simply put, an abstract class acts as a blueprint for its subclasses. It defines what needs to be done, but leaves the “how” part to the subclasses that extend it. ✅ Example: abstract class Example { void display() { // concrete method System.out.println("Hello"); } abstract void show(); // abstract method } In the above example: ● display() is a concrete method because it contains an implementation. ● show() is an abstract method because it has no body. ● Since the class contains at least one abstract method, it becomes an abstract class. 👉 Note : An abstract class cannot be instantiated directly” means that you cannot create an object of an abstract class using the new keyword. Instead, you must inherit it in a subclass and then create an object of that subclass. ✅Example: abstract class Vehicle { abstract void start(); // Abstract method (no body) void stop() { // Concrete method System.out.println("Vehicle stopped."); } } class Car extends Vehicle { void start() { System.out.println("Car started with a key."); } } public class Main { public static void main(String[] args) { // Vehicle v = new Vehicle(); ❌ Not allowed Car car = new Car(); // ✅ Allowed car.start(); car.stop(); } } 🌟Key Takeaways ✔️ An abstract method is declared without a method body. ✔️ An abstract class can have both abstract and concrete methods (methods with definitions). ✔️ Subclasses must implement all abstract methods. ✔️ Objects cannot be created directly for abstract classes. 🔥 Abstract classes help make Java programs more organized, easier to maintain, and more scalable by promoting clean code and proper object-oriented design. I’m one step closer to mastering the OOP concepts that form the foundation of Java Full Stack Development. #Java #OOPsConcepts #AbstractClass #Inheritance #Encapsulation #LearningJourney #JavaDeveloper #BackendDevelopment #JavaFullStackDevelopment #FullStackDeveloper #JavaProgramming #Day15 #LearningNeverStops #SoftwareEngineering #LearnJava #JavaDeveloper #CleanCode #ProgrammingConcepts
Learning Java: Abstract Classes & Methods Explained
More Relevant Posts
-
🚀 Day 23 | Learning Java Full Stack Development: Multithreading in Java 🧵 Multithreading in Java is a process of executing two or more threads simultaneously to achieve concurrent execution of tasks. It improves application performance by efficiently utilizing CPU resources. Each thread runs independently while sharing the same memory, making programs faster and more responsive, especially for complex or long-running tasks. In a system, the OS handles multiple tasks sequentially or concurrently — a concept called Multitasking, divided into two types. 👇 1️⃣ Process-Based Multitasking Process-based multitasking, also known as heavyweight processing, allows multiple programs to run simultaneously, each with its own memory and resources — for example, using Word, a browser, and a music player at the same time. 2️⃣ Thread-Based Multitasking Here, multiple tasks (threads) run within a single process, sharing the same memory and resources. This makes it more efficient and lightweight — hence known as Lightweight Processing. 👉 Thread: A thread represents an independent execution path, allowing Java to run multiple threads concurrently for better performance. 🏗️ How to Create a Thread in Java: ➠ There are two main ways to create threads in Java 1️⃣ By extending Thread class class MyThread extends Thread { public void run() { // thread logic here } } public class Main { public static void main(String[] args) { MyThread t = new MyThread(); t.start(); // starts the thread } } 2️⃣ By Implementing the Runnable Interface class MyRunnable implements Runnable { public void run() { System.out.println("Runnable thread is running..."); } } public class Main { public static void main(String[] args) { Thread t = new Thread(new MyRunnable()); t.start(); } } 👉 Remember: Calling start() automatically invokes the run() method in a new thread, while calling run() directly executes it in the main thread. ⚙️Thread Operations and Methods Threads can be controlled, paused, or prioritized using built-in methods in the Thread class. 1. sleep(long millis) : Temporarily pauses the thread for a specified time (in milliseconds). 2. join(): Ensures one thread waits for another to complete before continuing. 3. setPriority(int newPriority): Sets the priority of a thread between 1 (lowest) and 10 (highest). ● Thread.MIN_PRIORITY (1) ● Thread.NORM_PRIORITY (5 - default) ● Thread.MAX_PRIORITY (10) 👉 Threads with higher priority are scheduled before lower-priority threads. 4. setDaemon(true): Converts a user thread into a daemon thread (a background or service thread). 💼 Thread Groups: In Java, a Thread Group is a way to organize and manage multiple threads together as a single unit. 🔜 Next Up : Thread Lifecycle & States in Java #Day22 #JavaLearningJourney #Multithreading #JavaThreads #FullStackDevelopment #JavaProgramming #BackendDevelopment #Concurrency #Threading #CodingCommunity #JavaDeveloper #LearningInPublic #CodeEveryday #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Java Learning Just Got a Whole Lot Easier! 🚀🎯✍🏻 By~ Utkrisht Patel 🤯 Warning: May Cause Extreme Java Understanding! 🤯 Fellow coders, stop scrolling! I'm excited to share my #handwritten, self-designed Java PDF, crafted for quick, powerful🔥 30-minute revision! 🧠✍️ I poured my energy into making Java concepts not just understandable, but genuinely engaging. This isn't your average study guide; it's a single-document resource packed with everything you need. What makes this PDF unique?😊 🎨 Visual Learning: Concepts are broken down with funny and helpful #diagrams and illustrations (like the OOP examples on objects and classes) to simplify complex ideas. 💻 Code & Clarity: Includes clear code snippets and anatomical explanations of core structures, like the main method, so you know exactly what each part does. 💡 Quick Revision Focused: Designed to cover all key doubts and fundamental concepts swiftly—from WORA (Write Once, Run Anywhere) and the JVM to OOP Principles, Exceptions, and Multithreading. 🧩 All-in-One: Covers an extensive range of topics including: 📌Java Basics, History, and Flavors (J2SE, J2EE, J2ME) 📌Data Types, Variables, and Literals Operators (Assignment, Arithmetic, Unary, Relational, Logical) 📌Control Structures (Loops: while, do-while, for, for-each, and switch) 📌Methods, Arrays (1D and 2D), and Recursion 📌Object-Oriented Concepts (Class vs. Object, Encapsulation, Inheritance, Polymorphism, Abstraction) 📌Keywords (this, super, static, etc.) and Constructors 📌Exceptions (throw vs. throws, Custom Exceptions) 📌Autoboxing and Unboxing 📌Multithreading and Thread States 🫶🏻 Huge thanks to the community for the continuous support! I write with full energy and hope this gives your Java learning a major boost! 💪🎯 👀Let me know what you think of this approach! 👇 GitHub Link: https://lnkd.in/dfBmTVGt #Java #Programming #Notes #QuickRevision #Code #OOP #SoftwareDevelopment #Tech #Learning #UtkrishtPatel Utkrisht Patel Gautam Buddha University GBU USICT TRAINING & PLACEMENT CELL USICT GBU Department of Computer Science and Engineering (DCSE) /USICT/GBU USICT Placement In-Charge
To view or add a comment, sign in
-
🔜 🚀 Day 13 of Learning java 💡 OOPs Concepts in Java Object-Oriented Programming (OOPs) is the foundation of Java. It helps us write cleaner, modular, and reusable code. 🧩 Here are the 4 main pillars of OOPs 👇 ✨ Why OOPs? ✅ Better code reusability ✅ Improved security ✅ Easier maintenance ✅ Real-world modeling 1. 🔒 Encapsulation Encapsulation means wrapping data (variables) and methods (functions) that operate on that data into a single unit — called a class. It’s like putting data and behavior inside a capsule 💊 to protect it from outside interference. Key idea: Data is hidden using private variables. Access is given through public getter and setter methods. Example: class Account { private double balance; // data hidden // getter method public double getBalance() { return balance; } // setter method public void setBalance(double balance) { if (balance > 0) this.balance = balance; } } Benefits: ✅ Data protection ✅ Controlled access ✅ Improved code security 2. 🧬 Inheritance Inheritance allows one class to inherit the properties (fields) and behaviors (methods) of another class. This helps promote code reusability and establish a parent-child relationship between classes. Syntax: class ChildClass extends ParentClass { } Example: class Animal { void eat() { System.out.println("Eating..."); } } class Dog extends Animal { void bark() { System.out.println("Barking..."); } } Explanation: Dog inherits eat() from Animal. You can now reuse code instead of writing it again. Benefits: ✅ Code reuse ✅ Easier maintenance ✅ Logical class hierarchy 3. 🎭 Polymorphism Polymorphism means “many forms.” It allows methods to behave differently based on the object that’s calling them. There are two types: Compile-time Polymorphism (Method Overloading) Runtime Polymorphism (Method Overriding) Example of Overriding (Runtime Polymorphism): class Shape { void draw() { System.out.println("Drawing a shape"); } } class Circle extends Shape { void draw() { System.out.println("Drawing a circle"); } } Output: Drawing a circle Explanation: Even though both classes have draw(), the method in the child class is executed at runtime. Benefits: ✅ Flexibility in code ✅ Easy to extend functionality ✅ Supports dynamic behavior 4. 👻 Abstraction Abstraction means hiding complex implementation details and showing only what’s necessary. It focuses on what an object does instead of how it does it. In Java, abstraction is achieved through: Abstract classes (abstract keyword) Interfaces Example: abstract class Animal { abstract void sound(); // abstract } class Dog extends Animal { void sound() { System.out.println("Barks"); } } Explanation: The abstract class Animal defines a concept (sound()), But the subclass Dog provides the specific implementation. Benefits: ✅ Reduces complexity ✅ Increases flexibility
To view or add a comment, sign in
-
-
🚀 Day 24 of Learning Java Full Stack Development – Multithreading Life Cycle & States in Java 🧩 What is a Thread Life Cycle? A thread life cycle represents the complete journey of a thread — from the moment it is created, to the point it finishes its task and dies. Java defines several states that a thread can be in at any given time, managed automatically by the JVM (Java Virtual Machine). 👉 By understanding these states, you can build efficient, responsive, and well-synchronized multithreaded applications. 🌀 Thread Life Cycle States in Java Java defines five major thread states as part of its life cycle: 1️⃣ New (Born State): The thread is created but not yet started. 2️⃣ Runnable (Ready to Run): The thread is ready to run and waiting for CPU time. 3️⃣ Running (Active State): The thread is executing its run() method. 4️⃣ Blocked / Waiting (Paused State): A thread enters the waiting state when it becomes temporarily inactive using methods like sleep(), wait(), or join(), while waiting for another thread to finish or release a resource. 5️⃣ Terminated (Dead State): Once the run() method finishes execution or the thread is stopped, it enters the terminated state. 🔁 State Transitions Simplified Here’s how threads typically move between states: New → start() → Runnable → Running → Waiting/Blocked → Runnable → Terminated 💻 Complete Example: class MyThread extends Thread { public void run() { System.out.println("Thread is running..."); try { Thread.sleep(2000); // Thread enters waiting state } catch (InterruptedException e) { System.out.println("Thread interrupted..."); } System.out.println("Thread has finished execution."); } } public class ThreadLifeCycleExample { public static void main(String[] args) { MyThread t = new MyThread(); // New System.out.println("Thread State after creation: " + t.getState()); t.start(); // Runnable → Running System.out.println("Thread State after start: " + t.getState()); } } ✅ Output Thread State after creation: NEW Thread State after start: RUNNABLE Thread is running... Thread has finished execution. 🌟 Today’s key lesson: mastering concurrency is about writing faster and more reliable code while maintaining control over execution flow. Java’s multithreading model simplifies this powerfully yet elegantly. 🔜 Excited to continue exploring synchronization next! #Day24 #JavaLearning #Multithreading #ThreadLifeCycle #FullStackDevelopment #JavaDeveloper #JavaThreads #ProgrammingJourney #LearningEveryday #SoftwareEngineer #BackendDevelopment #Concurrency #JavaFundamentals #TechLearning #DevelopersJourney #JavaCommunity #CodingPractice #ThreadManagement #JavaSkills #JavaProgramming #DailyLExample
To view or add a comment, sign in
-
-
🚀 Day 26 | Learning Java Full Stack Development – Garbage Collection in Java 🧹 What is Garbage Collection? In simple terms, Garbage Collection is the process of automatically freeing up memory by removing unused or unreachable objects from the heap area. When we create objects in Java using the new keyword, they’re stored in heap memory. Over time, if some objects are no longer referenced, they occupy space unnecessarily — that’s where the Garbage Collector steps in. It identifies such unused objects and reclaims that memory space, ensuring the system has enough memory for new objects to be created. Unlike languages like C or C++, where we need to explicitly use free() or delete(), Java automates this process, making it safer and less error-prone. ⚙️How Does It Work? The JVM (Java Virtual Machine) runs a background process known as the Garbage Collector (GC). The GC tracks which objects are being used and which are not. Once it finds an object that has no active references, it marks it as “eligible for garbage collection” and eventually removes it to reclaim memory. 👉 The GC algorithm generally follows these steps: ● Mark: Identify which objects are still in use (reachable). ● Sweep: Remove objects that are no longer referenced. ● Compact: Rearrange remaining objects to optimize memory space. 💡Key Points to Remember ● Java developers cannot explicitly destroy objects — only the GC can do that. ● You can suggest GC execution using System.gc(), but it’s not guaranteed to run immediately. ● Objects become eligible for GC when they are no longer referenced. ● The finalize() method runs before GC deletes an object but is now deprecated and discouraged. ● GC improves performance and stability by preventing memory leaks and fragmentation. 🧰 Types of Garbage Collectors in Java ● Serial GC – Best for single-threaded applications. ● Parallel GC – Uses multiple threads for better performance. ● G1 GC (Garbage-First) – Designed for low-latency and large heap memory. ● ZGC / Shenandoah GC – Focused on ultra-low pause times. ✅ Example : class GarbageCollectorExample { public static void main(String[] args) { GarbageCollectorExample obj = new GarbageCollectorExample(); obj = null; // Now the object is unreachable System.gc(); // Requesting JVM to run Garbage Collector System.out.println("End of main method"); } protected void finalize() { System.out.println("Garbage Collector called and object destroyed"); } } 🟢 Output : End of main method Garbage Collector called and object destroyed 👉 This shows that when an object becomes unreachable, the GC reclaims it and runs its finalize() method before deletion. ✨ Learning about Garbage Collection showed me how smartly the JVM manages memory — like a personal assistant quietly keeping things clean while I focus on coding!🧹 #Day26 #JavaFullStackDevelopment #GarbageCollection #JVM #JavaLearning #MemoryManagement #JavaPerformance #CodingJourney #DeveloperCommunity #KeepLearning #Java #JavaTips
To view or add a comment, sign in
-
-
My Java Learning Journey: From Confusion to Clarity 🚀 From “Hello World” to Building Real Programs in Java — What a Journey It’s Been! A few months ago, I opened my IDE, stared at that blinking cursor, and typed: System.out.println("Hello World"); That single line felt magical. But what followed was far from easy. At first, Java felt like a puzzle made of thousands of tiny moving pieces. Every time I thought I’d understood something, a new concept would appear out of nowhere — classes, methods, data types, or those mysterious curly braces that somehow decided whether my code lived or died. 😅 There were nights when I sat staring at my screen for hours, unable to figure out a single error. I remember running a program 10 times only to realize I had missed a single semicolon. It was frustrating. But every small win — like fixing that one bug or getting a program to finally run — felt like a victory worth celebrating. Over time, I started connecting the dots. ✨ I understood how Java actually works — how JDK, JRE, and JVM fit together. ✨ I practiced loops, arrays, and conditionals until they became second nature. ✨ I explored Object-Oriented Programming — building real classes, constructors, and understanding inheritance and polymorphism. ✨ I even went deep into concepts like static methods, encapsulation, the ‘this’ and ‘super’ keywords, and upcasting/downcasting. Little by little, things began to make sense. What once looked complicated started to feel logical. That’s when I realized: learning to code is less about intelligence, and more about consistency, patience, and curiosity. The biggest lesson I’ve learned? ➡️ Coding teaches you how to think. It’s not just about syntax or logic — it’s about learning to break problems down, stay calm when things break, and find your own solutions. I’m now confident enough to read, understand, and write Java programs on my own. And this is just the beginning. Next up on my roadmap: Exception Handling, File I/O, and the Java Collections Framework — the tools that will help me build real-world projects. If you’re also learning Java or any programming language — keep going. There will be confusion, frustration, and doubt. But if you stay consistent, that moment when your code finally runs successfully will make it all worth it. To all the learners out there: your effort matters. Every small concept you understand today is building the foundation for something bigger tomorrow. Let’s keep learning, keep coding, and keep growing — one line of code at a time. 💪 #Java #LearningJourney #CodingLife #Programming #StudentDeveloper #CodeNewbie #SelfGrowth #TechJourney #Motivation #JavaDeveloper #Consistency
To view or add a comment, sign in
-
#Day43 of my Java learning Journey....... 🎯 Topic : Encapsulation!! Encapsulation in Java is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit. In encapsulation, the variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class. Therefore, it is also known as data hiding. ✅ To achieve encapsulation in Java − --> Declare the variables of a class as private. --> Provide public setter and getter methods to modify and view the variables values. ✅ Why Encapsulation? --> Better control of class attributes and methods. --> Class attributes can be made read-only (if you only use the get() method), or write-only (if you only use the set() method). --> Flexible: the programmer can change one part of the code without affecting other parts. --> Increased security of data. 📚 Creating Read-Only Class : // Class "Person" class Person { private String name = "Jonh"; private int age = 21; // Getter methods public String getName() { return this.name; } public int getAge() { return this.age; } } public class Main { public static void main(String args[]) { // Object to Person class Person p = new Person(); // Getting and printing the values System.out.println(p.getName()); System.out.println(p.getAge()); } } Output : John 21 📚 Creating Write-Only Class : // Class "Person" class Person { private String name; private int age; // Setter Methods public void setName(String name) { this.name = name; } public void setAge(int age) { this.age = age; } } public class Main { public static void main(String args[]) { // Object to Person class Person p = new Person(); // Setting the values p.setName("John"); p.setAge(21); } } ✅ Best Practices for Encapsulation --> Always give the most restrictive access level that still allows the code to work. This helps hide implementation details and reduces coupling. --> Expose data through methods (getters/setters) rather than making fields public. This gives more control (validation, lazy initialization, invariants, etc.). --> Use validation logic inside setters to ensure correct data. --> Avoid unnecessary setters if data should not be modified externally (e.g., IDs). 10000 Coders Gurugubelli Vijaya Kumar #Java #OOP #Encapsulation #ObjectOrientedProgramming #ProgrammingConcepts #SoftwareDevelopment #CleanCode #LearnJava #CodingBasics #TechLearning #JavaTips
To view or add a comment, sign in
-
#Day42 of my Java Learning Journey...... 🎯 Topic : Constructor in Java!! A constructor is a special method that initializes an object and is automatically called when a class instance is created using new. It is used to set default or user-defined values for the object's attributes * A constructor has the same name as the class. * It does not have a return type, not even void. * It can accept parameters to initialize object properties. ✅ Types of Java Constructors There are three different types of constructors in Java, we have listed them as follows: --> Default Constructor --> No-Parameterized Constructor --> Parameterized Constructor 1. Default Constructor : If you do not create any constructor in the class, Java provides a default constructor that initializes the object. 📚 Example : int num1; int num2; public static void main(String[] args) { // We didn't created any structure // a default constructor will invoke here Main s = new Main(); // Printing the values System.out.println("num1 : " + s.num1); System.out.println("num2 : " + s.num2); } } Output num1 : 0 num2 : 0 2. No-Parameterized / No-args Constructor : 📚 Example : public class Main { int num1; int num2; // Creating no-args constructor Main() { num1 = -1; num2 = -1; } public static void main(String[] args) { // no-args constructor will invoke Main s = new Main(); // Printing the values System.out.println("num1 : " + s.num1); System.out.println("num2 : " + s.num2); } } Output num1 : -1 num2 : -1 3. Parameterized Constructor A constructor with one or more arguments is called a parameterized constructor. 📚 Example : public class Main { int num1; int num2; // Creating parameterized constructor Main(int a, int b) { num1 = a; num2 = b; } public static void main(String[] args) { // Creating two objects by passing the values // to initialize the attributes. // parameterized constructor will invoke Main x = new Main(10, 20); Main y = new Main(100, 200); // Printing the objects values System.out.println("x"); System.out.println("num1 : " + x.num1); System.out.println("num2 : " + x.num2); System.out.println("y"); System.out.println("num1 : " + y.num1); System.out.println("num2 : " + y.num2); } } Output x num1 : 10 num2 : 20 y num1 : 100 num2 : 200 ✅ Note that the constructor name must match the class name, and it cannot have a return type (like void). Also note that the constructor is called when the object is created. All classes have constructors by default: if you do not create a class constructor yourself, Java creates one for you. However, then you are not able to set initial values for object attributes. 10000 Coders Gurugubelli Vijaya Kumar #Java #LearnJava #TechLearning #ObjectOrientedProgramming #Coding #SoftwareDevelopment #DeveloperCommunity #100DaysOfCode #JavaBasics #CodeNewbie
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
👉 Example Code : https://github.com/nagu-mulampaka/Java-practice