OOPs concepts 1

OOPs concepts
Object-oriented programming (OOP) is a programming paradigm that represents concepts as “objects” that have data fields (attributes that describe the object) and associated procedures known as methods.   What is an Object? An object can be considered a “thing” that can perform a set of related activities. The set of activities that the object performs ...

Null Keys or values in HashMap/Hashtable 4

Can java.util.HashMap store null key/value pair? Yes it can, However only one null key is allowed, but can store many null values against non-null keys   Example public class HashMapTest { public static void main(String args[]) { HashMap h = new HashMap(); h.put(null,null); h.put(null, "1"); h.put("1", null); h.put("1", "1"); h.put("2", null); System.out.println(h.get(null).toString()); System.out.println(h.get("1")); System.out.println(h.get("2")); } ...

NoClassDefFoundError and ClassNotFoundException

NoClassDefFoundError and ClassNotFoundException
NoClassDefFoundError is an Error ,occurs when the source  was successfully compiled but at runtime, the required class files were not found. It may also arise when the class is already loaded in different classloader(usually a parent classloader would have loaded the class and hence the class cannot be loaded again) or if an incompatible class definition ...

Marker Interfaces

Marker interfaces are those which do not declare any required methods, but signify their compatibility with certain operations. The java.io.Serializable interface and Cloneable are typical marker interfaces. These do not contain any methods, but classes must implement this interface in order to be serialized and de-serialized.

JVM, JRE, JDK 2

JVM (Java Virtual Machine) is an abstract machine.It is a specification that  provides runtime environment in which java bytecode can be executed. JVMs are available for many hardware and software platforms (i.e. JVM is plateform dependent).   The JVM performs four main tasks: Loads code Verifies code Executes code Provides runtime environment   JRE is an acronym for ...

Error and Exceptions

Error and Exceptions
An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. An Error is represented by an object of class Error. But an error is too severe for a program to handle mostly abnormal conditions, the program must stop running. Example : ...

equals() method

When you really need to know if two references are identical, use ==. But when you need to know if the objects themselves (not the references) are equal, use the equals() method(which you may need to override).Comparing two object references using the == operator evaluates to true only when both references refer to the same ...

Dynamic and Static binding

Dynamic binding means the runtime finds the type of an object (probably from its Class<T> object) and uses that type to look for the types of methods invoked. It applies to overridden class members. And the only kind of class member you can override is an instance method.   Static binding means the compiler finds the type of ...

Difference between sleep(), suspend() and wait() 8

The question that was popped-up to us was what is the difference between suspend(), wait() and sleep() (methods of Java)? Though minute, there is a subtle difference among the three. Here’s how: sleep() is a static method that is used to send the calling thread into a non-runnable state for the given duration of time. The ...

Difference between finally and finalize

finally block is used in exception handling.   try {         //code that may or may not throw exception, goes here } catch(Exception e) {     //handling exception } finally {     //Code goes here }   The finally block executes after a section of code in a method. For example, if you have code that might ...