🚀 Java Learning – Day 11 Do-While Loop in Java In while loop, condition is checked first. But in do-while loop, the code executes at least once, even if the condition is false. That’s why it is called an exit-controlled loop 💡 💻 Syntax do { // code to repeat } while(condition); 💻 Example Program class Test { public static void main(String[] args) { int i = 1; do { System.out.println(i); i++; } while(i <= 5); } } 🔍 Line-by-Line Explanation 🔹 int i = 1; → Initializes variable 🔹 do { } → Code inside runs first 🔹 System.out.println(i); → Prints value 🔹 i++; → Increments value 🔹 while(i <= 5); → Condition checked after execution 🔹 Loop repeats until condition becomes false ✅ Output 1 2 3 4 5 📝 Important Notes • Do-while loop executes at least once • Condition is checked after loop body • Useful in menu-driven programs • Ends with a semicolon (;) after while condition 🎯 Interview One-Line Answer Do-while loop in Java executes a block of code at least once, and then repeats based on a condition. 💬 Engagement Question If the condition is false at the beginning, how many times will a do-while loop execute? Comment your answer 👇 📌 Follow me to learn Java from Basics to Advanced daily 🚀
Java Do-While Loop Basics and Syntax
More Relevant Posts
-
🚀My Java Learning Journey Today, I explored the String concept in Java, which is one of the most important topics for handling text data. This helped me clearly understand immutability, memory management, and string operations in Java. 🔹 1️⃣ What is a String in Java? 📌 A String represents a sequence of characters 📌 Strings are stored as objects in Java 📌 Created using literals or the new keyword ✅ Helped me understand how Java handles text internally. 🔹 2️⃣ String Immutability 📌 Once created, a String cannot be changed 📌 Any modification creates a new String object 📌 Improves security and memory efficiency ✅ Gained clarity on why Strings are immutable in Java. 🔹 3️⃣Mutable Strings – StringBuilder & StringBuffer 📌 Allow modification without creating new objects 📌 Stored in heap memory 📌 Improve performance during frequent string changes ✅ Ideal for dynamic string operations. 🔹 4️⃣StringBuilder (Non-synchronized) 📌 Faster than StringBuffer 📌 Not thread-safe 📌 Used in single-threaded environments 📌 Common methods: append(), insert(), delete(), reverse() 🔹 5️⃣StringBuffer (Synchronized) 📌 Thread-safe and synchronized 📌 Slightly slower due to synchronization 📌 Used in multi-threaded environments 📌 Common methods: append(), insert(), delete(), replace() 🔹 6️⃣ String Pool & Memory 📌 String literals are stored in the String Constant Pool 📌 Reusing literals saves memory 📌 new String() always creates a new object ✅ Understood how Java optimizes memory for Strings. 🔹 7️⃣ Common String Operations 📌 Length, comparison, and concatenation 📌 Character access and substring operations 📌 Case conversion and trimming ✅ Practiced essential methods used in real-world applications. 🧠 Key Takeaways ✔ Clear understanding of String creation ✔ Importance of immutability ✔ Efficient memory usage with String Pool ✔ Strong foundation for advanced Java concepts 💡 Overall, learning Strings strengthened my core Java knowledge and prepared me for real-world programming scenarios. Guided by, Levaku Lavanya mam, Saketh Kallepu sir, Uppugundla Sairam sir.
To view or add a comment, sign in
-
✨ Understanding Method Overloading in Java | TAP Academy As part of my Java learning journey, I explored Method Overloading, an important concept of Compile-Time Polymorphism in Object-Oriented Programming. 🔹 What is Method Overloading? Method Overloading is the process of creating multiple methods within the same class that have the same method name but different parameters. It allows a method to perform different tasks based on the input, improving code readability and reusability. ✅ Ways to Achieve Method Overloading 1️⃣ By Changing the Number of Parameters class Demo { void add(int a, int b) { System.out.println(a + b); } void add(int a, int b, int c) { System.out.println(a + b + c); } } 2️⃣ By Changing the Data Type of Parameters void display(int a) { System.out.println("Integer value: " + a); } void display(double a) { System.out.println("Double value: " + a); } 3️⃣ By Changing the Sequence (Order) of Data Types void show(int a, String b) { System.out.println(a + " " + b); } void show(String b, int a) { System.out.println(b + " " + a); } 🔹 Method Overloading with Type Promotion If Java does not find an exact match, it automatically promotes the smaller data type to a larger compatible type. 📌 Type Promotion Hierarchy: byte → short → int → long → float → double 📌 Example: class Promotion { void print(int a) { System.out.println("Int method called"); } void print(double a) { System.out.println("Double method called"); } public static void main(String[] args) { Promotion obj = new Promotion(); obj.print(10); // Calls int version obj.print(10.5f); // float promoted to double → Calls double version } } 💡 Key Takeaways ✔ Same method name with different parameters ✔ Achieved using number, type, or order of parameters ✔ Happens at Compile Time (Static Binding) ✔ Supports flexibility using Type Promotion ✔ Return type alone cannot achieve overloading 📚 Learning Java step-by-step and strengthening my OOP concepts with TAP Academy. #Java #MethodOverloading #OOP #Polymorphism #JavaLearning #CodingJourney #TAPAcademy #Programming
To view or add a comment, sign in
-
-
🚀 Day 13 TAP Academy | Understanding Methods in Java 💡 What is a Method? A method is a group of statements that together perform an operation. Methods help make programs modular, clean, and easy to maintain. Think of a method as a mini-program inside your main program — you define it once and call it whenever needed. 🧠 Syntax of a Method: returnType methodName(parameters) { // Method body // Code to perform the task } ✅ Example: public int add(int a, int b) { return a + b; } Here: public → Access modifier int → Return type add → Method name (int a, int b) → Parameters return a + b; → Method body 🔹 Why Methods Are Important ✔️ Eliminate code repetition ✔️ Increase code reusability ✔️ Simplify debugging and testing ✔️ Improve program readability and structure 🔸 Types of Methods in Java Java provides different types of methods based on their behavior and purpose 👇 🧩 1️⃣ Predefined (Built-in) Methods These are already defined in Java’s standard libraries. You just have to use them. ✅ Example: System.out.println("Hello Java!"); Math.sqrt(25); // returns 5.0 📚 These methods come from predefined classes like Math, String, System, etc. 🧱 2️⃣ User-defined Methods These are created by the programmer to perform specific tasks. ✅ Example: public class Calculator { void greet() { System.out.println("Welcome to TAP Academy!"); } int add(int a, int b) { return a + b; } public static void main(String[] args) { Calculator obj = new Calculator(); obj.greet(); System.out.println("Sum: " + obj.add(5, 10)); } } ✅ Output: Welcome to TAP Academy! Sum: 15 ⚙️ Based on Return Type TypeDescriptionExampleVoid MethodDoes not return any valuevoid greet() {}Return Type MethodReturns a value after executionint add() { return a+b; } 🧠 Based on Parameters TypeDescriptionExampleWithout ParametersDoesn’t accept any inputvoid display()With ParametersTakes input valuesvoid add(int a, int b) 🔁 Method Overloading When multiple methods have the same name but different parameters, it’s called method overloading. It increases code flexibility and reusability. ✅ Example: void show() { System.out.println("No Parameters"); } void show(int a) { System.out.println("Value: " + a); } 🧩 Difference Between Built-in and User-defined Methods FeatureBuilt-in MethodsUser-defined MethodsDefined byJava LibraryProgrammerPurposeCommon operationsSpecific tasksExamplesMath.pow(), System.out.println()add(), display() #TAPAcademy #JavaProgramming #Methods #LearningJourney #InternshipExperience #JavaDeveloper #CodingJourney #ProgrammingBasics #TechLearning #LearnToCode #CodeWithJava #SoftwareDevelopment #CodingCommunity #BuildInPublic #JavaConcepts #MethodOverloading
To view or add a comment, sign in
-
-
🚀 Java Learning – Day 17 Jagged Array in Java (Irregular 2D Array) After learning 2D Arrays, the next important concept is the Jagged Array. 💡 What is a Jagged Array? A Jagged Array is a 2D array where each row can have a different number of columns. 👉 In simple words: Rows are fixed, columns are NOT fixed. 📊 Diagram Explanation (Easy to Visualize) Jagged Array Row 0 → [ 10 | 20 | 30 ] Row 1 → [ 40 | 50 ] Row 2 → [ 60 | 70 | 80 | 90 ] ✔ Row 0 → 3 elements ✔ Row 1 → 2 elements ✔ Row 2 → 4 elements 👉 Each row has different column size 💻 Example Program class Test { public static void main(String[] args) { int[][] arr = { {10, 20, 30}, {40, 50}, {60, 70, 80, 90} }; for(int i = 0; i < arr.length; i++) { for(int j = 0; j < arr[i].length; j++) { System.out.print(arr[i][j] + " "); } System.out.println(); } } } 🔍 Step-by-Step Explanation 🔹 arr.length → Number of rows 🔹 arr[i].length → Columns in that particular row 🔹 Inner loop changes based on row size 🔹 Nested loop is mandatory ✅ Output 10 20 30 40 50 60 70 80 90 📝 Important Notes • Jagged array is also called irregular array • Memory efficient compared to normal 2D array • Each row can have different column size • Uses nested loops for traversal 🎯 Interview One-Line Answer A jagged array in Java is a 2D array where each row can have a different number of columns. 📌 Follow me to learn Java from Basics to Advanced step by step 🚀
To view or add a comment, sign in
-
🚀 Java Mastery || Polymorphism Polymorphism means one reference, many behaviors. It allows the same operation to work differently based on the object involved, making Java programs flexible and easy to maintain. Instead of fixing behavior at the beginning, Java can decide the behavior at runtime, which is very useful in real applications. 🔹 Compile-Time Polymorphism Decision is made during compilation Based on method signatures Faster but less flexible Mainly improves readability This is also called early binding. 🔹 Runtime Polymorphism ⭐ Decision is made while the program runs Depends on the actual object Achieved through method overriding Commonly used in real-world Java projects This is the true form of polymorphism. 🔼 Upcasting & 🔽 Downcasting Upcasting Child object treated as Parent type Safe and automatic Supports runtime polymorphism Helps in loose coupling Downcasting Parent reference converted back to Child type Explicit and risky Used only when child-specific behavior is needed Prefer upcasting whenever possible. 🔓 Loose Coupling vs 🔒 Tight Coupling Loose Coupling Depends on abstractions Easy to change and maintain Tight Coupling Depends on concrete classes Hard to modify Polymorphism helps achieve loose coupling. 💡 Pro Tip 👉 Polymorphism works with methods, not variables. Methods are resolved at runtime, variables at compile time. 🔮 What’s Next? Java Mastery || Abstraction Learning how Java hides implementation details and exposes only what is needed.
To view or add a comment, sign in
-
-
Day 11 at Tap Academy: Arrays in Java Arrays in Java are a collection of homogeneous data elements of the same data type, stored in contiguous memory locations. They are objects, allocated memory in the heap, and have default values. Arrays can be classified based on dimensionality into one-dimensional, two-dimensional, and three-dimensional arrays. A one-dimensional array has a single row, while a two-dimensional array consists of rows and columns. A three-dimensional array comprises blocks, rows, and columns. The syntax for declaring arrays varies accordingly: `int[] a = new int[n];` for one-dimensional, `int[][] a = new int[m][n];` for two-dimensional, and `int[][][] a = new int[b][m][n];` for three-dimensional arrays. To access elements, use indices: `a[2] = 20;` adds an element, and `System.out.println(a[2]);` fetches it. Looping through arrays involves using for loops - one loop for one-dimensional, two loops for two-dimensional, and three loops for three-dimensional arrays. Arrays can hold homogeneous data (same data type) or be regular/jagged. Understanding array types and syntax is crucial for effective Java programming, enabling efficient data storage and manipulation.
To view or add a comment, sign in
-
-
🚀 AI Powered Java Full Stack – Day 28 Learning Update Today’s session focused on Object Class Methods and HAS-A (Composition) Relationship, which are essential for writing clean, reusable, and real-world Java applications 👨💻☕ 📚 Topics Covered Object Class in Java (root class of all classes) Important Object class methods: 🟣 equals() 🟣 hashCode() 🟣 toString() 🟣 wait(), notify(), notifyAll() 🟣 getClass(), clone(), finalize() 🟣 Equals & HashCode Contract (Interview Concept) 🟣 HAS-A Relationship (Composition & Aggregation) 🟣 Real-time examples with code 💡 Key Takeaways Object class is the parent of every Java class equals() and hashCode() must follow a strict contract HAS-A relationship helps in code reuse without inheritance Composition is preferred over inheritance in real-world design 🎯 Interview Highlights Every Java class implicitly extends Object class If equals() is overridden, hashCode() must also be overridden HAS-A represents “uses-a” relationship Composition is stronger than Aggregation 🌍 Real-World Analogy HAS-A: A Car has an Engine (Car uses Engine) Object class: A universal blueprint for all Java objects 🙏 Learning under expert guidance 👨🏫 Trainer: Fayaz S 🏫 Frontlines EduTech (FLM) Krishna Mantravadi 🚀 Strengthening Java OOPS fundamentals step by step toward becoming a Java Full Stack Developer. hashtag #Java #OOPS #ObjectClass #HasARelationship #JavaDeveloper #FullStackDevelopment #JavaInterview #LearningJourney #FrontLinesMedia
To view or add a comment, sign in
-
🚀 Day 11 of My Java Learning Journey... 🔁 Looping Statements in Java (Detailed Explanation) Looping statements are used when you want to repeat a block of code multiple times. Instead of writing the same code again and again, a loop allows automatic repetition until a condition is met. There are : 1. for loop 2. while loop 3. do-while loop 4. for each Each loop has a specific use and behavior. 🔁 for Loop: The for loop is one of the most commonly used loops in Java. It allows you to repeat a block of code a specific number of times. It is structured in a single line with three parts: 1️⃣ Initialization 2️⃣ Condition 3️⃣ Updation (Increment/Decrement) For Loop Syntax: for( initialization; Condition; Updation) 🔹Initialization * This part runs only once, at the beginning of the loop. * It sets the starting value of the loop variable. * Usually written as: starting number (e.g., i = 1). 🔹Condition * This is checked before every iteration. * If the condition is true, the loop executes. * If false, the loop stops. 🔹Updation(Increment / Decrement) * This part runs after each loop execution. * It updates the loop variable. * Helps move the loop towards completion. 🔁 How the for Loop Works Step-by-Step 1. Initialization happens → variable gets a starting value. 2. Condition is checked → if true → run loop body. 3. After running the loop body → increment/decrement happens. 4. Condition is checked again → repeat steps. 5. When the condition becomes false → loop stops. Guided by, Levaku Lavanya mam, Saketh Kallepu sir, Uppugundla Sairam sir.
To view or add a comment, sign in
-
-
🚀LinkedIn Post – Day 10 | TAP Academy 🎯 Day-10: Type Casting in Java – Learning & Growing! Today at TAP Academy, I learned one of the core Java fundamentals — Type Casting. It’s all about converting a value from one data type to another so our programs can work correctly and efficiently with different kinds of data. 🔹 What is Type Casting? In Java, type casting is the process of converting a variable from one data type into another. This ensures compatibility when values of different types interact — for example, in calculations or assignments. 🔹 Two Types of Type Casting ✅ 1️⃣ Implicit (Widening) Casting • Happens automatically • Converts smaller to larger data type • No syntax needed • No data loss Example conversions: byte → short → int → long → float → double Example: int num = 100; double d = num; // implicit conversion ✅ 2️⃣ Explicit (Narrowing) Casting • Programmer must do it manually • Converts larger type to smaller • May cause loss of data Example conversions: double → float → long → int → short → byte Example: double value = 9.78; int i = (int) value; // explicit casting Here, the decimal part is truncated — so we lose some data. 🔸 Why It Matters ✔ Helps prevent type mismatch errors ✔ Makes your code flexible and compatible ✔ Essential for arithmetic operations, method calls & object handling Type casting isn’t just syntax — it’s how Java understands and manages data safely and correctly. 💡 Feeling excited to apply this in real code! Leave a 👍 if you’ve used type casting before or drop a comment if you want code samples! “Type Casting in Java” Option 1 (Clean & Simple): Type Casting in Java 🔹 Implicit Casting (Widening) → Auto conversion → int → double 🔹 Explicit Casting (Narrowing) → Manual conversion → double → int ✔ Helps safely convert between data types Option 2 (With Examples): Java Type Casting – Explained 🟢 Implicit (Auto) int a = 10; double d = a; 🔵 Explicit (Manual) double d = 9.78; int i = (int) d; ⚙️ Converts values safely between types! 🟪 Poster 2 – “Implicit vs Explicit Casting” Option 1 (Rule Box): ⚖️ Implicit vs Explicit Type Casting Implicit (Widening) Auto conversion → No data loss byte → short → int → long → float → double Explicit (Narrowing) Manual conversion → Possible data loss double → float → long → int → short → byte Option 2 (Side-by-Side Example): Type Casting Simplified 🟩 Implicit int x = 50; double d = x; 🟦 Explicit double y = 9.99; int i = (int) y; 🧠 Core Java skill for type compatibility! #TAPAcademy #JavaProgramming #CharDataType #DataTypes #Unicode #JavaDeveloper #ProgrammingBasics #LearningJourney #CodingJourney #InternshipExperience #TechEducation #LearnToCode #CodingCommunity #SoftwareDevelopment #BuildInPublic #JavaConcepts #CodeWithJava #GlobalProgramming #CodeNewbie
To view or add a comment, sign in
-
-
🚀Day 4(Part 3) | core java learning journey ☕ 📘 Topic: Operators in Java Today I learned about Operators in Java, which are used to perform different types of operations on variables and values. Operators play a very important role in writing logic, conditions, and calculations in Java programs. 🔹 1. Unary Operators Unary operators work on a single operand. Examples: +, -, ++, --, ! They are mainly used to increment, decrement, or negate values. 🔹 2. Arithmetic Operators Used to perform mathematical calculations. Examples: +, -, *, /, % These operators are commonly used for addition, subtraction, multiplication, division, and modulus operations. 🔹 3. Relational Operators Used to compare two values and return a boolean result (true or false). Examples: ==, !=, >, <, >=, <= They are mostly used in decision-making statements like if and while. 🔹 4. Logical Operators Used to combine multiple conditions. Examples: && (AND), || (OR), ! (NOT) These operators are very helpful in complex conditional expressions. 🔹 5. Bitwise Operators Operate on bits and perform bit-by-bit operations. Examples: &, |, ^, ~ They are mainly used in low-level programming and performance optimization. 🔹 6. Assignment Operators Used to assign values to variables. Examples: =, +=, -=, *=, /= They help in updating variable values efficiently. 🔹 7. Shift Operators Used to shift bits to the left or right. Examples: <<, >>, >>> These operators are useful for fast calculations and bit manipulation. 🔹 8. Ternary Operator A shorthand way to write conditional statements. 🙏 Grateful to my mentor: Vaibhav Barde Sir for continuous guidance and support. #CoreJava #JavaOperators #JavaLearning #ProgrammingBasics #CodingJourney #FortuneCloud
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