☕ Day 11 of my “Java from Scratch” Series – "Assignment Operators in Java". In Java, Assignment Operators are used to assign values to variables. We can assign values directly or perform operations and assign them in short form. 1. 🔹 = (Simple Assignment) Assigns a value to a variable. 📘 Example: int a = 5; int b = a; Here, the value 5 is assigned to a, and the value of a is assigned to b. 2. 🔹 += (Add and Assign) Short way to write a = a + value 📘 Example: int a = 3; a += 3; ✅ Result: a = 3 + 3 => a = 6 3. 🔹 -= (Subtract and Assign) Short way to write a = a - value 📘 Example: int a = 10; a -= 3; ✅ Result: a = 10 - 3 => a = 7 4. 🔹 *= (Multiply and Assign) Short way to write a = a * value 📘 Example: int a = 10; a *= 3; ✅ Result: a = 10 * 3 => a = 30 5. 🔹 /= (Divide and Assign) Short way to write a = a / value 📘 Example: int a = 10; a /= 5; ✅ Result: a = 10 / 5 => a = 2 (Quotient) 6. 🔹 %= (Modulo and Assign) Short way to write a = a % value 📘 Example: int a = 10; a %= 5; ✅ Result: a = 10 % 5 => a = 0 (Remainder) 💡 In short: Assignment operators make your code cleaner, shorter, and easier to read. 👉 Which assignment operator do you use most often in your code? Comment below! 👇 #Java #Programming #Coding #JavaDeveloper #Learning #SoftwareEngineering #JavaFromScratch #InterviewQuestions #Developers #AssignmentOperatorsInJava #Tech #NeverGiveUp
"Java from Scratch: Assignment Operators Explained"
More Relevant Posts
-
⚙️ Java Multithreading: Run Multiple Tasks at the Same Time Multithreading is what gives Java the power to handle multiple operations concurrently making your applications faster, more responsive, and efficient. Here’s what you’ll learn in this guide: 🧠 What Is Multithreading? → Learn how multiple threads share memory but execute independently for improved performance. 💡 Creating Threads (2 Ways) → Extend the Thread class or implement the Runnable interface — both lead to parallel execution. 🚀 Starting Threads → Always use start() to launch a new thread; calling run() directly won’t create concurrency. 🔄 Thread Lifecycle → Understand thread states — New, Runnable, Running, Waiting, and Terminated. ⚙️ Key Thread Methods → Control execution using sleep(), join(), isAlive(), and setPriority(). 🔐 Synchronization → Prevent race conditions by locking shared resources with the synchronized keyword. 📈 Benefits of Multithreading → Maximize CPU usage, handle I/O and computation together, and deliver high-performing apps. 🎯 Interview Prep → Master differences between Thread vs Runnable, and key methods like join() and synchronized. 📌 Like, Save & Follow CRIO.DO for more advanced Java lessons made simple. 💻 Learn Java by Doing, Not Just Watching At CRIO.DO, you’ll master multithreading, synchronization, and concurrency by building real backend systems from scratch. 🚀 Join your FREE trial today - https://lnkd.in/e5UETdzC and start coding projects that perform like pros! #Java #Multithreading #CrioDo #LearnCoding #SoftwareDevelopment #Concurrency #BackendEngineering #JavaThreads #OOP #JavaInterview
To view or add a comment, sign in
-
☕ 5 Interesting Core Java Concepts Most Developers Overlook 🚀 Even after years with Java, it still surprises us with small gems 💎 Here are a few underrated but powerful features 👇 1️⃣ String Interning String a = "Java"; String b = new String("Java"); System.out.println(a == b.intern()); // true ✅ 👉 Saves memory by storing one copy of each unique string literal. 2️⃣ Transient Keyword Prevents certain fields from being serialized. Perfect for sensitive info like passwords 🔒 class User implements Serializable { transient String password; } 3️⃣ Volatile Keyword Used in multithreading — ensures visibility across threads 🔁 volatile boolean flag = true; 4️⃣ Static Block Execution Order Static blocks run once — before the main method! static { System.out.println("Loaded before main!"); } 5️⃣ Shutdown Hook Run cleanup code before JVM exits gracefully 🧹 Runtime.getRuntime().addShutdownHook(new Thread(() -> System.out.println("Cleaning up before exit...") )); --- 💡 Pro Tip: > “Mastering Java isn’t about writing code faster — it’s about knowing what’s happening behind the scenes.” 🧠 👉 Question: Which one of these did you know already? Or got you saying “Wait… what? 😅” #Java #CoreJava #ProgrammingTips #CleanCode #SoftwareDevelopment #LearningInPublic #CodeBetter #JavaDeveloper #CodingJourney #TechTips #springboot #backend #developers #JavaProgramm
To view or add a comment, sign in
-
🚀 Java Tip of the Day: "Collection" vs "Collections" — Know the Difference! If you’ve ever mixed these two up in interviews or code reviews — you’re not alone 😅 Here’s the quick breakdown: ✅ Collection (Interface) → Part of the java.util package, it’s the root interface for List, Set, and Queue. Think of it as the blueprint that defines how groups of objects are handled. ✅ Collections (Class) → A utility class in java.util package that provides static methods to operate on collections — like sorting, searching, or synchronizing them. 👉 Example: Collections.sort(list); // Using Collections class Collection<String> names; // Using Collection interface In short: Collection = Framework’s foundation Collections = Toolkit for manipulating data 💬 What’s your favorite Collections method you use often? Drop it in the comments 👇 #Java #CodingTips #InterviewPreparation #Developers #Programming #SpringBoot #ReactJS #SoftwareEngineering
To view or add a comment, sign in
-
☕ Day 13 of my “Java from Scratch” Series – “Unary Operators in Java” Unary operators are the ones that work on a single operand (variable). They’re used to change the sign, increase/decrease a value, or reverse a boolean condition. 1️⃣ +a 2️⃣ -a → if a = 5, -a will be -5 3️⃣ ! → if a = true, !a will be false 4️⃣ Increment operator (++) → increases the value by 1. a. Post increment: first the operation will be performed and then the value will be increased. 📘 Example: int a = 20; int b = a++; ✅ Result: b = 20, a = 21 b. Pre increment: first the value will be increased and then the operation will be performed. 📘 Example: int a = 20; int b = ++a; ✅ Result: a = 21, b = 21 5️⃣ Decrement operator (--) → decreases the value by 1. a. Post decrement: first the operation will be performed and then the value will be decremented. 📘 Example: int a = 20; int b = a--; ✅ Result: b = 20, a = 19 b. Pre decrement: first the value will be decremented and then the operation will be performed. 📘 Example: int a = 20; int b = --a; ✅ Result: a = 19, b = 19 💡 In short: Unary operators act on one operand to either change its value or its sign. 👉 Which one do you find tricky — pre or post increment? Comment below 👇 #Java #Programming #Coding #Tech #JavaDeveloper #SoftwareEngineering #Learning #Developers #UnaryOperatorsInJava #JavaFromScratch #NeverGiveUp
To view or add a comment, sign in
-
💥 Java Gotcha Alert! 💥 Ever tried removing items from an ArrayList while looping... and BOOM – ConcurrentModificationException? 😱 You're not alone – it's a classic trap! Let's fix it forever. 🚀 #Code List<String> list = new ArrayList<>(Arrays.asList("a", "b", "c")); for (String s : list) { if (s.equals("b")) { list.remove(s); // 💥 CRASH! } } Why? For-each loops use a fail-fast iterator. It detects changes (like remove()) and throws an exception to prevent bugs. 🛠️ EASY FIXES (Pick your favorite!) : 1️⃣ Super Simple: removeIf() (Java 8+) ⭐ list.removeIf(s -> s.equals("b")); // ✅ [a, c] 2️⃣ Iterator Magic Iterator<String> it = list.iterator(); while (it.hasNext()) { if (it.next().equals("b")) { it.remove(); // ✅ Safe! } } **🎯 PRO TIPS** ✅ **Always** use these over direct `remove()` in loops. 🔒 Multi-threaded? Switch to `CopyOnWriteArrayList`. 💡 Collect to-remove items → `removeAll()` for complex cases. #Java #Programming #CodingTips #SoftwareDevelopment #Tech #JavaProgramming #SoftwareEngineering #Coding #Developer #TechTips #ProgrammingLife #CodeNewbie #LearnToCode #JavaDeveloper #BackendDevelopment #CodingCommunity #TechTutorials #SoftwareDev #ProgrammingTutorials #CodeLife #TechCareer #DeveloperLife #JavaCode #LearnProgramming
To view or add a comment, sign in
-
🚀 Constructors (Java) A constructor is a special method in a class that is automatically called when an object of that class is created. Its purpose is to initialize the object's state, setting initial values for its attributes. Constructors have the same name as the class and do not have a return type. If you don't define a constructor, Java provides a default constructor with no arguments. Constructors ensure that objects are properly initialized before they are used. #Java #JavaDev #OOP #Backend #professional #career #development
To view or add a comment, sign in
-
-
☕ Day 17 of my “Java from Scratch” Series — “Switch Statement in Java” Switch statements work just like if-else statements, but they are used when we have multiple conditions to check. 🔹 Syntax: switch (expression) { case expression1: statement; break; case expression2: statement; break; default: statement; } 📘 Example: switch(2) { case 1: System.out.println("1"); break; case 2: System.out.println("2"); break; default: System.out.println("3"); } ✅ Result: 2 ⚠️ Important Points: 1. We must use break after each case. If we don’t, the next cases will also execute (this is called fall-through). 2. We don’t need break for the default case since it is the last case. 3. Even if default is written in between, it will be executed only if no cases match, but then we should use break. 5. Keeping default at last is the best practice ✅ 🚫 What Switch does not accept: 1. boolean values 2. logical operators (&&, ||, !) 3. nested case statements #Java #Programming #Coding #SoftwareDeveloper #JavaFromScratch #Learning #SoftwareEngineering #Developers #Tech #SwitchCaseInJava #NeverGiveUp
To view or add a comment, sign in
-
🚀 Converting Strings to Character Arrays and Vice Versa (Java) Java allows you to convert a String to a character array using the `toCharArray()` method. This is useful when you need to access or manipulate individual characters of the string. Conversely, you can create a String from a character array using the String constructor. These conversions enable you to perform character-level operations on strings and create new strings from character data. Learn more on our website: https://techielearns.com #Java #JavaDev #OOP #Backend #professional #career #development
To view or add a comment, sign in
-
-
🧵 Inter-Thread Communication in Java: How Threads Talk to Each Other. Here’s what you’ll master in this guide: ▪️ What Is Inter-Thread Communication? → A mechanism that lets threads work together instead of competing — essential for smooth concurrency. ▪️ wait() Method → Puts a thread to sleep and releases its lock until another thread signals it to resume. ▪️ notify() Method → Wakes one waiting thread on the same object, letting it continue execution. ▪️ notifyAll() Method → Wakes all threads waiting on the same object, which then compete to acquire the lock. ▪️ Synchronization Rule → All three methods must be used inside a synchronized block or method to avoid race conditions. ▪️ Producer-Consumer Example → Learn the classic synchronization pattern where one thread produces data and another consumes it efficiently. ▪️ Common Pitfalls → Forgetting synchronized, mishandling InterruptedException, or overusing notifyAll() can cause tricky bugs. ▪️ Interview Q&A → Understand real-world scenarios, timing issues (notify before wait), and why inter-thread communication underpins modern concurrent systems. Mastering inter-thread communication helps you write safe, high-performance, and scalable multithreaded Java applications. 📌 Like, Save & Follow CRIO.DO to learn Java from real-world use cases, not just theory. 💻 Build Hands-On Multithreaded Projects At CRIO.DO, you’ll implement producer-consumer systems, thread pools, and synchronization models by coding them yourself the way real engineers learn. 🚀 Start your FREE trial today - https://lnkd.in/gyFgTGUw and learn to build concurrency the right way! #Java #Multithreading #InterThreadCommunication #CrioDo #LearnCoding #Concurrency #ProducerConsumer #SoftwareDevelopment #JavaInterview #BackendEngineering
To view or add a comment, sign in
-
Java Tricky Question Most developers think they know what finally does… until they see this. What do you think this program prints? class Test { public static void main(String[] args) { System.out.println(test()); } static int test() { try { return 10; } finally { return 20; } } } Hint: finally always executes but does it override the value returned from try? #Java #CodingChallenge #Developers #ProgrammingPuzzle #JavaTrickyQuestions #LearnJava #BackendDeveloper
To view or add a comment, sign in
-
Explore related topics
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