Most Java developers use constructors. Very few truly understand 𝐰𝐡𝐚𝐭 𝐡𝐚𝐩𝐩𝐞𝐧𝐬 𝐰𝐡𝐞𝐧 𝐚𝐧 𝐨𝐛𝐣𝐞𝐜𝐭 𝐢𝐬 𝐜𝐫𝐞𝐚𝐭𝐞𝐝. When is memory allocated? When are variables initialized? Why does the order matter? And what does this actually refer to at runtime? These questions decide whether your code is reliable or fragile. Today, I published the 𝐬𝐞𝐯𝐞𝐧𝐭𝐡 𝐚𝐫𝐭𝐢𝐜𝐥𝐞 in my backend engineering series, where I break down 𝐜𝐨𝐧𝐬𝐭𝐫𝐮𝐜𝐭𝐨𝐫𝐬, 𝐨𝐛𝐣𝐞𝐜𝐭 𝐜𝐫𝐞𝐚𝐭𝐢𝐨𝐧, the 𝐭𝐡𝐢𝐬 𝐤𝐞𝐲𝐰𝐨𝐫𝐝, and 𝐢𝐧𝐢𝐭𝐢𝐚𝐥𝐢𝐳𝐚𝐭𝐢𝐨𝐧 𝐟𝐥𝐨𝐰 in Java. In this article, I cover: What object creation really means in Java How constructors actually work Why constructors have no return type What this represents at runtime Initialization order that often confuses developers Common mistakes that cause subtle backend bugs What interviewers really test around constructors This is not about syntax. It is about building the 𝐦𝐞𝐧𝐭𝐚𝐥 𝐦𝐨𝐝𝐞𝐥 behind Java’s object system. Read the article here: https://lnkd.in/gr2h9KPE If you are learning Java, preparing for backend roles, or trying to write more reliable code, this will help. Building in public. Learning in public. #SoftwareEngineering #BackendEngineering #Java #CoreJava #ObjectOrientedProgramming #LearningInPublic #CareerGrowth #Developers #EngineeringStudents
Java Constructors: What Happens When Objects Are Created
More Relevant Posts
-
So Java's a thing. It's crazy to think computers only speak in 1s and 0s, right? But we humans, we like to write programs in languages like Java - it's just easier for us to understand. And, honestly, have you ever wondered how Java code actually gets executed by machines? I mean, it's not like they can just magically read our code. There's a process, and it's pretty interesting: humans write Java code, and then - to execute it - you need the Java Development Kit, or JDK for short. It's like a translator, kinda. You save your Java file with a .java extension, like Sample.java, and if everything's good, it gets converted into a .class file, like Sample.class. Done. But here's the thing: the .java file is readable, like you can open it and see what's going on, whereas the .class file is not - it's like a secret code. And if there are errors, you'll get a heads up, with specifics, like the line number where things went wrong. It's all about communication, really - between humans and machines. Check out this resource for more info: https://lnkd.in/gZg-VmXE #JavaProgramming #Coding #SoftwareDevelopment
To view or add a comment, sign in
-
📌 Is Java 100% Object-Oriented? Let’s Clarify 👇 Many people ask whether Java is a 100% object-oriented programming language. The short answer is No — but it is very close. 🔹 Why Java is NOT 100% object-oriented? Java supports primitive data types such as int, double, char, and boolean. These primitives: Are not objects Do not belong to classes Do not have methods Because of this, Java cannot be considered fully object-oriented. 🔹 Why Java is STILL strongly object-oriented? Java follows almost all OOP principles: ✔ Encapsulation ✔ Inheritance ✔ Polymorphism ✔ Abstraction To bridge the gap between primitives and objects, Java provides Wrapper Classes (Integer, Double, Character, etc.), which allow primitives to be treated as objects when needed (e.g., collections, generics). 🔹 Comparison Insight Languages like Pure OOP languages treat everything as an object, while Java balances performance + OOP design, making it practical for real-world applications. 🎯 Conclusion: Java is not 100% object-oriented, but it is a highly object-oriented, class-based language designed for scalability, performance, and enterprise development. 💡 This concept is very important for interviews, exams, and real-world Java development. #Java #ObjectOrientedProgramming #OOP #JavaDeveloper #ProgrammingConcepts #LearningJava #SoftwareDevelopment
To view or add a comment, sign in
-
-
Most Java devs know 𝐒𝐭𝐫𝐢𝐧𝐠 𝐢𝐬 “𝐢𝐦𝐦𝐮𝐭𝐚𝐛𝐥𝐞”. But very few understand what that REALLY means… and how JVM treats it internally 👇 When you write: 𝑺𝒕𝒓𝒊𝒏𝒈 𝒔 = "𝑯𝒆𝒍𝒍𝒐"; You’re not just creating an object. You’re using something called the String Pool in the JVM. 🔹 What is String Pool? The JVM stores commonly used string values in a special memory area. So instead of creating new objects, it reuses existing ones to: ✔ Save memory ✔ Improve performance ✔ Avoid duplicate strings Example: 𝑺𝒕𝒓𝒊𝒏𝒈 𝒂 = "𝑱𝒂𝒗𝒂"; 𝑺𝒕𝒓𝒊𝒏𝒈 𝒃 = "𝑱𝒂𝒗𝒂"; Both reference the same object , But… 𝑺𝒕𝒓𝒊𝒏𝒈 𝒄 = 𝒏𝒆𝒘 𝑺𝒕𝒓𝒊𝒏𝒈("𝑱𝒂𝒗𝒂"); This forces JVM to create a new object in Heap — no reuse, extra memory. 🔥 𝐖𝐡𝐲 𝐈𝐦𝐦𝐮𝐭𝐚𝐛𝐢𝐥𝐢𝐭𝐲 𝐌𝐚𝐭𝐭𝐞𝐫𝐬 Because strings are immutable: ✔ They are thread-safe ✔ They can be cached safely ✔ They’re stable for keys in HashMap ✔ Safe for security-sensitive code ⚠️ Misuse = Performance Issues ❌ Building strings in loops with + creates tons of garbage ✔ Use StringBuilder instead If you want to really understand Java — not just syntax — follow along. I’m posting daily JVM + core Java deep dives 😊 #java #jvm #stringpool #developers #blogs
To view or add a comment, sign in
-
-
Variables in Java are not just containers for data ☕💡 They are the foundation of logic, clarity, and clean coding. In Java, variables help us: ✔️ Store information ✔️ Control program flow ✔️ Make code readable and maintainable As I always say: 👉 If you don’t understand variables clearly, advanced Java will feel confusing. Mastering variables means mastering how Java thinks and works. Strong basics today lead to confident developers tomorrow 🚀 #Java #JavaVariables #CoreJava #ProgrammingBasics #LearnJava #CodingFundamentals #DeveloperMindset #JavaTraining
To view or add a comment, sign in
-
👋 Hey Developers! Ever struggled with writing multi-line strings in Java using "\n" + … "+ … and losing your sanity? 😅 Say hello to Java Text Blocks 🎉 ✨ What are Text Blocks? Text Blocks let you write multi-line strings using """ (triple quotes), making your code cleaner, readable, and maintainable. 🧠 Important to remember: Text Blocks are still Strings — same behavior, just better syntax as i show in the image. ✅ Less escaping ✅ Better readability ✅ Perfect for JSON, SQL, HTML 👋 Catch you in the next learning post — until then, keep your code readable and your bugs minimal 😄💻 #Java #CoreJava #Java15 #CleanCode #DeveloperLearning #ProgrammingBasics
To view or add a comment, sign in
-
-
Day 17 of Mastering Backend 🔥 This is why Java 8 changed the way we write code. For a long time, we accepted extra structure as normal in Java. Even small logic needed more wrapping, more lines, more effort. Then Lambda expressions came. They didn’t change what Java can do. They changed how clearly we can write logic. One-line logic stayed one line. Functional interfaces became easy to use. Streams became easier to read. Java didn’t suddenly change. The way we expressed ideas did. Once this clicked for me, Java 8 stopped feeling like new syntax. It started feeling practical. Most developers don’t struggle with Lambdas. They struggle with letting go of the old way. If this helped you see Java 8 differently, save it for later ⭐ and share it with someone learning Java. 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴 𝗯𝗮𝗰𝗸𝗲𝗻𝗱 𝗼𝗻𝗲 𝗱𝗮𝘆 𝗮𝘁 𝗮 𝘁𝗶𝗺𝗲 𝗮𝗻𝗱 𝘀𝗵𝗮𝗿𝗶𝗻𝗴 𝗺𝘆 𝗷𝗼𝘂𝗿𝗻𝗲𝘆 𝗵𝗲𝗿𝗲 🚀 𝗜𝗳 𝘁𝗵𝗶𝘀 𝗵𝗲𝗹𝗽𝗲𝗱 𝘆𝗼𝘂 𝘀𝗲𝗲 𝗝𝗮𝘃𝗮 𝗱𝗶𝗳𝗳𝗲𝗿𝗲𝗻𝘁𝗹𝘆 & 𝗶𝗳 𝘆𝗼𝘂 𝘄𝗮𝗻𝘁 𝘁𝗼 𝗴𝗿𝗼𝘄 𝗰𝗼𝗻𝘀𝗶𝘀𝘁𝗲𝗻𝘁𝗹𝘆 𝘄𝗶𝘁𝗵 𝗺𝗲 📈📈 𝗜 𝘀𝗵𝗼𝘄 𝘂𝗽 𝗱𝗮𝗶𝗹𝘆, 𝐋𝐢𝐤𝐞 𝐚𝐧𝐝 𝐅𝐨𝐥𝐥𝐨𝐰 ❤️ 𝐇𝐚𝐩𝐩𝐲 𝐭𝐨 𝐜𝐨𝐧𝐧𝐞𝐜𝐭 𝐰𝐢𝐭𝐡 𝐞𝐧𝗴𝗶𝗻𝗲𝗲𝗿𝘀 𝐰𝐡𝗼 𝐞𝗻𝗷𝗼𝘆 𝐥𝗲𝗮𝗿𝗻𝗶𝗻𝗴, 𝐛𝐮𝗶𝗹𝗱𝗶𝗻𝗴 𝐚𝐧𝐝 𝐠𝗿𝗼𝘄𝗶𝗻𝗴 ❤️ #Java #CleanCode #BackendDevelopment #LearnInPublic #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 How Java Code Actually Runs When you write and run a Java program, it goes through several important steps before it produces output. Understanding this flow helps you write better and more efficient code. 1️⃣ **Write Source Code** You create a `.java` file containing your classes and methods. 2️⃣ **Compilation** The Java compiler (`javac`) converts your `.java` file into **bytecode**, which is stored in a `.class` file. Bytecode is **platform-independent**, which means the same file can run on any system with a JVM. 3️⃣ **Class Loading** The JVM (Java Virtual Machine) loads the bytecode into memory using the **ClassLoader subsystem**. It handles classes, interfaces, and resources needed by your program. 4️⃣ **Execution** The JVM executes the bytecode using the **JIT compiler** (Just-In-Time), which converts frequently used bytecode into native machine code for faster execution. 5️⃣ **Memory Management** JVM allocates memory for **objects in the heap** and **method calls in the stack**. Garbage collection automatically cleans up unused objects, freeing memory and preventing leaks. 💡 Key Takeaways: - Java code is **compiled to bytecode**, not machine code directly. - The JVM handles **execution and memory management**, making Java platform-independent and secure. - Understanding this flow helps you reason about performance, memory usage, and multithreading. #Java #JVM #CoreJava #BackendDevelopment #Programming
To view or add a comment, sign in
-
𝗪𝗵𝗮𝘁 "𝗩" (𝗪𝗘) 𝗟𝗲𝗮𝗿𝗻 𝗘𝗽𝗶𝘀𝗼𝗱𝗲 𝟮 𝗛𝗼𝘄 𝗝𝗮𝘃𝗮 𝗪𝗼𝗿𝗸𝘀 ? 𝗬𝗲𝘀, 𝘆𝗼𝘂 𝗵𝗮𝘃𝗲 𝘄𝗿𝗼𝘁𝗲 𝗮 𝗝𝗮𝘃𝗮 𝗖𝗼𝗱𝗲 𝘀𝗲𝘃𝗲𝗿𝗮𝗹 𝘁𝗶𝗺𝗲 𝗵𝗮𝘃𝗲 𝘆𝗼𝘂 𝗲𝘃𝗲𝗿 𝘁𝗵𝗶𝗻𝗸... • how it works ? • why, need to compile it ? • how it work on any device ? • why, it not run without main function ? • What makes java one of the top language ? These are the some Questions, which come in my mind when i started my Java Journey.... Lets figure out , how it work... 1. Write Java source code (.𝚓𝚊𝚟𝚊) 2. Compile using 𝚓𝚊𝚟𝚊𝚌 → creates bytecode (.𝚌𝚕𝚊𝚜𝚜) 3. Class Loader loads .𝚌𝚕𝚊𝚜𝚜 file into memory 4. Bytecode Verifier checks security & validity 5. JVM interprets or JIT-compiles bytecode 6. Machine code is executed 7. Output is produced Here are 𝗶𝗺𝗽𝗼𝗿𝘁𝗮𝗻𝘁 𝗝𝗮𝘃𝗮 𝗶𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗤&𝗔 𝗤𝟭. 𝗪𝗵𝘆 𝗝𝗮𝘃𝗮 𝗶𝘀 𝗽𝗹𝗮𝘁𝗳𝗼𝗿𝗺-𝗶𝗻𝗱𝗲𝗽𝗲𝗻𝗱𝗲𝗻𝘁? A. Because Java compiles into 𝗯𝘆𝘁𝗲𝗰𝗼𝗱𝗲, which runs on any 𝗝𝗩𝗠. 𝗤𝟮. 𝗪𝗵𝗮𝘁 𝗵𝗮𝗽𝗽𝗲𝗻𝘀 𝗮𝗳𝘁𝗲𝗿 𝘄𝗿𝗶𝘁𝗶𝗻𝗴 𝗝𝗮𝘃𝗮 𝗰𝗼𝗱𝗲? A. Code → Compile → Bytecode → JVM → Execution → Output. 𝗤𝟯. 𝗪𝗵𝗮𝘁 𝗶𝘀 𝗯𝘆𝘁𝗲𝗰𝗼𝗱𝗲? A. Intermediate code generated by the Java compiler. 𝗤𝟰. 𝗪𝗵𝗮𝘁 𝗶𝘀 𝗝𝗩𝗠? A. JVM executes bytecode and converts it into machine code. 𝗤𝟱. 𝗗𝗶𝗳𝗳𝗲𝗿𝗲𝗻𝗰𝗲 𝗯𝗲𝘁𝘄𝗲𝗲𝗻 𝗝𝗗𝗞 𝗮𝗻𝗱 𝗝𝗥𝗘? A. JDK = Develop + Run, JRE = Run only. 𝗤𝟲. 𝗪𝗵𝗮𝘁 𝗶𝘀 𝗝𝗜𝗧 𝗰𝗼𝗺𝗽𝗶𝗹𝗲𝗿? A. Converts frequently used bytecode into machine code for speed. 𝗤𝟳. 𝗜𝘀 𝗝𝗮𝘃𝗮 𝗰𝗼𝗺𝗽𝗶𝗹𝗲𝗱 𝗼𝗿 𝗶𝗻𝘁𝗲𝗿𝗽𝗿𝗲𝘁𝗲𝗱? A. Both — compiled to bytecode, interpreted by JVM. 𝗤𝟴. 𝗪𝗵𝗮𝘁 𝗶𝘀 𝗖𝗹𝗮𝘀𝘀 𝗟𝗼𝗮𝗱𝗲𝗿? A. Loads .𝚌𝚕𝚊𝚜𝚜 files into JVM memory. 𝗤𝟵. 𝗪𝗵𝘆 𝗯𝘆𝘁𝗲𝗰𝗼𝗱𝗲 𝘃𝗲𝗿𝗶𝗳𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗶𝘀 𝗻𝗲𝗲𝗱𝗲𝗱? A. For security and code safety. 𝗤𝟭𝟬. 𝗖𝗮𝗻 𝘄𝗲 𝗿𝘂𝗻 𝗝𝗮𝘃𝗮 𝘄𝗶𝘁𝗵𝗼𝘂𝘁 𝗝𝗩𝗠? A. No, JVM is mandatory. #Java #JavaDeveloper #SoftwareEngineering #ComputerScience #LearningInPublic #CareerGrowth #TechCommunity #ProfessionalDevelopment #DhoomBoy #Krish
To view or add a comment, sign in
-
Most Java developers write code for years without ever asking this question: How does the JVM know that a file is actually a Java class file? The answer is hidden in the first 4 bytes. Every .class file starts with a 𝐦𝐚𝐠𝐢𝐜 𝐧𝐮𝐦𝐛𝐞𝐫. 0xCAFEBABE Not a joke. Not a coincidence. A deliberate design choice. When the JVM loads a class, the very first check it performs is this: “Do the first four bytes match CAFEBABE?” If they don’t, the JVM immediately rejects the file. No bytecode parsing. No execution. No mercy. That one constant acts as a gatekeeper. It protects the JVM from: Invalid or corrupted files Random binaries Misleading inputs pretending to be bytecode In other words, before Java cares about methods, fields, or performance, it first asks a basic question: “Are you even a Java class?” What I find fascinating is what this represents philosophically. Java doesn’t assume trust. It verifies first. Even before version checks, constant pools, or instructions, the JVM demands identity. This tiny detail explains a lot about Java as a platform: Defensive by default Explicit validation Designed for long-running, safe systems Once you start noticing details like this, Java stops feeling “magical” and starts feeling intentionally engineered. Sometimes, the most important lessons are hidden in the first four bytes. #Java #JVM #Bytecode #BackendEngineering #SoftwareEngineering #ComputerScience #LearningInPublic
To view or add a comment, sign in
More from this author
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