🌟 Day 7 of My Java Learning Journey ~> Understanding == vs .equals() in Java 🔥 Hey connections 👋 Today I explored one of the most commonly confusing topics in Java — the difference between == and .equals(). Let’s break it down simply 👇 💡 == Operator Used to compare memory references (i.e., whether two variables point to the same object in memory). Works perfectly for primitive data types like int, char, boolean, etc. But when used with objects (like String), it only checks if both references point to the same object, not if their values are equal. 🧩 Example: -------------------------------------code start---------------------------------------- String s1 = new String("Java"); String s2 = new String("Java"); System.out.println(s1 == s2); // false (different memory locations) System.out.println(s1.equals(s2)); // true (same value) --------------------------------------code end--------------------------------------- 💬 .equals() Method Comes from the Object class. Used to compare the actual content (values) of two objects. In most Java classes (like String, Integer, etc.), it’s overridden to check value equality. 🧩 Example: ----------------------------------code start------------------------------------------- String name1 = "Yuvi"; String name2 = "Yuvi"; System.out.println(name1 == name2); // true (same memory due to String pool) System.out.println(name1.equals(name2)); // true (same value) ----------------------------------code end------------------------------------------- 🚀 Quick Summary ~ Comparison TypeWorks OnChecks==Primitives ~ Object referencesMemory location.equals()ObjectsActual values/content ✨ Remember: Use == for primitive data types Use .equals() for comparing object values 💭 This small concept makes a big difference when working with strings, collections, and custom objects. #Java #Coding #LearningJourney #JavaDeveloper #OOPs #Programming #100DaysOfCode #DevOps #JavaLearning #SoftwareDevelopment #LinkedInLearning
Yuvraj Singh Kushwah’s Post
More Relevant Posts
-
🌟 Day 14 of My Java Learning Journey 🔥 💯 Hey everyone! 👋 ~ Today’s topic was all about decision-making in Java — how a program chooses which path to follow based on given conditions. 💡 . I explored how to find the greatest number among multiple values using nested if-else statements, one of the core parts of selection statements in Java. 💻 Here’s the code I worked on today: 👇 -------------------------------------code start-------------------------------------- public class FindGreaterNumberDemo2 { public static void main(String[] args) { int p = 11; int q = 22; int r = 33; int s = 44; if (p > r && p > s && p > q) { System.out.println("p is greater number "); } else if (q > s && q > p && q > r) { System.out.println("q is greater number"); } else if (r > p && r > s && r > q) { System.out.println("r is greater number"); } else { System.out.println("s is greater number"); } } } -------------------------------------code output------------------------------------ s is greater number ---------------------------------------code end-------------------------------------- . 🔍 Explanation: We have four integer variables: p, q, r, and s. Using an if-else-if ladder, we compare each number with the others using the logical AND (&&) operator. The first condition that turns out true will print which number is the greatest. If none of them match, the else block executes, showing that s is the greatest. . 💡 Key Takeaway: Selection statements like if, else if, and else help control the program’s logic — deciding what happens next depending on the condition. . 🚀 What’s next? In the upcoming posts, I’ll share many more real-world examples related to selection statements, so we can deeply understand how decision-making works in Java programs. Stay tuned — it’s gonna get crazy cool and more practical! 💻🔥 . #Java #100DaysOfCode #Day14 #JavaLearningJourney #FlowControl #IfElse #SelectionStatements #DevOps #Programming #CodingJourney #LearnJava #TechLearner #CodeNewbie .
To view or add a comment, sign in
-
-
🚀 Java Learning Journey – Day 22 🔥 Understanding Switch Case with Expressions (Java) Today I explored how switch-case works when we use expressions inside the case labels. ~ In Java, expressions like (0+1) or (1+2) get evaluated first, and then matched with the switch variable. The interesting part is fall-through, which happens when we don’t use a break statement. This helps in understanding how multiple cases can run together. ✅ Here’s the code I practiced today: -------------------------------------code start------------------------------------ public class SwitchDemo2 { public static void main(String[] args) { int x = 0; //x=0 (E) | x=1 (A,B) | x=2 (B) | x=3 (C,D,E) | x=4 (D,E) | x=5 (E) switch (x) { case (0+1): System.out.println("A"); case (1+1): System.out.println("B"); break; case (1+2): System.out.println("C"); case (2+2): System.out.println("D"); default: System.out.println("E"); } } } ----------------------------------code output------------------------------------ E -------------------------------------code end------------------------------------ 🧠 Key Takeaways case expressions are evaluated before matching. Without break, execution continues to the next case (fall-through). Helps in understanding how switch-case flows internally. 🌱 Personal Note: I’m continuously learning Java and exploring DevOps tools and practices to build a strong foundation for full-stack and automation development. If you like my daily progress posts, please support with a like, comment, or share ~ it truly motivates me to keep learning and sharing. 🙌 I’m also looking for internship opportunities in Java development or DevOps to apply my skills in real-world projects, learn from professionals, and grow further. If you know of any such opportunities or can guide me, I’d really appreciate your help 🙏 #JavaLearningJourney #day22 #Java #Programming #LearningInPublic #SwitchCase #JavaBeginners #CodeNewbie #FallThrough #DeveloperJourney #DevOps #TechJourney #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 20 of My Java Learning Journey ~ Switch Statement with Break 💯 . Hey everyone 👋 Today, I learned about the switch statement in Java ~ a control flow statement that helps us choose one action out of many based on a given value. Here’s the program I practiced 👇 --------------------------------------code start--------------------------------------- public class SwitchDemoWithBreak { public static void main(String[] args) { int x = 2; switch (x) { case 1: System.out.println("Today is Monday"); break; case 2: System.out.println("Today is Tuesday"); break; case 3: System.out.println("Today is Wednesday"); break; case 4: System.out.println("Today is Thursday"); break; case 5: System.out.println("Today is Friday"); break; case 6: System.out.println("Today is Saturday"); break; case 7: System.out.println("Today is Sunday"); break; default: System.out.println("You have entered the number out of range"); } } } -----------------------------------code output--------------------------------------- Today is Tuesday --------------------------------------code end--------------------------------------- 🧠 Explanation: The switch statement checks the value of x and executes the matching case. Each case represents a possible value of x. The break statement prevents execution from continuing into the next case. The default block runs when no case matches. 👉 In this example, since x = 2, it prints: “Today is Tuesday” ✅ 🌱 Personal Note: I’m continuously learning Java and exploring DevOps tools and practices to build a strong foundation for full-stack and automation development. If you like my daily progress posts, please support with a like, comment, or share ~ it truly motivates me to keep learning and sharing. 🙌 I’m also looking for internship opportunities in Java development or DevOps to apply my skills in real-world projects, learn from professionals, and grow further. If you know of any such opportunities or can guide me, I’d really appreciate your help 🙏 . #Java #LearningJourney #Day20 #CodingInPublic #SwitchCase #BreakStatement #JavaDeveloper #DevOps #Internship #CareerGrowth #CodeWithYuvi ..... ... .
To view or add a comment, sign in
-
-
😍 Day 17 of My Java Learning Journey – Finding Odd or Even Numbers 🔢 . Hey everyone 👋 . Today, I explored a simple but important concept 💯 ~ how to check whether numbers are odd or even in Java using conditional statements (if-else). . Here’s the code I practiced today: 👇 --------------------------------------code start-------------------------------------- public class FindOddOrEvenNumberDemo { public static void main(String[] args) { int c = 32; int d = 21; if (c % 2 == 0 && d % 2 == 0) { System.out.println("c & d both are even number"); } else if (c % 2 != 0 && d % 2 != 0) { System.out.println("c & d both are odd number"); } else if (c % 2 == 0) { System.out.println("c is even number and d is odd number"); } else { System.out.println("c is odd number and d is even number"); } } } ------------------------------------code output------------------------------------ c is even number and d is odd number ------------------------------------code end--------------------------------------- 💡 Explanation: The expression number % 2 gives the remainder when dividing the number by 2. If the remainder is 0, the number is even. If the remainder is not 0, the number is odd. . I used multiple if-else conditions to check all possibilities: Both numbers are even. Both numbers are odd. One is even and the other is odd. . 👉 In this example, c = 32 (even) and d = 21 (odd), so the output will be: ~ c is even number and d is odd number. . Building these logic-based programs helps strengthen my understanding of control flow and conditions in Java, which are essential for solving real-world coding problems. . #Java #Coding #LearnJava #100DaysOfCode #DevOps #JavaLearningJourney #Day16 #Programming #CodeWithYuvi #LogicBuilding .
To view or add a comment, sign in
-
-
🚀 Day 21 of My Java Learning Journey ~ Switch Statement Without Break – Fall-Through Behavior Explained 💡 . Hey everyone 👋 Today, I learned how the switch statement behaves when we don’t use the break keyword. This is an important Java concept called fall-through, where execution continues into the next cases until the switch ends. Here’s the program I practiced 👇 --------------------------------------code start--------------------------------------- public class SwitchDemoWithoutBreak { public static void main(String[] args) { int m = 9; switch (m) { case 1: System.out.println("the month is january"); case 2: System.out.println("the month is February"); case 3: System.out.println("the month is March"); case 4: System.out.println("the month is April"); case 5: System.out.println("the month is May"); case 6: System.out.println("the month is June"); case 7: System.out.println("the month is July"); case 8: System.out.println("the month is August"); case 9: System.out.println("the month is September"); case 10: System.out.println("the month is October"); case 11: System.out.println("the month is November"); case 12: System.out.println("the month is December"); default: System.out.println("You have entered the number out of range"); } } } -----------------------------------code output--------------------------------------- the month is September the month is October the month is November the month is December You have entered the number out of range --------------------------------------code end--------------------------------------- 🧠 Explanation: The switch statement checks the value of m. Since there is no break statement in any case, Java continues executing all cases from the matching case until the end. This behavior is known as fall-through. Since m = 9, the program starts printing from case 9 all the way to default. 👉 This helps you understand why break statements are important when you want to stop execution after a specific matched case. 🌱 Personal Note: I’m learning Java consistently every day and improving my understanding of core concepts. Along with Java, I’m also exploring DevOps tools to strengthen my development and automation skills. If you find my daily learning posts helpful, please support with a like, comment, or share — it really motivates me to keep going! 🙌 I’m also actively looking for internship opportunities in Java development or DevOps. If you know of any openings or can guide me, I’d truly appreciate your help 🙏 . hashtag#Java hashtag#LearningJourney hashtag#Day21 hashtag#SwitchCase hashtag#FallThrough hashtag#JavaDeveloper hashtag#CodingInPublic hashtag#DevOps hashtag#Internship hashtag#CareerGrowth hashtag#CodeWithYuvi ....... ...
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
-
Topic – The static Keyword in Java ⚙️ In Java, the static keyword means — 👉 “It belongs to the class, not to any specific object.” So instead of each object creating its own copy, everyone shares one common copy! 🧱 1️⃣ Static Variables (Class Variables) Belong to the class, not to individual objects One copy shared among all objects class Student { static String school = "ABC School"; // Shared by all students String name; Student(String name) { this.name = name; } } public class Main { public static void main(String[] args) { Student s1 = new Student("Shahil"); Student s2 = new Student("Ravi"); System.out.println(s1.school); // ABC School System.out.println(s2.school); // ABC School } } 💡 Like a school name — same for every student! ⚙️ 2️⃣ Static Methods Called using class name (no need to create an object) Cannot use this or access non-static members directly class MathUtils { static int add(int a, int b) { return a + b; } } public class Main { public static void main(String[] args) { int sum = MathUtils.add(5, 10); // No object needed System.out.println(sum); } } 💡 Like using a calculator’s “Add” button — it works without creating a calculator object! 🧩 3️⃣ Static Blocks Run once when the class loads Used to initialize static variables class Config { static int maxUsers; static { maxUsers = 100; System.out.println("Static block executed!"); } } public class Main { public static void main(String[] args) { System.out.println(Config.maxUsers); } } 💡 Like setting up a system before starting work — it runs only once. 🧱 4️⃣ Static Nested Classes A class inside another class Does not need an instance of the outer class class Outer { static class Inner { void show() { System.out.println("Inside static nested class"); } } } public class Main { public static void main(String[] args) { Outer.Inner obj = new Outer.Inner(); obj.show(); } } 💡 Like a department inside a company — it can work independently. 🧠 Key Takeaway: Use static when something should stay common, shared, or utility-based — not tied to any one object. #Day9 #JavaLearning #StaticKeyword #JavaDeveloper #SpringBoot #BackendDevelopment #CodingJourney #StaticKeyword
To view or add a comment, sign in
-
🚀 Day 1 Learn Java with Me Topic:- Variables Imagine you have a few empty boxes on a table. and suppose in each box you are writing a name(label) like “Age,” “Name,” or “IsStudent.” Then you put something inside — maybe 25, "Furquan", or true. That’s exactly what a variable is in Java. Q. Define Variable 👉Variable is a small container that stores information for your program. Syntax of variable:- dataType variableName = value; In Java, Variable looks like 👉 int age = 25; String name = "Furquan"; boolean isStudent = true; int → stores whole numbers (like 25) String → stores text or words (like “Furquan”) boolean → stores yes/no or true/false values You can use declared variable (Value must be assigned) and undeclared variable (Value isn't assigned) ex:- Int x; //UnDeclared variables Int x=10; //Declared Variables 🧩 Two Main Types of Variables in Java 🧩 1. Local Variable Think of this like a box that exists only inside a small room. You can use it only inside that room, and when you leave, the box disappears. In programming, that “room” is usually a method (a small block of code). A local variable is created inside a method, used there, and destroyed when the method ends. In local variables, values must be declared before using them. Example: public class Greeting { public void sayHello() { String message = "Hello, Java Learner!"; System.out.println(message); } } 🌍 2. Instance Variable (Global Variable) Now imagine a box that belongs to the whole house, not just one room. Anyone inside the house can use it anytime. That’s what an instance variable is — it’s created inside a class but outside any method. It can be used by all methods of that class. It’s also called a global variable because it’s accessible everywhere inside the class. Instance Variable have default value like 0, NULL, or false. Example: public class Student { String name = "Furquan"; // instance (global) variable public void showName() { System.out.println(name); // accessible here } public void changeName() { name = "Ali"; // still accessible here } } 🎯 Bonus Tips about Variables 1. Java is case-sensitive → Age and age are not the same. 2. Variable names can’t start with a number → age1 ✅ but 1age ❌ 3. Always end your statement with a semicolon ( ; ) 4. Use meaningful names → totalMarks is better than x. 5. You can change the value later, but the data type must stay the same: 👉int score = 50; score = 90; // ✅ value changed score = "Ninety"; // ❌ can’t store text in a number box 6. You can declare first and assign later: 👉int age; age = 25; 7. You can declare multiple variables together: 👉int x = 10, y = 20, z = 30; Every program you’ll ever write in Java it uses variables to store names, numbers, results, and everything in between. #Day1 #LearnJavaWithMe #Java #CodingJourney #ProgrammingMadeSimple
To view or add a comment, sign in
-
🎯 Day 15 of My Java Learning Journey 🎯 . Hey everyone! 👋 .. Today I explored Selection Statements again — but this time, I focused on finding the smallest number among four values using if-else if ladder in Java. Here’s the code I wrote 👇 --------------------------------------code start--------------------------------------- public class FindSmallerNumberDemo2 { public static void main(String[] args) { int l = 1; int m = 2; int n = 3; int o = 4; if (l < m && l < n && l < o) { System.out.println("l is smaller"); } else if (m < o && m < n && m < l) { System.out.println("m is smaller"); } else if (o < n && o < m && o < l) { System.out.println("o is smaller"); } else { System.out.println("n is smaller"); } } } --------------------------------------code output---------------------------------- l is smaller number -------------------------------------code end--------------------------------------- . 💡 Explanation: I’ve declared four integer variables — l, m, n, and o. The if statement checks multiple conditions using logical AND (&&) to make sure one number is smaller than all others. . If the first condition fails, the program moves to the next else if condition. Finally, if none of the earlier conditions are true, the else block executes — meaning the last variable n is the smallest. . 🧠 This program is a simple way to understand how comparison and logical operators work together in decision-making statements. In the next few posts, I’ll share more concepts related to selection and looping statements in Java 🚀 . #Day15 #JavaLearningJourney #100DaysOfCode #LearnJava #Programming #DevOps #Coding #JavaBeginners #SelectionStatement #IfElseInJava .
To view or add a comment, sign in
-
-
💡 My Today’s Java Learning Journey: Static Keyword and Method Overloading Today, I explored two important concepts in Java — Static Keyword and Method Overloading — both of which play a crucial role in memory management and polymorphism. ⚙️ Static Keyword in Java In Java, the static keyword is used for class members — such as static variables, static methods, and static blocks. Unlike instance members, which belong to individual objects, static members belong to the class itself. Here’s what I learned: Static Variable: Common for all objects. It helps in efficient memory utilization, since only one copy is shared among all instances. Static Block: Executes before the main method. It is mainly used to initialize static variables or to perform certain actions during class loading. Static Method: If a method’s logic is the same for all objects, declaring it as static ensures efficient memory usage and allows it to be accessed without creating an object. 📍 All static members are stored in the method area (metaspace) — previously known as PermGen. Static members can be accessed directly, while instance members can only be accessed through objects. 🧩 Method Overloading Method Overloading occurs when multiple methods have the same name but different parameters (in type, number, or order) within the same class. This helps in achieving compile-time polymorphism, also known as: Static binding Early binding Here’s how it works: When methods share the same name, the Java compiler decides which one to execute based on the method signature — i.e., the method name and parameter list. Though it looks like one method does all the work, in reality, multiple methods exist with the same name — creating the illusion of a single method handling different tasks. Overloading can also occur due to type promotion (implicit typecasting). ✅ Can we overload the main method? Yes! We can have multiple main methods with different parameter lists. However, the JVM always looks for the specific signature: public static void main(String[] args) 🔍 Key Takeaways Static members are class-level — memory-efficient and shared among all objects. Method overloading provides compile-time polymorphism, making code more readable and flexible. Understanding how static and overloading work internally helps in writing optimized and clean Java code. #Java #LearningJourney #Programming #OOPs #StaticKeyword #MethodOverloading #JavaDeveloper #Coding #CompileTimePolymorphism #EarlyBinding #SoftwareDevelopment #TechLearning
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