📘 Day 6 of Java Learning Series 🔹 Control Statements in Java (if-else, loops) Control statements help us control the flow of execution in a program. They allow decision-making and repetition of tasks. 🔸 1. if-else Statement (Decision Making) Used when we want to execute code based on a condition. 💡 Example: int age = 18; if (age >= 18) { System.out.println("You can vote"); } else { System.out.println("You cannot vote"); } 🔸 2. Loops (Repetition) Loops help us execute a block of code multiple times. 👉 for loop (when number of iterations is known) for (int i = 1; i <= 5; i++) { System.out.println(i); } 👉 while loop (runs while condition is true) int i = 1; while (i <= 5) { System.out.println(i); i++; } ✅ Key Takeaways: ✔ if-else → decision making ✔ loops → repetition ✔ for loop → fixed iterations ✔ while loop → condition-based execution 💬 Which loop do you use more – for or while? 👉 Follow me for more Java content 🚀 #Java #Programming #100DaysOfCode #Developers #Learning #CoreJava
Java Control Statements if-else Loops
More Relevant Posts
-
🚀 Day 3 of My Java Learning Journey – Control Statements in Java Today, I learned how programs make decisions and repeat tasks using Control Statements in Java. These are essential for building logic in real-world applications. 🔹 Types of Control Statements: ➤ 1. if-else Statement Used for decision making 👉 Executes code based on conditions if (x > 10) { System.out.println("Greater than 10"); } else { System.out.println("Less than or equal to 10"); } ➤ 2. switch Statement Used when we have multiple choices 👉 Cleaner alternative to multiple if-else switch(day) { case 1: System.out.println("Monday"); break; case 2: System.out.println("Tuesday"); break; default: System.out.println("Invalid day"); } ➤ 3. Loops (Repetition Statements) Used to execute code multiple times ✔ for loop – when number of iterations is known ✔ while loop – when condition is checked before execution ✔ do-while loop – executes at least once for(int i = 1; i <= 5; i++) { System.out.println(i); } 💡 Key Learning: Control statements help in decision-making and repeating tasks, making programs smarter and more dynamic. 📌 Practiced writing programs using if-else, switch, and loops to strengthen my logic-building skills. #Java #Programming #CodingJourney #LearningJava #ControlStatements #100DaysOfCode #Developers 🚀
To view or add a comment, sign in
-
🚀 Core Java Learning Journey Explored Constructors in Java and the rules for writing them ☕ 🔹 What is a Constructor? A constructor is a special method used to initialize objects. It is automatically called when an object is created. 📌 Key Features of Constructors: ✅ Same name as the class ✅ No return type (not even "void") ✅ Automatically invoked during object creation ✅ Used to initialize instance variables 🔹 Types of Constructors: ✔️ Default Constructor ✔️ Parameterized Constructor 📌 Rules for Writing Constructors: 🔸 Constructor name must be the same as the class name 🔸 It should not have any return type 🔸 Can be overloaded (multiple constructors in one class) 🔸 Cannot be static, final, or abstract 🔸 If no constructor is written, Java provides a default constructor 💡 Example: class Student { int id; String name; Student(int i, String n) { // Parameterized constructor id = i; name = n; } } 🎯 Key Takeaway: Constructors make object initialization easy and are a fundamental part of Object-Oriented Programming in Java. Learning and growing at Dhee Coding Lab 💻 #Java #CoreJava #Constructors #OOP #Programming #LearningJourney #FullStackDevelopment
To view or add a comment, sign in
-
🚀 Understanding Constructors in Java – With Examples Today, I explored Constructors in Java, one of the most important concepts in Object-Oriented Programming. 🔹 A constructor is a special method that gets called automatically when an object is created. It helps initialize the object with the required values. 💡 Types of Constructors I learned: ✔ Default Constructor class Student { String name; Student() { name = "Default"; } } ✔ Parameterized Constructor class Student { String name; Student(String n) { name = n; } } ✔ Constructor Overloading class Student { Student() { System.out.println("Default"); } Student(int id) { System.out.println("ID: " + id); } } ✔ Constructor Chaining class Student { Student() { this(100); System.out.println("Default Constructor"); } Student(int id) { System.out.println("Parameterized: " + id); } } 📌 Why Constructors matter? 🔐 Ensures proper object initialization 🧱 Makes code clean and structured 🔄 Avoids repetition using chaining 👉 One key takeaway: Constructors make object creation meaningful and organized. Step by step, building strong Java fundamentals 🚀 What Java concept are you currently learning? #Java #OOPS #Constructors #Code #Programming #LearningJourney #Developers #tapacademy
To view or add a comment, sign in
-
-
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
-
-
📘✨ 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
-
-
🚀 Day 16 of My Java Learning Journey Today, I explored one of the most important OOP concepts in Java — Constructors 🔥 🔹 What I Learned: • Constructor is a special method used to initialize objects • It has the same name as the class • No return type (not even void) • Automatically called when object is created 🔹 Types of Constructors: • Default Constructor • Parameterized Constructor 💡 Key Insight: Java does not have a built-in copy constructor like C++, but we can create it manually if needed. 🧠 Realization: Constructors make object creation more structured and efficient — they are like the “starting point” of any object in Java. Consistency + Practice = Growth my mentor Aman Soni Vidhya Code Gurukul #Java #OOP #Programming #LearningJourney #CodeNewbie #100DaysOfCode #Developers #TechSkills
To view or add a comment, sign in
-
-
🚀 Day 32/100 – Java Learning Journey Today’s focus was on a very important yet often overlooked concept in Java: Wrapper Classes & Cache Memory. 🔍 Key Learnings: ✔️ Wrapper Classes & Object Creation Wrapper classes like Integer, Character, etc., allow us to convert primitive data types into objects, enabling their use in collections and advanced operations. ✔️ Cache Memory in Wrapper Classes Java optimizes memory usage using cache memory for certain values. For example, Integer values between -128 to 127 are cached. 👉 Instead of creating new objects repeatedly, Java reuses existing ones — improving performance. ✔️ Important Insight When using Integer.valueOf(), Java may return a cached object. But using new Integer() always creates a new object (less efficient). ✔️ Special Case – Decimal Types Types like Float and Double do not use cache memory, which is an important distinction for optimization. 💡 Hands-on Example: Converted a string "10" into an integer using: Integer i = Integer.valueOf(s); 📌 Takeaway: Understanding internal optimizations like caching helps write efficient and memory-optimized Java code, which is crucial for real-world applications and interviews. 🔥 Consistency is key — learning something new every single day! #Java #100DaysOfCode #LearningJourney #Programming #JavaDeveloper #Coding #SoftwareDevelopment #BackendDevelopment #TechGrowth Meghana M 10000 Coders
To view or add a comment, sign in
-
Most beginners think learning Java is about syntax. But real Java developers think in concepts. When I started learning Java, I focused a lot on writing code… But over time, I realized something important: 👉 Good Java developers don’t just write code — they design solutions. So today, I want to share 5 Java concepts that made the biggest difference in my learning journey. ☕ 5 Java Concepts Every Developer Should Master 🔹 1. Object-Oriented Programming (OOP) Understanding Encapsulation, Inheritance, Polymorphism, and Abstraction completely changes how you structure your code. 👉 Clean OOP = Maintainable code. 🔹 2. Exception Handling Handling errors properly makes your application reliable and professional. try-catch-finally is not just syntax — it’s about writing safe code. 🔹 3. Collections Framework Knowing when to use: ArrayList HashMap HashSet can make your program faster and cleaner. 🔹 4. Multithreading Basics Modern applications need performance. Understanding Threads and Synchronization gives your programs real power. 🔹 5. JDBC & Database Connectivity Java without database interaction is incomplete. Learning JDBC basics helps you build real-world backend applications. 💡 My Biggest Realization: 👉 Java is not hard — lack of practice is. 👉 Consistency beats complexity every time. I’m currently strengthening my Java fundamentals and exploring backend development step by step. #Java #JavaDeveloper #BackendDevelopment #Programming #SoftwareDevelopment #CodingJourney #TechLearning #JavaProgramming
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
-
📘 Day 2 of Java Learning Series 🔹 Understanding OOP Concepts in Java Java is based on Object-Oriented Programming (OOP), which helps in writing clean, reusable, and scalable code. 🔑 4 Main OOP Concepts: 1️⃣ Encapsulation 👉 Wrapping data (variables) and code (methods) into a single unit 👉 Achieved using classes 👉 Helps in data hiding 💡 Example: class Student { private String name; public void setName(String name) { this.name = name; } public String getName() { return name; } } 2️⃣ Inheritance 👉 One class can inherit properties of another class 👉 Promotes code reuse 💡 Example: class Animal { void sound() { System.out.println("Animal makes sound"); } } class Dog extends Animal { void bark() { System.out.println("Dog barks"); } } 3️⃣ Polymorphism 👉 One action, many forms 👉 Method overloading & overriding 4️⃣ Abstraction 👉 Hiding implementation details and showing only functionality 👉 Achieved using abstract classes & interfaces 🚀 Mastering OOP is the foundation of becoming a strong Java developer! 👉 Follow for more Java concepts #Java #OOP #Programming #Developers #Learning #100DaysOfCode
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