Say you create a ‘Car’ class, instantiate it, and write it out to an object stream. The flattened car object sits in the file system for some time. Meanwhile, if the ‘Car’ class is modified by adding a new field. Later on, when you try to read (i.e. deserialize) the flattened ‘Car’ object, you get […]
Category: Java Interview questions
What are the usages of Java packages?
It helps resolve naming conflicts when different packages have classes with the same names. This also helps us organize files within project. For example: java.io package do something related to I/O and java.net package do something to do with network and so on. If we tend to put all .java files into a single package, […]
What are wrapped classes?
Wrapped classes are classes that allow primitive types to be accessed as objects.
What does it mean that a method or field is “static”?
Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class. Static methods can be referenced with the name of the […]
What is a local, member and a class variable?
Variables declared within a method are “local” variables. Variables declared within the class i.e not within any methods are “member” variables (global variables). Variables declared within the class i.e not within any methods and are defined as “static” are class variables.
What modifiers are allowed for methods in an Interface?
Only public and abstract modifiers are allowed for methods in interfaces.
What is transient variable?
Transient variable can’t be serialize. For example if a variable is declared as transient in a Serializable class and the class is written to an ObjectStream, the value of the variable can’t be written to the stream instead when the class is retrieved from the ObjectStream the value of the variable becomes null
What is reflection API? How are they implemented?
Reflection is the process of introspecting the features and state of a class at runtime and dynamically manipulate at run time. This is supported using Reflection API with built-in classes like Class, Method, Fields, Constructors etc. Example: Using Java Reflection API we can get the class name, by using the getName method.
Explain working of Java Virtual Machine (JVM)?
JVM is an abstract computing machine like any other real computing machine which first converts .java file into .class file by using Compiler (.class is nothing but byte code file.) and Interpreter reads byte codes.
What are the differences between C++ and Java?
Both C++ and Java use similar syntax and are Object Oriented, but: Java does not support pointers. Pointers are inherently tricky to use and troublesome. Java does not support multiple inheritances because it causes more problems than it solves. Instead Java supports multiple interface inheritance, which allows an object to inherit many method signatures from […]