Fresher interview questions
The JVM runs bytecode, the JRE bundles the JVM plus core libraries needed to run programs, and the JDK adds development tools such as the compiler on top of the JRE.
A class is a blueprint that describes what data and behaviour something has: what properties it holds and what it can do. An object is a real instance created from that blueprint, with its own actual values sitting in memory. For example, a Car class might define colour and speed as properties and a drive method as behaviour, while a specific red car you create with the new keyword is an object built from that plan.
The relationship is one class to many objects. From a single Car class you can create thousands of car objects, each with different colour and speed values, but all of them share the same set of properties and methods defined by the class. This separation between the general design and the many possible instances of it is the foundation of object-oriented programming, and most other Java concepts, such as constructors and inheritance, build on this idea.
A static member belongs to the class itself rather than to any single object, so there is only ever one copy of it no matter how many objects you create. You can access a static field or method through the class name directly, without creating an object first, and every object that exists shares that same copy. The main method is declared static precisely so the Java Virtual Machine can call it to start the program before any object of that class exists.
A common use for static members is a shared counter or a constant value that every instance should agree on, such as a tax rate or a maximum limit. It is worth being careful with static fields that change, however, since every part of the program reads and writes the same shared value, which can cause subtle bugs if two parts of the code update it at the same time.
The == operator checks whether two references point to the exact same object in memory, essentially asking "are these two variables pointing at the identical box." The equals() method, by contrast, checks whether two objects hold the same value, answering "do these two boxes contain the same contents," even if they are different boxes. For primitive types like int, == compares the actual values directly since there is no separate object involved.
This distinction matters most with text. Two separate String objects can contain the exact same characters, "hello" for example, yet == may return false because they are different objects in memory, while equals() correctly returns true because their contents match. As a rule, always use equals() when comparing the value of objects such as String, Integer or a custom class, and reserve == for checking whether two references genuinely point to the same instance.
An array in Java has a fixed size that is set the moment it is created and can never change afterward; to fit one more item, a new, larger array has to be created and the values copied across. An ArrayList, on the other hand, is a class from the collections framework that grows and shrinks automatically as items are added or removed, and it comes with convenient methods such as add, remove and contains that a plain array does not have.
The trade-off is that arrays are slightly more memory-efficient and can hold primitive types like int directly, while an ArrayList of integers actually stores boxed Integer objects, adding a small amount of overhead. In practice, an array fits best when the number of items is fixed and known upfront, such as the seven days of the week, and an ArrayList fits best whenever the collection might grow, shrink, or the extra convenience methods are useful, which describes most real application code.