💡 Day 24/30 — Annotations in Java: metadata that drives frameworks Today I learned how annotations add extra information to your code, and how frameworks use that information to activate behavior. [Video Link] - https://lnkd.in/ghbSkrxG 🔵 Examples we use every day @Override prevents accidental mistakes @Deprecated warns when something is unsafe @Test triggers JUnit @FunctionalInterface ensures one abstract method Annotations improve quality, safety, and tooling. 🧩 Creating your own annotation You can define custom behavior: @interface Loggable {} And then apply it: @Loggable public void process() {} A framework can scan the classpath and add: logging security checks validation caching This is how Spring Boot works internally. 🔐 Retention policy matters We decide where the annotation exists: SOURCE → only in code CLASS → in bytecode RUNTIME → available to reflection Frameworks love RUNTIME. ⭐ Key takeaway Annotations enable clean, declarative programming — you annotate your intent and let the framework do the rest. Tomorrow: Day 25 — JVM internals: how Java actually runs your code #Java #Annotations #SpringBoot #SoftwareEngineering #CleanCode #LearningChallenge
Lakshay Thakur’s Post
More Relevant Posts
-
Behind the scenes: How Java objects are created:- What happens step by step inside the JVM: The Java source code is compiled and .class files are generated. When the program runs, Animal.class and AnimalMain.class are loaded into the Method Area (Metaspace). A java.lang.Class object is created in the Heap, which holds runtime metadata of the class. JVM creates the main thread and its stack. When, new Animal() is executed: Memory is allocated in the Heap Area. All instance variables are initialized with default values (age = 0, legs = 0). The constructor is executed. A reference to the newly created object is returned. This reference is stored in the stack variable buzo. Note:- Heap → stores objects Stack → stores references and method frames Method Area / Metaspace → stores class metadata Important: ->The reference variable does not store the actual object or a memory address. ->HashCode is generated only when hashCode() is called, not during object creation. Learning Java internals makes concepts much clearer. #Java #JVM #CoreJava #ObjectOrientedProgramming #ComputerScience #objects
To view or add a comment, sign in
-
-
🌱 My Spring Journey : Understanding Spring Contexts & the .class Property in Java Difference between FileSystemXmlApplicationContext and ClassPathXmlApplicationContext : 🔹 FileSystemXmlApplicationContext → Creates the IOC container by locating the Spring bean configuration file from the specified path of the file system. → We can provide either a relative path or an absolute path. 🔹 ClassPathXmlApplicationContext : → Creates the IOC container by locating the given Spring bean configuration file from directories or JAR files added to the classpath. class property / .class property : 🔹 It is useful to get the object of java.lang.Class having the metadata of a given class or interface. Example : Class c1 = System.class; 🔹 Here, class is the static property of type java.lang.Class in the System class. 🔹 c1 is not an object of the System class, but an object of java.lang.Class that holds detailed metadata about the System class. Java Compiler adds multiple things to every class during compilation. Some of them are : 🔹 Adds java.lang.Object as the super class if the class doesn’t explicitly extend any class. 🔹 Adds a non-parameterized constructor if no constructor is defined. 🔹 Adds a static class property of type java.lang.Class, and more. #Java #SpringFramework #CoreJava #IOC #DependencyInjection #JavaDeveloper #BackendDevelopment #LearningJourney
To view or add a comment, sign in
-
5 steps to finally understand how the JVM actually executes your Java code (in a way most developers never learn) Most Java developers write thousands of lines of code… But very few truly understand how the JVM runs it under the hood. And once you learn it, many things suddenly make sense — performance, memory leaks, GC behavior, class loading issues, “why is this slow?”, everything. Here’s the simplest explanation you’ll read today 👇 1️⃣ Your Java code is first turned into bytecode (.class files) javac doesn’t create machine code. It creates bytecode, a platform-independent instruction set the JVM understands. This is why Java is “Write once, run anywhere.” 2️⃣ The ClassLoader brings your bytecode into memory When your program starts, the JVM uses class loaders to load the required classes. Think of it like: ✔ Your classes ✔ Java libraries ✔ Framework jars (Spring Boot, etc.) If something isn’t found → you get ClassNotFoundException or NoClassDefFoundError. 3️⃣ The bytecode verifier checks if your code is safe to run Before execution, JVM validates: - No illegal access - No broken bytecode - No wrong data types - No stack overflow/underflow It protects the JVM from corrupted or unsafe code. 4️⃣ The JVM interpreter begins executing bytecode line by line The JVM starts with the interpreter — slow but instant. This is why first-time execution or cold starts feel slow. 5️⃣ JIT Compiler converts “hot code” into machine code When JVM finds frequently used methods, JIT compiles them to native machine code: 🔥 Much faster execution 🔥 Stored in memory 🔥 Near C/C++ level speed after warmup This is why Java performance improves the longer the program runs. In short: Java → Bytecode → ClassLoader → Verification → Interpreter → JIT → Machine code. Understanding this flow makes you a stronger developer and helps you debug real-world issues much faster. #java #springboot #jvm #javadeveloper #backenddeveloper #softwareengineering #programmingtips #techcontent #javainterview #coding
To view or add a comment, sign in
-
-
I’ve just published an article about handling protobuf schema evolution in long-lived Java systems. When multiple protocol versions must coexist, version-specific classes tend to leak into business logic, leading to duplication and brittle code. The article describes a practical, production-tested approach to generating version-agnostic Java APIs on top of multiple protobuf schemas — without touching protobuf itself. If you work with protobuf, Java, or long-running backend systems, this might be useful.
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
-
-
🚀 𝐇𝐨𝐰 𝐚 𝐉𝐚𝐯𝐚 𝐏𝐫𝐨𝐠𝐫𝐚𝐦 𝐑𝐮𝐧𝐬 – 𝐒𝐭𝐞𝐩 𝐛𝐲 𝐒𝐭𝐞𝐩 Ever wondered what actually happens when you run a Java program? Here’s the complete flow from .java file to output 👇 🔹 1️⃣ 𝑾𝒓𝒊𝒕𝒊𝒏𝒈 𝒕𝒉𝒆 𝑷𝒓𝒐𝒈𝒓𝒂𝒎 We write Java code in a file with .java extension. This code is human-readable but not understood by the machine. 🔹 2️⃣ 𝑪𝒐𝒎𝒑𝒊𝒍𝒂𝒕𝒊𝒐𝒏 (𝒋𝒂𝒗𝒂𝒄) The Java Compiler checks the syntax and converts the .java file into a .class file. ✔️ .class file contains bytecode ✔️ Bytecode is platform-independent 🔹 3️⃣ 𝑪𝒍𝒂𝒔𝒔 𝑳𝒐𝒂𝒅𝒆𝒓 The Class Loader loads the .class file into memory. It ensures classes are loaded only once and in the correct order. 🔹 4️⃣ 𝑩𝒚𝒕𝒆𝒄𝒐𝒅𝒆 𝑽𝒆𝒓𝒊𝒇𝒊𝒄𝒂𝒕𝒊𝒐𝒏 Before execution, JVM verifies bytecode for: ✔️ Security ✔️ Memory access ✔️ Illegal code This makes Java safe and reliable. 🔹 5️⃣ 𝑬𝒙𝒆𝒄𝒖𝒕𝒊𝒐𝒏 𝒃𝒚 𝑱𝑽𝑴 The Execution Engine runs the bytecode: Interpreter executes line by line 🔹 6️⃣ 𝑶𝒖𝒕𝒑𝒖𝒕 The JVM interacts with the OS and hardware, and finally you see the output. 📌 𝗞𝗲𝘆 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆: ➤ Java is compiled once and run anywhere ➤ .class file + JVM = Platform Independence #Java #CoreJava #JVM #JavaBasics #Compilation #LearningJourney #JavaDeveloper
To view or add a comment, sign in
-
-
🚀 Java Essentials for Every Developer Whether you're prepping for interviews or brushing up, here’s a quick breakdown of key Core Java and OOP concepts: 📌Core Java: 1️⃣JDK vs JRE: JDK = Development Kit (compiler + tools), JRE = Runtime Environment (only runs code). 2️⃣Platform Independence: Java compiles to bytecode, which runs on any JVM. 3️⃣Abstract Class vs Interface: Abstract classes can have state; interfaces are contracts with no state (until Java 8+). 4️⃣final / finally / finalize: 🔹final: Constant or non-overridable. 🔹finally: Block that always executes. 🔹finalize(): Called before garbage collection. 5️⃣Stack vs Heap: 🔹Stack = method calls, primitive/local vars. 🔹Heap = objects, class instances Overloading vs Overriding: 6️⃣Overloading = same method name, different params (compile-time). 🔹Overriding = redefining inherited method (runtime). 7️⃣private vs protected: 🔹private: Class-only access. 🔹protected: Package + subclass access. 8️⃣Constructor Overloading: Multiple constructors with different parameter lists. 9️⃣super Keyword: Access parent class methods/constructors. 🔟Static: 🔹Method: Called without object. 🔹Variable: Shared across instances. 🔹Class: Nested static class. 💡 Mastering these fundamentals is key to writing clean, efficient, and maintainable Java code. #Java #Programming #OOP #SoftwareDevelopment #InterviewPrep #BackendDevelopment #Parmeshwarmetkar
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
-
👋 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
-
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