| Why do we need public static void main(String args[]) method in Java |
We need
If the main() was not static, you would require an instance of the class in order to execute the method. |
| What is the difference between an Interface and an Abstract class |
| In abstract class you can define as well as declare methods, the methods which are declared are to be marked as abstract. In interface all we just declare methods and the definition is provided by the class which is implementing it |
| Explain serialization |
| Serialization means storing a state of a java object by coverting it to byte stream |
| What are the rules of serialization |
| Rules: 1. Static fileds are not serialized because they are not part of any one particular object 2. Fileds from the base class are handled only if hose are serializable 3. Transient fileds are not serialized |
| What is difference between error and exception |
| Error occurs at runtime and cannot be recovered, Outofmemory is one such example. Exceptions on the other hand are due conditions which the application encounters such as FileNotFound exception or IO exceptions |
| What do you mean by object oreiented programming |
| In object oreinted programming the emphasis is more on data than on the procedure and the program is divided into objects. The data fields are hidden and they cant be accessed by external functions. The design approach is bottom up. The functions operate on data that is tied together in data structure |
| What are 4 pillars of object oreinted programming |
| 1. Abstraction It means hiding the details and only exposing the essentioal parts 2. Polymorphism Polymorphism means having many forms. In java you can see polymorphism when you have multiple methods with the same name 3. Inheritance Inheritance means the child class inherits the non private properties of the parent class 4. Encapsulation It means data hiding. In java with encapsulate the data by making it private and even we want some other class to work on that data then the setter and getter methods are provided |
| Difference between procedural and object oreinted language |
| In procedural programming the instructions are executed one after another and the data is exposed to the whole program In OOPs programming the unit of program is an object which is nothing but combination of data and code and the data is not exposed outside the object |
| What is the difference between constructor and method |
| Constructor will be automatically invoked when an object is created whereas method has to be called explicitly. |
| What is the difference between parameters and arguments |
| While defining method, variables passed in the method are called parameters. While using those methods, values passed to those variables are called arguments. |
| What is reflection in java |
| Reflection allows Java code to discover information about the fields, methods and constructors of loaded classes and to dynamically invoke them |
| What is a cloneable interface and how many methods does it contain |
| It is not having any method because it is a TAGGED or MARKER interface |
| What's the difference between a queue and a stack |
| Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule |
| Can you make an instance of abstract class |
| No you cannot create an instance of abstract class |
| What are parsers |
| Parsers are used for processing XML documents. There are 2 types of parsers DOM parser and SAX Parser |
| Difference between SAX and DOM parser |
| DOM parsers are Object based and SAX parsers are event based DOM parsers creates Tree in the memory whereas SAX parser does not and hence it is faster than DOM DOM parser are useful when we have to modify the XML, with SAX parser you cannot modify the xml, it is read only |
| What is the difference between Java Bean and Java Class |
| Basically a Bean is a java class but it has getter and setter method and it does not have any logic in it, it is used for holding data. On the other hand the Java class can have what a java bean has and also has some logic inside it |
| What are null or Marker interfaces in Java |
| The null interfaces are marker interfaces, they do not have function declarations in them, they are empty interfaces, this is to convey the compiler that they have to be treated differently |
| Does java Support multiple inheritance |
| Java does not support multiple inheritance directly like C++, because then it is prone to ambiguity, example if a class extends 2 other classes and these 2 parent classes have same method names then there is ambiguity. Hence in Java Multiple inheritance is supported using Interfaces |
| What are virtual function |
| In OOP when a derived class inherits from a base class, an object of the derived class may be referred to (or cast) as either being the base class type or the derived class type. If there are base class functions overridden by the derived class, a problem then arises when a derived object has been cast as the base class type. When a derived object is referred to as being of the base's type, the desired function call behavior is ambiguous. The distinction between virtual and not virtual is provided to solve this issue. If the function in question is designated "virtual" then the derived class's function would be called (if it exists). If it is not virtual, the base class's function would be called. |
| Does java support virtual functions |
| No java does not support virtual functions direclty like in C++, but it supports using Abstract class and interfaces |
| Describe what happens when an object is created in Java |
| Several things happen in a particular order to ensure the object is constructed properly: 1. Memory is allocated from heap to hold all instance variables and implementation-specific data of the object and its superclasses. Implemenation-specific data includes pointers to class and method data. 2. The instance variables of the objects are initialized to their default values. 3. The constructor for the most derived class is invoked. The first thing a constructor does is call the consctructor for its superclasses. This process continues until the constrcutor for java.lang.Object is called, as java.lang.Object is the base class for all objects in java. 4. Before the body of the constructor is executed, all instance variable initializers and initialization blocks are executed. Then the body of the constructor is executed. Thus, the constructor for the base class completes first and constructor for the most derived class completes last. |
| What is the purpose of System Class |
| The purpose of the system class is to provide the access to the System reources |
| What is instanceOf operator used for |
| It is used to if an object can be cast into a specific type without throwing Class cast exception |
| Why we should not have instance variable in an interface |
| Since all data fields and methods in an Interface are public by default, then we implement that interface in our class then we have public members in our class and this class will expose these data members and this is violation of encapsulation as now the data is not secure |
| What is JVM |
| When we install a java package. It contains 2 things * The Java Runtime Environment (JRE) * The Java Development Kit (JDK) The JRE provides runtime support for Java applications. The JDK provides the Java compiler and other development tools. The JDK includes the JRE. Both the JRE and the JDK include a Java Virtual Machine (JVM). This is the application that executes a Java program. A Java program requires a JVM to run on a particular platform |
| Can abstract class be final |
| No, abstract class cannot be final |
| When a new object of derived Class is created, whose constructor will be called first, childs or parents |
| Even when the new object of child class is created, first the Base class constructor gets executed and then the child classes constructor |
| What is a singleton class |
| A singleton is an object that cannot be instantiated. The restriction on the singleton is that there can be only one instance of a singleton created by the Java Virtual Machine (JVM) - by prevent direct instantiation we can ensure that developers don't create a second copy. |
| Can an abstract class have final method |
| Yes |
| Can a final class have an abstract method |
| No, the compiler will give an error |
| What is the difference between Authentication and Authorization |
| Authentication is a process for verifying that an individual is who they say they are. Authorization is an additional level of security, and it means that a particular user (usually authenticated), may have access to a particular resource say record, file, directory or script. |
Saturday, November 7, 2009
Java Basic
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment