🕵️♂️☕ GUESS THE JAVA VERSION: CAN YOU SPOT IT? 🔸 TLDR ▪️ If you see var in Java local variables → think Java 10+ ☕🧠 🔸 THE QUIZ (GUESS BEFORE READING THE ANSWER) import java.util.*; class Example { void test() { var x = 10; var s = "hello"; var list = new ArrayList<String>(); for (var item : list) {} for (var i = 0; i < 10; i++) {} try (var r = new java.io.StringReader("")) {} } } 🔸 OPTIONS ▪️ Java 1 ▪️ Java 2 ▪️ Java 10 ▪️ Java 13 ▪️ Java 16 🔸 ANSWER ✅ Java 10 🔸 WHY? (VERY SHORT) ▪️ The giveaway is var: local-variable type inference was introduced in Java 10 (JEP 286). ▪️ You can use var for local variables, for-loop indexes, enhanced for, and try-with-resources variables (as shown here). 🔸 TAKEAWAYS ▪️ var reduces boilerplate while keeping Java statically typed ✅ ▪️ Works only for local variables (not fields / params) ▪️ Requires an initializer (no initializer = nothing to infer) ▪️ The inferred type is a real compile-time type, not “dynamic typing” #Java #Java10 #JVM #CleanCode #SoftwareEngineering #Programming #JavaDevelopers #Backend #DevTips #CodeQuality #Learning Go further with Java certification: Java👇 https://lnkd.in/eZKYX5hP Spring👇 https://lnkd.in/eADWYpfx SpringBook👇 https://lnkd.in/en7CvPmi
Vincent Vauban’s Post
More Relevant Posts
-
🕵️♂️📦 GUESS THE JAVA VERSION: STATIC IMPORT EDITION 🔸 TLDR ▪️ Static imports + autoboxing → think Java 5 🧠☕ 🔸 THE QUIZ (GUESS BEFORE READING THE ANSWER) import static java.lang.System.out; import static java.util.Arrays.asList; class Example { void test() { out.println(asList(1, 2, 3)); } } 🔸 OPTIONS ▪️ Java 5 ▪️ Java 11 🔸 ANSWER ✅ Java 5 🔸 WHY? (VERY SHORT) ▪️ import static ... was introduced in Java 5. ▪️ asList(1,2,3) also leans on autoboxing (ints → Integer) which arrived in Java 5 too. 🔸 TAKEAWAYS ▪️ Static imports let you write out.println(...) instead of System.out.println(...) ▪️ asList(1, 2, 3) becomes a List<Integer> thanks to autoboxing ✅ ▪️ Use static imports sparingly: they can hide where names come from 👀 #Java #Java5 #Programming #JVM #DevTips #CleanCode #SoftwareEngineering #Backend #JavaDevelopers Go further with Java certification: Java👇 https://lnkd.in/eZKYX5hP Spring👇 https://lnkd.in/eADWYpfx SpringBook👇 https://bit.ly/springtify JavaBook👇 https://bit.ly/jroadmap
To view or add a comment, sign in
-
-
Hi everyone 👋 Continuing the weekend Java Keyword Series with another important keyword 👇 📌 Java Keyword Series – Part 2 ✅ super keyword in Java The super keyword is used to refer to the immediate parent class object 👇 🔹 Why do we use super? To access parent class variables To call parent class methods To call the parent class constructor 🔹 Where can we use super? 1️⃣ Access parent class variable class Parent { int x = 10; } class Child extends Parent { int x = 20; void show() { System.out.println(super.x); // prints 10 } } 2️⃣ Call parent class method class Parent { void display() { System.out.println("Parent method"); } } class Child extends Parent { void display() { super.display(); // calls parent method System.out.println("Child method"); } } 3️⃣ Call parent class constructor class Parent { Parent() { System.out.println("Parent constructor"); } } class Child extends Parent { Child() { super(); // calls parent constructor } } 🔹 In simple words super is used to access or call members of the parent class. 👉 🧠 Quick Understanding super.variable → parent variable super.method() → parent method super() → parent constructor #Java #CoreJava #JavaKeywords #LearningInPublic #BackendDevelopment
To view or add a comment, sign in
-
🚀 Java 8 Complete Feature List – Day 1 of My Java 8 Series Java 8 (released in 2014) was one of the biggest upgrades in Java history. It didn’t just add features. It changed the way we write Java. With Java 8, Java officially stepped into functional programming, cleaner code, and powerful data processing. Here’s a complete list of important Java 8 features 👇 1️⃣ Lambda Expressions → Write shorter, cleaner code → Replace anonymous inner classes 2️⃣ Functional Interfaces → Single abstract method → Predicate → Function → Consumer → Supplier → UnaryOperator → BinaryOperator 3️⃣ Method References (::) → Static method reference → Instance method reference → Constructor reference 4️⃣ Stream API 🔥 → filter() → map() → reduce() → collect() → Parallel Streams 5️⃣ Default Methods in Interfaces → Method implementation inside interfaces → Backward compatibility 6️⃣ Static Methods in Interfaces 7️⃣ Optional Class → Better null handling → Avoid NullPointerException 8️⃣ New Date & Time API (java.time) → LocalDate → LocalTime → LocalDateTime → ZonedDateTime → Period & Duration 9️⃣ CompletableFuture → Asynchronous programming → Non-blocking operations 🔟 Nashorn JavaScript Engine 1️⃣1️⃣ Base64 Encoding & Decoding 1️⃣2️⃣ Repeatable & Type Annotations 1️⃣3️⃣ Collection API Enhancements → forEach() → removeIf() → replaceAll() → computeIfAbsent() → merge() 1️⃣4️⃣ Arrays.parallelSort() 1️⃣5️⃣ Concurrency Enhancements → Fork/Join improvements → StampedLock 📌 Over the next few days, I’ll break down each feature with: Real-world examples Interview-focused explanations Practical use cases If you're preparing for interviews or want to write cleaner Java code, this series will help. Follow along 🚀 #Java #Java8 #BackendDevelopment #SoftwareEngineering #Coding #InterviewPreparation #SpringBoot
To view or add a comment, sign in
-
Day 11 - What I Learned In a Day(JAVA) Today I learned that Java variables are classified into two areas and understood their scope. 1️⃣ Global Area (Instance Variable) Declared inside the class but outside methods. Accessible by all methods inside the class. Scope: Entire class. Memory is created when the object is created. 2️⃣ Local Area (Local Variable) Declared inside a method, constructor, or block. Accessible only inside that method or block. Scope: Limited to that block only. Memory is created when the method runs. Types of Variables in Java (Based on Scope): 1️⃣ Local Variable Declared inside a method. Used only inside that method. Cannot be used outside the method. 2️⃣ Non-Static Variable (Instance Variable) Declared inside the class but outside methods. Belongs to the object. Each object has its own copy. 3️⃣Static Variable Declared using static keyword. Belongs to the class. One copy is shared by all objects. Three Important Statements in Java (Variables): 1️⃣ Declaration Creating a variable. You are telling Java the type and name of the variable. No value is given. Example: int a; 2️⃣ Initialization Giving a value to a variable. The variable must already be declared. Example: a = 10; 3️⃣ Declaration + Initialization Creating the variable and giving value at the same time. Example: int a = 10; Practiced 👇 #Java #Variables #Programming #CodingJourney
To view or add a comment, sign in
-
✅ Java Features – Step 15: New String Methods (Java 11) ☕ Java 11 introduced useful additions to the String class that simplify everyday tasks. 1️⃣ isBlank() Checks if a string is empty or contains only whitespace. String s = " "; System.out.println(s.isBlank()); // true 2️⃣ strip(), stripLeading(), stripTrailing() Better Unicode-aware alternatives to trim(). String name = " Mariya "; System.out.println(name.strip()); // "Mariya" 3️⃣ repeat(int count) Repeat a string multiple times. System.out.println("Hi ".repeat(3)); // Hi Hi Hi 4️⃣ lines() Splits a string into a Stream of lines. String text = "Java\nSpring\nDocker"; text.lines().forEach(System.out::println); Why This Matters: Cleaner code Less manual string handling More expressive APIs Useful in backend data processing Small improvements, but they reduce boilerplate significantly. Next up: Java 11 – HttpClient API 🌐
To view or add a comment, sign in
-
Most Java developers use abstract classes. Few understand what they're actually enforcing. It's not just "a class you can't instantiate." It's a contract between the designer and the implementor. 🎯 What is an abstract class? A class that is intentionally *in-com-ple-te*. It defines structure and shared behavior, but delegates the specific details to its subclasses. Think of it like an architect's blueprint. The walls, doors, and rooms are defined. But the interior design? That's up to whoever builds it. 🔑 Two key rules: → You CANNOT instantiate it directly! → Subclasses MUST implement all abstract methods (or be abstract themselves) 💡 Abstract class vs Interface — when to choose? Use an abstract class when: ✅ You want to share code between closely related classes ✅ There's a clear "is-a" relationship (Dog IS-A Animal) ✅ You need constructors or shared state Use an interface when: ✅ You need to define a capability across unrelated classes ✅ You need multiple inheritance of behavior ⚡ The deeper insight: Abstract classes are the backbone of the Template Method Pattern — used heavily in Spring and JUnit. The base class defines the algorithm skeleton. Subclasses fill in the steps. That's how HttpServlet works. That's how JUnit's TestCase works. The difference between junior and senior? The junior sometimes avoids abstract classes because they seem complex. The senior reaches for them the moment they see a family of related classes sharing behavior. 👉 But wait — if you can't instantiate an abstract class... how do you actually USE one? Part 2 coming soon. 📊 Oracle Java Docs — Abstract Classes (2024): https://lnkd.in/e2E4H9RX 📊 Effective Java, 3rd Ed. — Joshua Bloch: https://lnkd.in/exH-cA-j #Java #SoftwareEngineering #OOP #BackendDevelopment #CleanCode #SpringBoot #TechLeadership
To view or add a comment, sign in
-
Stop Forgetting to Close Resources in Java 🚨 If you've worked with files, database connections, or streams in Java, you've probably written code like this: BufferedReaderbr=null; try { br=newBufferedReader(newFileReader("data.txt")); System.out.println(br.readLine()); } catch (IOExceptione) { e.printStackTrace(); } finally { if (br!=null) { br.close(); // manually closing resource } } This works... but it's easy to forget closing the resources. And may lead to memory leaks and performance issues. Enter try-with-resources(Java 7+) ✨ The try-with-resources statement is a feature introduced in Java 7 that ensures resources are automatically closed after they are no longer needed, thereby preventing resource leaks and reducing boilerplate code. 🧩Code: try (BufferedReaderbr=newBufferedReader(newFileReader("data.txt"))) { System.out.println(br.readLine()); } catch (IOExceptione) { e.printStackTrace(); } -> No finally block ->No manual closing Java automatically closes the resource after the try block finishes the execution. Why it's better ✅Less boilerplate code ✅Automatic resource cleanup ✅Safer and easier read ✅Prevents resource leaks 📌One important rule The resource must implement the AutoClosable interface. Examples: FileInputStream, BufferReader, Connection, Scanner #Java #ExceptionHandling #JavaDeveloper #CleanCode #Programming #BackendDevelopment #LearningInPublic
To view or add a comment, sign in
-
-
In the last two days, I upgraded my understanding of Interfaces in Java 🔥 📊 Interface Structure Interface can contain: ✅ Constants (public static final) ✅ Abstract methods (public abstract) ✅ Default methods (Java 8) ✅ Static methods (Java 8) 💼 Interface Basics interface ISalary { int LEAVE = 7; void paySalary(); void checkSalaryPaid(); } 🔎 Key Learning: ✔ All variables → public static final ✔ All methods → public abstract (by default) 🏢 Class + Interface Together public class ExOfInterface extends SalaryAmount implements ISalary This means: 📦 Data → From Class 📜 Rules → From Interface Java doesn’t allow multiple class inheritance, but supports multiple interfaces — avoiding the Diamond Problem. 🏦 Java 8 Upgrade – Game Changer interface IBank { void transferFund(); default void printPassbook() { } static void sendEmail() { } } Before Java 8: ❌ Only abstract methods ❌ Adding method breaks all classes After Java 8: ✅ Default methods (optional override) ✅ Static methods (utility) ✅ Backward compatibility 🧠 Realization Abstract → Mandatory rules Default → Optional common behavior Static → Utility methods Interfaces are no longer just contracts — they are powerful design tools for scalable systems 🚀 My Mentor Suresh Bishnoi Sir Huge Thanks for Him Koti Pranam My Guru🫡❤️🙏 #Java #OOPS #Java8 #Interfaces #BackendDevelopment #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Java 8 Series – Day 2 Understanding Lambda Expressions Before Java 8, writing simple logic required a lot of boilerplate code. Example: Creating a Comparator Before Java 8: Comparator comp = new Comparator() { @Override public int compare(String s1, String s2) { return s1.length() - s2.length(); } }; Too much code for a small logic, right? Now with Java 8 Lambda: Comparator comp = (s1, s2) -> s1.length() - s2.length(); One line. Same logic. Much cleaner. What is a Lambda Expression? A lambda expression is an anonymous function that: • Has no name • Has no modifier • Has no return type declaration • Can be passed as an argument It is mainly used to implement Functional Interfaces. Basic Syntax: (parameters) -> expression OR (parameters) -> { block of code } Examples: 1️⃣ No parameter () -> System.out.println("Hello") 2️⃣ Single parameter x -> x * x 3️⃣ Multiple parameters (a, b) -> a + b Why Lambda Was Introduced? • Reduce boilerplate code • Enable functional programming • Improve readability • Make collections processing powerful (Stream API) Where Are Lambdas Commonly Used? • Comparator • Runnable • Event handling • Stream API operations (filter, map, reduce) Interview Question: 1. Why can lambda be used only with Functional Interfaces? (Answer coming in Day 3 😉) In the next post, I’ll explain Functional Interfaces in depth with real interview examples. Follow the series if you're preparing for Java interviews 🚀 #Java #Java8 #Lambda #BackendDevelopment #Coding #SoftwareEngineering
To view or add a comment, sign in
-
Basic Java Questions That Every Developer Should Know 1️⃣ Why is Java not considered a pure object-oriented language? 💡 Hint: Think about primitive data types. 2️⃣ What is the difference between == and .equals() in Java? 💡 Hint: Reference vs value comparison. 3️⃣ Why is the main() method declared as static in Java? 💡 Hint: Think about how the JVM calls it. 4️⃣ What is the difference between String, StringBuilder, and StringBuffer? 💡 Hint: Mutability and thread safety. 5️⃣ Why doesn’t Java support multiple inheritance with classes? 💡 Hint: The famous Diamond Problem. 6️⃣ What is the difference between JDK, JRE, and JVM? 💡 Hint: Think about development vs execution. 7️⃣ What is the difference between ArrayList and LinkedList? 💡 Hint: Internal data structure and performance. 8️⃣ What happens if you don’t override hashCode() when you override equals()? 💡 Hint: Think about HashMap behavior. 9️⃣ What is the difference between final, finally, and finalize in Java? 💡 Hint: They belong to completely different concepts. 🔟 Why are Strings immutable in Java? 💡 Hint: Security, caching, and thread safety. 💬 Follow for more Java interview questions and system design concepts. 📩 Feel free to drop me a message if you'd like to discuss any interview question. #Java #Programming #SoftwareEngineering #InterviewPreparation #JavaDeveloper
To view or add a comment, sign in
-
More from this author
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
credits: mostlynerdless.de https://mostlynerdless.de/java-game/