Today while revising Core Java, I came across a small but interesting concept Anonymous Object ✅ class AnonymousObject { public void AnonymousObj() { System.out.println("Anonymous object practice"); } AnonymousObject() { System.out.println("In constructor"); } } public class Main { public static void main(String[] args) { new AnonymousObject().AnonymousObj(); new AnonymousObject().AnonymousObj(); } } Every time new AnonymousObject() is used, a new object is created and the constructor gets called. Simple concept, but clarity matters. 😊 #Java #CoreJava #Learning
Java Anonymous Object Creation
More Relevant Posts
-
🚀 Defining and Calling a Simple Java Method This code demonstrates how to define a simple method in Java and call it from the main method. The `addNumbers` method takes two integer arguments, calculates their sum, and prints the result to the console. Calling the method involves using its name followed by parentheses, providing the required arguments. This example illustrates the basic syntax and usage of methods in Java, emphasizing their role in encapsulating functionality. #Java #JavaDev #OOP #Backend #professional #career #development
To view or add a comment, sign in
-
-
**State of the Java ecosystem: March 2026 update** I was looking through some of my old blog posts, and I came across my post about the state of the Java ecosystem which I wrote in December 2023. I figured that now was a good time for an update. https://lnkd.in/dkUuFjPC #incusdata #programmertraining #codingmatters #java
To view or add a comment, sign in
-
-
Interfaces in Java Interfaces allow classes to define what they must do, without saying how to do it. Any class that implements an interface must provide the methods inside it. Also, one key difference: - Inheritance uses “extends” - Interfaces use “implements” Another interesting thing is that a class can implement multiple interfaces, which adds more flexibility in design. Still learning step by step and focusing on consistency. #Java #OOP #BackendDevelopment #Learning
To view or add a comment, sign in
-
-
Day 3 of revising Java fundamentals. Today I focused on understanding some important object-oriented concepts in Java. Topics revised: • Constructors • Keywords – static, final, this, super • Access modifiers and their usage • Practiced small examples to understand how these concepts work in real programs Revisiting these fundamentals is helping me strengthen my understanding of Java and object-oriented programming. Consistency over intensity — learning a little every day. #Java #CodingJourney #SoftwareDevelopment #LearningInPublic #JavaDeveloper
To view or add a comment, sign in
-
-
Hello Connections, Post 14 — Java Fundamentals A-Z This looks correct… but gives a completely wrong result 😵 Can you spot the bug? 👇 int a = 1_000_000; int b = 1_000_000; int result = a * b; System.out.println(result); // 💀 -727379968 Wait… what? 1,000,000 × 1,000,000 should be 1,000,000,000,000 right? But Java prints a negative number! 😱 Here’s what’s happening 👇 • int can store values only up to 2,147,483,647 • The result exceeds this limit • Java silently overflows and wraps around ⚠️ No error. No warning. Just wrong data. This is called integer overflow. Here’s the fix 👇 long result = (long) a * b; System.out.println(result); // ✅ 1000000000000 Post 14 Summary: 🔴 Unlearned → Assuming int is always safe for calculations 🟢 Relearned → Use long when dealing with large numbers to avoid overflow Have you ever faced this in real scenarios? Drop a ⚠️ below! Follow along for more Java & backend concepts 👇 #Java #JavaFundamentals #BackendDevelopment #LearningInPublic #SDE2
To view or add a comment, sign in
-
-
🚀 365-Day Java Challenge – Day 326 🚀 ⸻ 🔹 Day 326: Lambda Expressions and Method References Given the following code snippet: List<String> list = Arrays.asList("a", "b", "c"); list.forEach(s -> System.out.print(s.toUpperCase())); What is printed to the console when this code executes? Options: A) abc B) ABC C) a b c D) aB c
To view or add a comment, sign in
-
Unlock the power of Java Access Modifiers. Discover how these tools shape visibility in your code. Essential insights in a concise guide.
To view or add a comment, sign in
-
An immutable class in Java is one whose instances cannot be modified after creation. This ensures thread safety and consistency. To create one, declare the class as final, make fields private and final, and provide no setters. Here's an example: java public final class ImmutablePoint { private final int x; private final int y; public ImmutablePoint(int x, int y) { this.x = x; this.y = y; } public int getX() { return x; } public int getY() { return y; } } ``` #Java #ImmutableClass #Programming #SoftwareDevelopment
To view or add a comment, sign in
-
One of the most underrated skills in Java: 👉 Handling exceptions the RIGHT way. Early in my career, I used to either catch and ignore exceptions or throw them without any context. Bad idea. Over time, I realized that good exception handling is not just about fixing errors — it’s about making systems more reliable and easier to debug. Here’s what I follow now: ✔ Use meaningful exception messages ✔ Don’t swallow exceptions ✔ Log with proper context (user, request, trace) ✔ Create custom exceptions when needed ✔ Fail fast, but with clarity 💡 Insight: Users don’t care what exception occurred. They care that the system works reliably. Write code that fails well — so your system recovers better. #Java #ExceptionHandling #BestPractices #CleanCode #BackendDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
-
Hello Connections, Post 15 — Java Fundamentals A-Z This one surprises even senior developers. 😱 Can you spot the bug? 👇 public int getValue() { try { return 1; } finally { return 2; // 💀 What gets returned? } } System.out.println(getValue()); // 1 or 2? Most developers say 1. The answer is 2. 😱 finally ALWAYS runs — and overrides return! Here’s the full order 👇 public int getValue() { try { System.out.println("try"); // 1st return 1; } catch (Exception e) { System.out.println("catch"); // Only if exception } finally { System.out.println("finally"); // ALWAYS runs! 💀 // ❌ Never return from finally! } return 0; } // Output: try → finally → returns 1 ✅ Post 15 Summary: 🔴 Unlearned → finally just cleans up resources 🟢 Relearned → finally ALWAYS runs — even after return! #Java #JavaFundamentals #BackendDevelopment #LearningInPublic #SDE2 Follow along for more! 👇
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