Day 58/200 - Java Learning Journey 🌱 ✨ Sharing what I learned today in Java. 📚 Today I learned about Encapsulation in Java Today's Topic: Encapsulation ✴️ Encapsulation: 👉 It means wrapping(hiding) the data (variables,methods) and providing the controlled access. 🔯 Advantages/Features: 🔺 Security 🔺 Hiding the data 🔺 Controlled access 🔺 Validation 🔺 Flexibility 🔆 How to hide the data ❓ ▪️ By making those variables,methods to be private. 1️⃣ Setters: 👉 These are used to set the data. 2️⃣ Getters: 👉 Get or return the data. 🔸 Syntax: For setters: access_modifier returntype(void) settersName(){ -------------//data } For getters: access_modifier returntype gettersName(){ return value; } 💠 Without setters we cant use getters. 💠 Without getters we can set the value by using setters. 👎 Drawback: 👉 In Encapsulation for each and every variables we need to use setters to set the value to those variables. #Java#Encapsulation#OOPS#DailyLearning#Consistency#Meghana M#10000 Coders#
Java Encapsulation Basics
More Relevant Posts
-
Day 40 of Learning Java: Method Overloading Instead of creating different method names for similar tasks, we can use the same method name but change the parameters — and Java figures out which one to call. -So what exactly is Method Overloading? It’s when multiple methods in the same class have: ✔ Same name ✔ Different parameter list That’s it. Simple idea, but very powerful. -Ways to overload a method • Change the type of parameters • Change the number of parameters • Change the order of parameters Example- Think of a login system: Login using username + password Login using mobile + password Both are login actions, right? So instead of writing different method names, we just overload: login(String username, String password) login(long mobile, String password) Same method name → different ways to use it -Another relatable one Payment systems 👇 COD UPI Card Net Banking Instead of: paymentByUPI(), paymentByCard()… We can just do: payment() payment(String upi) payment(long card) payment(String user, String pass) - Important things I learned • Just changing return type won’t work (it gives error) • Overloading happens at compile time • Works with static, private, and even final methods • Yes, even main() can be overloaded (but JVM only runs the standard one) #Java #LearningInPublic #100DaysOfCode #Programming #OOP #CodingJourney
To view or add a comment, sign in
-
-
🚀 Core Java Learning Journey Explored Variables in Java ☕ 🔹 What is a Variable? A variable is a container used to store data values in a program. Each variable has a name, type, and value. 📌 Types of Variables in Java: ✅ Local Variables - Declared inside methods, constructors, or blocks - Accessible only within that scope - Must be initialized before use ✅ Instance Variables - Declared inside a class but outside methods - Belong to objects - Each object has its own copy ✅ Static Variables - Declared using "static" keyword - Shared among all objects of the class - Memory allocated only once 💡 Example: "int age = 21;" "String name = "Java";" 🎯 Key Takeaway: Variables are the basic building blocks of any Java program used to store and manage data efficiently. Learning and growing at Dhee Coding Lab 💻 #Java #CoreJava #Variables #Programming #LearningJourney #FullStackDevelopment
To view or add a comment, sign in
-
📘✨ Collections and Framework Introduction to ArrayList in Java – Conceptual Overview 🚀 Continuing my learning, I focused on the theory behind ArrayList, a fundamental part of Java’s data handling 📋 🔹 ArrayList is a class that implements a dynamic array, meaning its size can change automatically during runtime 🔄 🔹 It belongs to the Java Collections Framework and is widely used for storing and managing data efficiently 💡 Core Properties: ✔ Preserves insertion order 📑 ✔ Allows duplicate elements 🔁 ✔ Provides random (index-based) access ⚡ ✔ Dynamically resizes as data grows 📈 💡 Performance Insight ⚙️ - Fast for accessing elements (O(1)) - Slower for inserting/removing elements in between (due to shifting) - Better suited for read-heavy operations 💡 Behind the Scenes 🔍 - Internally uses an array structure - When capacity is full, it creates a larger array and copies elements - Default capacity grows automatically 💡 Use Cases 🌍 📌 Managing lists of students, products, or records 📌 Applications where order matters 📌 Situations where frequent searching/access is required 💡 Drawbacks ⚠️ ❌ Not efficient for frequent insertions/deletions ❌ Not thread-safe without synchronization 🎯 Final Thought 💡 ArrayList offers a perfect balance between simplicity and performance, making it one of the most commonly used data structures in Java 💻✨ #Java #ArrayList #Collections #Programming #CodingLife #Developer #LearningJourney #HarshitT #TapAcademy
To view or add a comment, sign in
-
-
🚀 Starting My Java Learning Journey – Day 16 🔹 Topic: Encapsulation in Java. Encapsulation is one of the core OOP concepts. It is the process of wrapping data (variables) and code (methods) into a single unit (class). It also helps in data hiding. 📌 How to Achieve Encapsulation? ✔ Declare variables as private. ✔ Provide public getter and setter methods to access and update values. 📌 Example Program class Student { private String name; // Getter method public String getName() { return name; } // Setter method public void setName(String name) { this.name = name; } } public class Main { public static void main(String[] args) { Student s1 = new Student(); s1.setName("John"); System.out.println(s1.getName()); } } Output: John 💡 Key Points: ✔ Protects data from unauthorized access. ✔ Improves security and flexibility. ✔ Achieved using private variables + getters/setters. #Java#JavaLearning #Programming #BackendDevelopment #CodingJourney #Encapsulation #OOP#
To view or add a comment, sign in
-
Learning Priority Queue in Java Recently, I explored the concept of Priority Queue in Java, and it gave me a strong understanding of how efficient data handling works when priority matters over order. 🔹 Why Priority Queue? Unlike normal queues (FIFO), a Priority Queue processes elements based on their priority (min or max), which makes it extremely useful in scenarios like scheduling, real-time systems, and optimization problems. 🔹 Key Learnings: How Priority Queue is implemented using a heap (min-heap by default) Syntax and basic operations in Java Time complexity for insertion and deletion: O(log n) How ordering works internally without full sorting 🔹 Java Syntax Example: PriorityQueue<Integer> pq = new PriorityQueue<>(); pq.add(10); pq.add(5); pq.add(20); System.out.println(pq.peek()); // Smallest element pq.poll(); // Removes smallest element 🔹 Problems I Practiced: ✔️ Kth Smallest Element ✔️ Kth Largest Element These problems helped me understand how to use min-heap and max-heap effectively to optimize performance instead of sorting the entire array. 💡 Takeaway: Priority Queue is a powerful tool when you need efficient access to the smallest or largest element without sorting everything. Looking forward to applying this in more real-world problems and system design scenarios! 💻🔥 big thanks to Pratyush Narain #Java #DataStructures #PriorityQueue #DSA #Learning #CodingJourney
To view or add a comment, sign in
-
-
🚀 Mastering TreeSet in Java: Hierarchy & Powerful Methods While diving deeper into the Java Collections Framework, I explored the structure and capabilities of TreeSet—a class that combines sorting, uniqueness, and efficient navigation. 🔷 TreeSet Hierarchy (Understanding the Backbone) The hierarchy of TreeSet is what gives it its powerful features: 👉 TreeSet ⬇️ extends AbstractSet ⬇️ implements NavigableSet ⬇️ extends SortedSet ⬇️ extends Set ⬇️ extends Collection ⬇️ extends Iterable 💡 This layered structure enables TreeSet to support sorted data, navigation operations, and collection behavior seamlessly. 🔷 Important Methods in TreeSet TreeSet provides several methods for efficient data handling and navigation: 📌 Basic Retrieval first() → Returns the first (smallest) element last() → Returns the last (largest) element 📌 Range Operations headSet() → Elements less than a given value tailSet() → Elements greater than or equal to a value subSet() → Elements within a specific range 📌 Removal Operations pollFirst() → Removes and returns first element pollLast() → Removes and returns last element 📌 Navigation Methods ceiling() → Smallest element ≥ given value floor() → Largest element ≤ given value higher() → Element strictly greater than given value lower() → Element strictly less than given value 🔷 When to Use TreeSet? TreeSet is the right choice when you need: ✔️ Sorted Order (automatic ascending order) ✔️ No Duplicate Entries ✔️ Efficient Range-Based Operations ✔️ Navigation through elements (closest matches) 📊 Time Complexity: Insertion → O(log n) Access/Search → O(log n) 💡 Key Insight: TreeSet internally uses a self-balancing tree (Red-Black Tree), which ensures consistent performance and sorted data at all times. 🎯 Understanding TreeSet not only strengthens your knowledge of collections but also helps in solving real-world problems involving sorted and dynamic datasets. #Java #TreeSet #JavaCollections #Programming #DataStructures #LearningJourney TAP Academy
To view or add a comment, sign in
-
-
🚀 Java Learning Journey | Day 15 | Core Java Learned about Wrapper Classes in Java. 💡 Key Concept: Wrapper classes convert primitive data types into objects. Example: int → Integer, double → Double ⚙ Why Important? • Required for Collections Framework (ArrayList, HashMap) • Enables autoboxing & unboxing • Useful in object-based operations 📚 Learning: Understanding how Java handles data as objects and why wrapper classes are essential in real-world applications. #JavaDeveloper #Java #CoreJava #OOP #Programming #CodingJourney #LearningInPublic #100DaysOfCode #DevelopersOfLinkedIn #BackendDevelopment
To view or add a comment, sign in
-
🚀 Day 49 – Mastering ArrayList Methods in Java Today I focused on one of the most powerful parts of the Java Collections Framework – the ArrayList and its important methods. 📌 Key Learnings: 🔹 Dynamic data structure (resizable array) 🔹 Allows duplicates & maintains insertion order 🔹 Efficient data manipulation using built-in methods 💡 Methods I explored: ✔ add() – Insert elements ✔ add(index, value) – Insert at specific position ✔ addAll() – Merge collections ✔ remove() / removeAll() – Delete elements ✔ retainAll() – Keep common elements ✔ set() – Replace values ✔ get() – Access elements ✔ size() – Count elements ✔ contains() – Search elements ✔ subList() – Extract partial data ✔ clear() – Remove all data ✔ trimToSize() – Optimize memory 🔥 Key Insight: Understanding the difference between add() vs set() is crucial: add() → shifts elements set() → replaces elements 📊 These methods are not just theory — they are heavily used in real-world applications for managing and processing data efficiently. 💭 Takeaway: Mastering ArrayList methods improves problem-solving and builds a strong foundation in Java programming. #Java #ArrayList #CollectionsFramework #Programming #CodingJourney #JavaDeveloper #Learning #Day49
To view or add a comment, sign in
-
-
🚀 Core Java Learning Journey Explored How to Write Package Statement in Java ☕ 🔹 What is a Package Statement? A package statement is used to define the package (namespace) in which a class belongs. It helps organize classes into a structured hierarchy. 📌 Syntax of Package Statement: package package_name; 👉 It must be the first statement in a Java file (before any import or class declaration). --- 📌 Example: package com.myapp; public class Demo { public static void main(String[] args) { System.out.println("Hello Package"); } } --- 📌 Key Rules: ✅ Package statement should be written at the top of the file ✅ Only one package statement is allowed per file ✅ Package name should follow naming conventions (lowercase, reverse domain like "com.company") --- 📌 Compile & Run: javac -d . Demo.java java com.myapp.Demo --- 🎯 Key Takeaway: The package statement defines the location of a class and helps in organizing Java programs into a clean and maintainable structure. Learning and growing at Dhee Coding Lab 💻 #Java #CoreJava #Packages #Programming #LearningJourney #FullStackDevelopment
To view or add a comment, sign in
-
🚀 Core Java Learning Journey Explored Instance, Static, and Local Variables in Java ☕ 🔹 Local Variables - Declared inside methods, constructors, or blocks - Accessible only within that specific scope - Must be initialized before use - Stored in stack memory 🔹 Instance Variables - Declared inside a class but outside methods - Belong to each object of the class - Each object has its own copy - Stored in heap memory 🔹 Static Variables - Declared using the "static" keyword - Shared among all objects of the class - Only one copy exists - Stored in method area 💡 Example: class Demo { int instanceVar = 10; // Instance variable static int staticVar = 20; // Static variable void display() { int localVar = 5; // Local variable System.out.println(localVar); } } 🎯 Key Takeaway: Understanding variable types helps in writing efficient and optimized Java programs by managing memory and scope effectively. Learning and growing at Dhee Coding Lab 💻 #Java #CoreJava #Variables #OOP #Programming #LearningJourney #FullStackDevelopment
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