🌱 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
GYAN RANJAN NAYAK’s Post
More Relevant Posts
-
💡 Question: What will be the output of this Java code? public class Test { public static void main(String[] args) { Integer a = 100; Integer b = 100; Integer c = 200; Integer d = 200; System.out.println(a == b); System.out.println(c == d); } } 🤔 Think before answering. Don’t rush. Most people say the same output for both lines… and that’s where the trap is. 👇 Actual Output true false 🔥 Why this happens? (The twist) Java caches Integer objects in the range -128 to 127 a and b point to the same cached object c and d are different objects in heap memory == compares references, not values 👉 If this surprised you, imagine this bug hiding in a production system 😅 📌 Lesson for Interviews & Real Code Always use .equals() for wrapper classes Understand autoboxing, caching, and JVM internals Core Java ≠ basic Java 💬 Comment your answer before reading the explanation ❤️ Like if Java still manages to trick you after years 🔁 Repost to challenge your Java network #Java #CoreJava #JavaInterview #JVM #Programming #SoftwareEngineering #JavaDeveloper #LinkedInLearning
To view or add a comment, sign in
-
-
🌱 My Spring Journey : Singleton Class -> Single means one and ton means object -> A Java class that allows us to create only one object at any time is called a Singleton class. -> In Java programming, object creation is a costly process in terms of memory and CPU time. So, it is recommended to minimize object creation whenever possible. -> To make a Java class a perfect Singleton, we must take care of the following protections : a) Protection from multithreaded environment b) Protection from deserialization c) Protection from Reflection API d) Protection from cloning e) Protection from subclass loading -> In XML-driven configuration, we can use the scope attribute of the <bean> tag. -> In annotation-driven configuration, we can use the @Scope annotation to specify the scope. -> The IoC container does not make a Spring bean a perfect Singleton class just by using the "singleton" scope. Instead, it provides singleton behavior by creating only one object per bean definition. -> If we do not specify the scope explicitly, singleton becomes the default scope,and those objects are stored in the internal cache of the IoC container for reusability. Different types of scopes in Spring : -> singleton -> prototype -> request -> session -> application -> websocket -> If we configure a class as a Spring bean with singleton scope but define two different bean IDs, the IoC container will create two different objects, because it internally uses the Reflection API to create bean instances. #Java #SpringFramework #SpringCore #SingletonPattern #DesignPatterns #IOC #DependencyInjection #BackendDevelopment #JavaDeveloper
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
-
🚀 𝐇𝐨𝐰 𝐚 𝐉𝐚𝐯𝐚 𝐏𝐫𝐨𝐠𝐫𝐚𝐦 𝐑𝐮𝐧𝐬 – 𝐒𝐭𝐞𝐩 𝐛𝐲 𝐒𝐭𝐞𝐩 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
-
-
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
-
-
final vs finally vs finalize in Java These three look similar, but they are very different. This is a classic interview question. 🔹 final Used to restrict modification. final variable → value cannot change final method → cannot be overridden final class → cannot be inherited 👉 Used at compile time 🔹 finally Used in exception handling. Always executes Runs whether exception occurs or not Used for cleanup (closing files, DB connections) 👉 Part of try-catch-finally 🔹 finalize() Used by Garbage Collector. Called before object is destroyed Not reliable Rarely used in modern Java 👉 Managed by JVM, not developers 🧠 Quick Tip Control code → final Handle cleanup → finally JVM memory cleanup → finalize() Understanding small differences like this shows strong Core Java fundamentals. 🚀 #Java #CoreJava #JavaInterview #ProgrammingConcepts #BackendDevelopment #JavaDeveloper #LearningInPublic #DevelopersCommunity
To view or add a comment, sign in
-
-
Day 5 : Class Loader Subsystem 📚 When a Java program runs, the JVM uses the Class Loader Subsystem to load .class files into JVM memory. 🧱 Built-in Class Loaders in JVM 1. Bootstrap Class Loader : 1. Root of the class loader hierarchy 2.Part of core JVM 3. Implemented in native code (C/C++) 4. Loads core Java APIs java.lang, java.util, java.io, etc. 5. Loads classes from rt.jar (Java 8) or core modules (Java 9+). 2. Extension Class Loader : 1. Child of Bootstrap Class Loader 2.Written in Java 3.Loads extension libraries 4.Used for APIs like JDBC, Sound, etc. 5.Loads classes from: Java 8: ext directory Java 9+: Platform modules 3. Application Class Loader 1.Child of Extension/Platform Class Loader 2.Also called System Class Loader 3.Loads user-defined classes 4.Loads classes from Classpath 5.Written in Java 🔗 Linking Phase (After Loading, Before Initialization) The Linking Phase ensures the class is safe and ready to use. 1. Verification Verifies bytecode correctness Prevents malicious or corrupted code If verification fails → LinkageError 2. Preparation Allocates memory for static variables Assigns default values: int → 0 float → 0.0 boolean → false char → '\u0000' object reference → null 3. Resolution: Converts symbolic references into direct references Class names → actual memory addresses 🚀 Initialization Phase: Final phase of class loading Executes static blocks Assigns explicit values to static variables Static blocks run in the order they appear In Short : Class Loader loads → Linking verifies & prepares → Initialization executes static logic #Java #JVM #JavaInternals #JavaDeveloper #LearnJava #BackendDevelopment #Programming #SoftwareEngineering #JavaDaily #TechExplained
To view or add a comment, sign in
-
-
🔐 Java Access Modifiers Access modifiers in Java define where a class, method, or variable can be accessed, and they play a crucial role in encapsulation, security, and clean code design. In this visual, I’ve summarized all four access modifiers with clear rules and examples: 🔹 public – Accessible from anywhere (same class, same package, subclasses, and other packages). 🔹 protected – Accessible within the same package and by subclasses (supports inheritance). 🔹 default (package-private) – Accessible only within the same package. 🔹 private – Accessible only inside the same class (maximum data hiding). Each section includes: ✔ Access scope ✔ When to use it ✔ Simple Java code examples ✔ A comparison table for quick revision Understanding access modifiers is essential for writing secure, maintainable, and interview-ready Java applications. Strong fundamentals always lead to better design decisions. 🚀 #Java #CoreJava #OOPs #AccessModifiers #JavaLearning #ProgrammingConcepts #DeveloperJourney #LearningInPublic
To view or add a comment, sign in
-
-
When working with APIs or other systems that return JSON responses, you’ll often encounter date-time values in ISO 8601 format — like "2022-03-25T00:00:00.000Z". In Java, converting these strings into https://lnkd.in/gJPbf3sM
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