You are on page 1of 14

Object Oriented Programming Viva Questions. Q1. What is a class? A.

A class is a template for an object, a user-defined data type that contains variables, properties, andmethods. A class defines the abstract characteristics of a thing (object), including its characteristics (its attributes operations or features). One might say that a class is a blueprint or factory that describes thenature of something Q2. What is an instance? A. The instance of a class is the actual object created at run-time. Q3. What is a method? A. Method is a set of procedural statements for achieving the desired result. It performs different kinds of operations on different data types. In a programming language, methods (sometimes referred to as "functions") are verbs. Q4. What is an object? A. Objects can be thought of as wrapping the data within a set of functions designed to ensure that the data is used appropriately, and to assist in that use. Q5. What is Object Oriented Programming Paradigm? A. Object Oriented Paradigm is a programming paradigm that uses Objects to design applications and computer programs, it models the real world. This includes some unique concepts which overcome the drawbacks of other programming paradigms. In OOP, the emphasis is on data and not on procedures. C++ is a programming language which obeys OOP features. Q6. What are the general features of OOP? A. General Features of OOP Programming: Object Classes Data Abstraction Data Encapsulation Inheritance Modularity Polymorphism Message Passing Dynamic Binding Q7. What are the three OOP principles? A. The three principles of OOP are as follows: 1. Encapsualtion 2. Inheritance 3. Polymorphism 8. What is Abstraction? A. Abstraction is a way to remove the association of the behavior of an object with the actual details behind the scenes which implement that object's behavior. Q9. What is Encapsulation? A. Encapsulation conceals the functional details of a class from objects that send messages to it. It is a process that facilitates the bundling of data with the methods operating on that data.[ Q10. What is Inheritance? A. In object-oriented programming (OOP), inheritance is a way to compartmentalize and reuse code by creating collections of attributes and behaviors called objects which can be based on previously created objects. Q11. What is a Super-class? A. A superclass, base class, or parent class is a class from which other classes are derived. Q12. What is a Sub-class? A. The classes that are derived from a super class are known as child classes, derived classes, or subclasses. Q13. What is a Virtual Function? A. In object oriented programming, a virtual function or virtual method is a function or method whose behavior can be overridden within an inheriting class by a function with the same signature. Q14. What is the use of Virtual functions? A. 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 methods overridden by the derived class, the method call behavior is ambiguous. The distinction between virtual and not virtual resolves this ambiguity. If the function in question is designated "virtual" in the base class 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. Q15. What is overriding? A. Many object-oriented programming languages permit a class or object to replace the implementation of an aspect typically a behavior that it has inherited. This process is usually called overriding Q16. What is Polymorphism?

A. In object-oriented programming, polymorphism (from the Greek meaning "having multiple forms") is the characteristic of being able to assign a different meaning or usage to something in different contexts - specifically, to allow an entity such as a variable, a function, or an object to have more than one form. Q17. What are the different types of Polymorphism? A. There are 2 types of Polymorphism. They are, 1. Compile time polymorphism 2. Run time polymorphism. Q18. How is compile time polymorphism achieved? A. Compile time polymorphism is achieved using Function over-loading and operating over-loading. Q19. How is run-time polymorphism achieved? A. Run-time polymorphism is achieved using over-riding. Q20. What is function overloading? A. Function overloading or method overloading is a feature found in various programming languages that allows the creation of several methods with the same name which differ from each other in terms of the type of the input and the type of the output of the function. Q21. What is operator overloading? A. Operator overloading is a specific case of polymorphism in which some or all of operators like +, =, or == have different implementations depending on the types of their arguments. Q22. What is method overriding? A. Method overriding, in object oriented programming , is a language feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes. The implementation in the subclass overrides (replaces) the implementation in the superclass by providing a method that has same name, same parameters or signature, and same return type as the method in the parent class.[1] The version of a method that is executed will be determined by the object that is used to invoke it. If an object of a parent class is used to invoke the method, then the version in the parent class will be executed, or If an object of the subclass is used to invoke the method, then the version in the child class will be executed Q23. What is Java? A. Java language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture. Java is a general-purpose, concurrent, class-based, object-oriented language that is specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere". Java is currently one of the most popular programming languages in use, and is widely used from application software to web applications. Q24. What are Java Buzzwords? A. The java buzzwords are: .Simple Secure Portable Object-oriented Robust Multithreaded Architecture- neutral Interpreted Highperformance Distributed Dynamic Q25. What are the Data types in java and explain their default values? The following table shows the default values for the data types: Keyword Description Size/Format Byte Byte-length integer 8-bit two's complement hort Short integer 16-bit two's complement Int Integer 32-bit two's complement long Long integer 64-bit two's complement Float Single-precision floating point 32-bit IEEE double Double-precision floating point

64-bit IEEE char A single character 16-bit Unicode character boolean A boolean value (true or false) true or false Q26. What is an Access modifier? A. The access to classes, constructors, methods and fields are regulated using access modifiers i.e. aclass can control what information or data can be accessible by other classes. To take advantage of encapsulation, you should minimize access whenever possible. Q26. What are the different types of Access modifier in javas? Java provides a number of access modifiers to help you set the level of access you want for classes as well as the fields, methods and constructors in your classes. A member has package or default accessibility when no accessibility modifier is specified. Access Modifiers 1. private 2. protected 3. default 4. public Q27. What is Public Access Modifier? A. Fields, methods and constructors declared public (least restrictive) within a public class are visible to any class in the Java program, whether these classes are in the same package or in another package. Q28. What is Private Access Modifier? A. The private (most restrictive) fields or methods cannot be used for classes and Interfaces. It also cannot be used for fields and methods within an interface. Fields, methods or constructors declared private are strictly controlled, which means they cannot be accesses by anywhere outside the enclosing class. A standard design strategy is to make all fields private and provide public getter methods formthem. Q29. What is Protected Access Modifier? A. The protected fields or methods cannot be used for classes and Interfaces. It also cannot be used for fields and methods within an interface. Fields, methods and constructors declared protected in a superclass can be accessed only by subclasses in other packages. Classes in the same package can also access protected fields, methods and constructors as well, even if they are not a subclass of the protected member s class. Q30. What is a Constructor? A. A constructor (sometimes shortened to ctor) in a class is a special type of subroutine called at the creation of an object. It prepares the new object for use, often accepting parameters which the constructor uses to set any member variables required when the object is first created. A constructor resembles an instance method, but it differs from a method in that it never has an explicit return-type. Q31. What are the functions of a Constructor in java? A. It initializes the class variables to default values. (Byte, short, int, long, float, and double variables default to their respective zero values, booleans to false, chars to the null character ('\u0000') and references of any objects to null.) It then calls the super class constructor (default constructor of super class only if no constructor is defined). It then initializes the class variables to the specified values like ex: int var = 10; or float var = 10.0f and so on. It then executes the body of the constructor. Q32. What is the difference between a constructor and a normal function? A. In Java, some of the differences between other methods and constructors are: Constructors never have an explicit return type. Constructors cannot be directly invoked (the keyword new must be used). Constructors cannot be synchronized, final, abstract, native, or static. Constructors are always executed by the same thread. Q33.What is a Destructor? A. A destructor (sometimes shortened to dtor) is a method which is automatically invoked when the object is destroyed. Its main purpose is to clean up and to free the resources (which includes closing database connections, releasing network resources, relinquishing resource locks, etc.) which were

acquired by the object along its life cycle and unlink it from other objects or resources invalidating any references in the process. Q34. What is a Finalizer? A. Unlike destructors, finalizers are usually not deterministic. A destructor is run when the program explicitly frees an object. In contrast, a finalizer is executed when the internal garbage collection system frees the object. Q35. What is an inline function in C++? A. The idea behind inline functions is to insert the code of a called function at the point where the function is called. If done carefully, this can improve the application's performance in exchange for increased compile time and possibly (but not always) an increase in the size of the generated binary executables. Q36. What are the different types of access specifiers in C++? A. Public, protected and private are three access specifier in C++. Public data members and member functions are accessible outside the class. Protected data members and member functions are only available to derived classes. Private data members and member functions can t be accessed outside the class. However there is an exception can be using friend classes. Q37. What is a template in c++? A. Templates allow to create generic functions that admit any data type as parameters and return value without having to overload the function with all the possible data types. Until certain point they fulfill the functionality of a macro. Its prototype is any of the two following ones: template <class identifier> function_declaration; template <typename indetifier> function_declaration; The only difference between both prototypes is the use of keyword class or typename, its use is indistinct since both expressions have exactly the same meaning and behave exactly the same way. Q38. What is the difference between class and a structure? A. Structure: Initially (in C) a structure was used to bundle different type of data types together to perform a particular functionality. But C++ extended the structure to contain functions also. The major difference is that all declarations inside a structure are by default public. Class: Class is a successor of Structure. By default all the members inside the class are private. Q39. What is a friend class? A. Friend classes are used when two or more classes are designed to work together and need access to each other's implementation in ways that the rest of the world shouldn't be allowed to have. Q40. What is a friend function? A.As the name suggests, the function acts as a friend to a class. As a friend of a class, it can access its private and protected members. A friend function is not a member of the class. But it must be listed in the class definition. Q41.What is scope resolution operator? A.A scope resolution operator (::), can be used to define the member functions of a class outside the class. Q42.What is an Interface? A. In the Java programming language, an interface is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated they can only be implemented by classes or extended by other interfaces. Q43. What is the major need for interfaces in java? A. One benefit of using interfaces is that they simulate multiple inheritance. All classes in Java must have exactly one base class; multiple inheritance of classes is not allowed. Furthermore, a Java class may implement, and an interface may extend any number of interfaces; however an interface may not implement an interface. Q44. Can an interface be instantiated? A. No, an interface cannot be instantiated but the class which implements the interface can be instantiated. Q45. What is an abstract class? A. Java Abstract classes are used to declare common characteristics of subclasses. An abstract class cannot be instantiated. It can only be used as a superclass for other classes that extend the abstract class. Abstract classes are declared with the abstract keyword. Abstract classes are used to provide a template or design for concrete subclasses down the inheritance tree. Q46. What is the use of static keyword? A. When a member is declared static, it can be accessed before any objects of its class are created, and without reference to any object.

Q47. Can variables be declared as static? A. Yes variables as well as the methods can be declared static . Q48. What restrictions do static methods have? A. Methods declared as static have several restrictions: They can only call other static methods. They must access only static data. They cannot refer to this or super in anyway. Q49.What is a Package? A. A Java package is a mechanism for organizing Java classes into namespaces. Programmers also typically use packages to organize classes belonging to the same category or providing similar functionality. A package provides a unique namespace for the types it contains. Classes in the same package can access each other's package-access members. Q50. What is the use of super keyword in java? A. Super keyword is used to call immediate parent. Super keyword can be used with instance members i.e., instance variables and instance methods. Super keyword can be used within constructor to call the constructor of parent class. Q51.What is final? A. * Java classes declared as final cannot be extended. Restricting inheritance! * Methods declared as final cannot be overridden. In methods private is equal to final, but in variables it is not. * Final parameters values of the parameters cannot be changed after initialization. Q52.What is a blank final variable? A.A variable that is declared as final and not initialized is called a blank final variable. A blank final variable forces the constructors to initialize it. Q53.What is an Exception? A. An exception is a problem that arises during the execution of a program. An exception can occur for many different reasons, including the following: A user has entered invalid data. A file that needs to be opened cannot be found. A network connection has been lost in the middle of communications, or the JVM has run out of memory. Some of these exceptions are caused by user error, others by programmer error, and others by physical resources that have failed in some manner. Q54.What are the three categories of Exceptions? A. The three categories of exceptions are: Checked exceptions: A checked exception is an exception that is typically a user error or a problem that cannot be foreseen by the programmer. For example, if a file is to be opened, but the file cannot be found, an exception occurs. These exceptions cannot simply be ignored at the time of compilation. Runtime exceptions: A runtime exception is an exception that occurs that probably could have been avoided by the programmer. As opposed to checked exceptions, runtime exceptions are ignored at the time of compilation. Errors: These are not exceptions at all, but problems that arise beyond the control of the user or the programmer. Errors are typically ignored in your code because you can rarely do anything about an error. For example, if a stack overflow occurs, an error will arise. They are also ignored at the time of compilation. Q55.What is Exception hierarchy? A. All exception classes are subtypes of the java.lang.Exception class. The exception class is a subclass of the Throwable class. Other than the exception class there is another subclass called Error which is derived from the Throwable class. Errors are not normally trapped form the Java programs. These conditions normally happen in case of severe failures, which are not handled by the java programs. Errors are generated to indicate errors generated by the runtime environment. Example : JVM is out of Memory. Normally programs cannot recover from errors. The Exception class has two main subclasses : IOException class and RuntimeException Class. Q56. What is the role of try in Exception Handling? A. A method catches an exception using a combination of the try and catch keywords. A try/catch block is placed around the code that might generate an exception. Code within a try/catch block is referred to

as protected code. Q57. What is the role of catch in Exception Handling? A. A catch statement involves declaring the type of exception you are trying to catch. If an exception occurs in protected code, the catch block (or blocks) that follow the try is checked. If the type of exception that occurred is listed in a catch block, the exception is passed to the catch block much as an argument is passed into a method parameter. Q58.What is the role of throw statement? A: Throw statement is used to throw an exception explicitly. The throw statement requires a single argument: a throwable object. Ex: throw someThrowableObject; Q59. What is the role of throws statement? Ans: throws is used to tell the compiler the method might through mentioned type of exception. Q60. What is the role of finally keyword in Exception Handling? A. The finally Keyword The finally keyword is used to create a block of code that follows a try block. A finally block of code always executes, whether or not an exception has occurred. Using a finally block allows you to run any cleanup-type statements that you want to execute, no matter what happens in the protected code. Q61. What is a thread? A. Any application that runs in a continuous mode is a thread. Each thread defines a separate path of execution. A thread is a light-weight process. Q62. Thread class implements Runnable interface. Q63. How do I create my own thread class? A. We can create our own thread class in two ways. One is by implementing the runnable interface and the other is by extending the predefined Thread class. Q64.What is Multi-Threading? A. Java provides built-in support for Multi-Threaded programming. A multi-threaded program contains two or more parts that can run concurrently. Q65. Does C++ have built-in multithreading support? A. No Q66. What are the advantages of Multithreading? A. There are various reasons for the popularity of multithreaded programming. One reason for this is that multithreading enables a program to make the best use of available CPU cycles, thus allowing very efficient programs to be written. Another reason is that multithreading is a natural choice for handling event-driven code, which is so common in today s highly distributed, networked, GUI-based environments. Q67. What are the differences between multithreading and multitasking? A. multitasking infers the mechanism to run many processes simultaneously with user interaction. In contrast, multithreading is a mechanism of running various threads under single process within its own space. Q68. What is a process? A. A program that is executing in known as a process. Q69. What is the life cycle of Thread? A. 1. When the thread create New State 2. After start () Runnable state 3. Running State 4. Wait/Block/Sleep State 5. Dead State Q70. How do you prioritize threads in java? A. By using the methods defined in thread class. The methods are: MAX_PRIORITY : The maximum priority that a thread can have. MIN_PRIORITY : The minimum priority that a thread can have. NORM_PRIORITY: The default priority that is assigned to a thread. Q71. What is synchronization and why is it important? A. With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object's value. This often leads to significant errors.

Q72. What is main thread? A. Every Java program has one thread, even if you don t create any threads explicitly. This thread is called the main thread because it is the thread that executes when you start the main program. Q73. Which thread is the one that finishes execution last? A. The main thread is always the last thread to finish executing because typically the main thread needs to release a resource used by the program such as network connections. Q74. What is a monitor? A.A Monitor is an object that is used as mutually exclusive lock or mutex. Only one thread can own a given monitor at a given time. Q75. What is a Wrapper class? A. Wrapper class is a wrapper around a primitive data type. It represents primitive data types in their corresponding class instances e.g. a boolean data type can be represented as a Boolean class instance. All of the primitive wrapper classes in Java are immutable i.e. once assigned a value to a wrapper class instance cannot be changed further. Q76. What are the features of a wrapper class? A. Features of the Wrapper Classes Some of the sound features maintained by the Wrapper Classes are as under: All the methods of the wrapper classes are static. The Wrapper class does not contain constructors. Once a value is assigned to a wrapper class instance it can not be changed, anymore. Q77. What is an Adapter class? A. Adapter class provides an empty implementation of all the methods in EventListener interface. Q78. What is the use of an Adapter class? A. Most commonly an adapter is used to help you rapidly construct your own Listener class to field events. By extending an adapter class, with KeyAdapter, FocusAdapter, WindowAdapter etc. you don t have to write methods for events you are not interested in handling. Q79. What is an inner-class? A. In Java it is possible to define one class inside another. A class defined inside another one is called an inner class. Q80. What are the rules of inner-classes? A. Inner classes cannot have static members. only static final variables. Interfaces are never inner. Static classes are not inner classes. Inner classes may inherit static members that are not compile-time constants even though they may not declare them. Q81.What is an applet? A. An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a page. When you use a Java technology-enabled browser to view a page that contains an applet, the applet's code is transferred to your system and executed by the browser's Java Virtual Machine (JVM). Q82. What are the methods of Applets life cycle? A. Applet runs in the browser and its lifecycle method are called by JVM when it is loaded and destroyed. Here are the lifecycle methods of an Applet: init(): This method is called to initialized an applet start(): This method is called after the initialization of the applet. stop(): This method can be called multiple times in the life cycle of an Applet. destroy(): This method is called only once in the life cycle of the applet when applet is destroyed. Q83. What is Garbage collection? A. The JVM's heap stores all objects created by an executing Java program. Objects are created by Java's "new" operator, and memory for new objects is allocated on the heap at run time. Garbage collection is the process of automatically freeing objects that are no longer referenced by the program. This frees the programmer from having to keep track of when to free allocated memory, thereby preventing many potential bugs. Q84. What is the need for Garbage-Collection? A. Garbage collection relieves programmers from the burden of freeing allocated memory. Knowing when to explicitly free allocated memory can be very tricky. Giving this job to the JVM has several advantages. Q85. What is Event-driven programming? A. Event-driven programming or event-based programming is a programming paradigm in which the

flow of the program is determined by events i.e., sensor outputs or user actions (mouse clicks, key presses) or messages from other programs or threads. Q86. Describe an event model? A. The event model is quite powerful and flexible. Any number of event listener objects can listen for all kinds of events from any number of event source objects. For example, a program might create one listener per event source. Or a program might have a single listener for all events from all sources. A program can even have more than one listener for a single kind of event from a single event source. Multiple listeners can register to be notified of events of a particular type from a particular source. Also, the same listener can listen to notifications from different objects. Q87. What is an Event? A. An event is an object that describes a state change in a source. Events can be generated by pressing a button, entering a character via the keyboard, clicking the mouse or when a timer expires,a counter exceeds a value. Q88.What is an Event source? A.A source is an object that generates an event. Q89. What is an Event-listener? A.A listener is an object that is notified when an event occurs. Q90.What is an Anonymous Inner Class? A. An Anonymous inner class is one that is not assigned a name. Q91. What is the full form of AWT? A.AWT stands for Abstract Window Toolkit; it is a user-interface tool-kit. Q92. What is a Component? A. A graphical user interface is built of graphical elements called components. Typical components include such items as buttons, scrollbars, and text fields. Components allow the user to interact with the program and provide the user with visual feedback about the state of the program. Q93. What is a container? A. Container contains and controls the layout of components. Containers are themselves components, and can thus be placed inside other containers. In the AWT, all containers are instances of class Container or one of its subtypes. Q94. What is the class hierarchy of components and containers? Q95. What is a servlet? A. Servlet is a java server side program. Q96. What are the uses of Servlets? A. 1. Servlets are used to process the client request. 2. A Servlet can handle multiple requests concurrently and be used to develop high performance system 3. A Servlet can be used to load balance among several servers, as Servlet can easily forward request. Q97. What are the methods of Servlets life cycle? A. The javax.servlet.Servlet interface defines the three methods known as life-cycle method. public void init(ServletConfig config) throws ServletException public void service( ServletRequest req, ServletResponse res) throws ServletException, IOException public void destroy() Q98. How does the lifecycle method of servlet work? A. First the servlet is constructed, then initialized wih the init() method. Any request from client are handled initially by the service() method before delegating to the doXxx() methods in the case of HttpServlet. The servlet is removed from service, destroyed with the destroy() method, then garbage collected and finalized. Q99. What is required to create Servlets? A. To create servlets, we need access to a servlet development environment. Most applications use Tomcat for this purpose. Q100. What are the types of Servlet? A. There are two types of servlets, GenericServlet and HttpServlet. GenericServlet defines the generic or protocol independent servlet. HttpServlet is subclass of GenericServlet and provides some http specific functionality linke doGet and doPost methods. Q101. Differentiate between Servlet and Applet. A. Servlets are a server side component that executes on the server whereas applets are client side components and executes on the web browser. Applets have GUI interface but there is not GUI interface

in case of Servlets. Q102. Differentiate between doGet and doPost method? A. doGet is used when there is requirement of sending data appended to a query string in the URL. The doGet models the GET method of Http and it is used to retrieve the info on the client from some server as a request to it. The doGet cannot be used to send too much info appended as a query stream. GET puts the form values into the URL string. GET is limited to about 256 characters (usually a browser limitation) and creates really ugly URLs. POST allows you to have extremely dense forms and pass that to the server without clutter or limitation in size. e.g. you obviously can't send a file from the client to the server via GET. POST has no limit on the amount of data you can send and because the data does not show up on the URL you can send passwords. But this does not mean that POST is truly secure. For real security you have to look into encryption which is an entirely different topic. Q103. What are the advantages of servlets over CGI (Common gateway interface)? A. Java Servlets have a number of advantages over CGI and other API's. They are: 1. Platform Independent. 2. Performance. 3. Secure. 4. Extensibility. 5. Safe. Q104. Explain the directory structure of a web application. A: The directory structure of a web application consists of two parts. A private directory called WEB-INF A public resource directory which contains public resource folder WEB-INF folder consists of 1. web.xml 2. Classes directory 3. Lib directory Q105. What is a java session? A. Session is a server side object which is of type HttpSession interface. www.jntuworld.com www.jntuworld.com Q106. What is the use of session object? A. Session object ensures that the data of one servlet is available to all the servlets which are executed by the same browser. Q107. Session objects are maintained by whom? A. Session objects are automatically created and maintained by the Server. Q108. What is session tracking? A. session tracking is a mechanism which helps the servers to maintain the state to track the series of requests from the same user across some period of time. Q109. What is a cookie? A. Cookie is a client side program. Q110. What is transient variable? A. 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. Q111. What do you understand by Synchronization? A. Synchronization is a process of controlling the access of shared resources by the multiple threads in such a manner that only one thread can access one resource at a time. In non synchronized multithreaded application, it is possible for one thread to modify a shared object while another thread is in the process of using or updating the object's value. Synchronization prevents such type of data corruption. Q112. What is similarities/difference between an Abstract class and Interface? Answer: Differences are as follows: Interfaces provide a form of multiple inheritance. A class can extend only one other class. Interfaces are limited to public methods and constants with no implementation. Abstract classes can have a partial implementation, protected parts, static methods, etc. A Class may implement several interfaces. But in case of abstract class, a class may extend only one abstract class. Interfaces are slow as it requires extra indirection to to find corresponding method in in the actual class.

Abstract classes are fast. Similarities: Neither Abstract classes nor Interface can be instantiated. Q113. How to define an Interface? A. In Java Interface defines the methods but does not implement them. Interface can include constants. A class that implements the interfaces is bound to implement all the methods defined in Interface. Q114. How can a subclass call a method or a constructor defined in a superclass? A. Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass's constructor. Q115. When you declare a method as abstract method? A. When I want child class to implement the behavior of the method. Q116. Can I call a abstract method from a non abstract method? A. Yes, We can call a abstract method from a Non abstract method in a Java abstract class Q117. What are the static fields & static Methods? A. If a field or method defined as a static, there is only one copy for entire class, rather than one copy for each instance of class. Static method cannot access non-static field or call non-static method Q118. What are the Final fields & Final Methods? A. Fields and methods can also be declared final. A final method cannot be overridden in a subclass. A final field is like a constant: once it has been given a value, it cannot be assigned to again. Q119. What are null or Marker interfaces in Java A. The null interfaces are marker interfaces, they do not have function declarations in them, they are empty interfaces, and this is to convey the compiler that they have to be treated differently . Q120. What is this pointer? A. It is a pointer which points to the current object in the member function. Q121. What is the purpose of System Class A. The purpose of the system class is to provide the access to the System resources Q122. Can abstract class be final? Answer: No, abstract class cannot be final. Q123. What is a singleton class? A. 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. Q124. Can an abstract class have final method? A. Yes Q125. Can a final class have an abstract method? A. No, the compiler will give an error Q126. What is the difference between Authentication and Authorization? A. 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. Q127. Why is the main method static? A. So that it can be invoked without creating an instance of that class. Q128. What is the difference between class variable, member variable and automatic(local) variable A. class variable is a static variable and does not belong to instance of class but rather shared across all the instances member variable belongs to a particular instance of class and can be called from any method of the class automatic or local variable is created on entry to a method and has only method scope. Q129. When are static and non static variables of the class initialized? A. The static variables are initialized when the class is loaded. Non static variables are initialized just before the constructor is called. Q130. When are automatic variable initialized? A. Automatic variable have to be initialized explicitly Q131. How is an argument passed in java, by copy or by reference? A. If the variable is primitive data type then it is passed by copy. If the variable is an object then it is passed by reference. Q132. What are different types of operators in java? A. Uniary ++, --, +, -, |, ~, () Arithmetic *, /, %,+, -

Shift <<, >>, >>> Comparison =, instanceof, = =,!=Bitwise &, ^, |Short Circuit &&, ||Ternary ?:Assignment = Q133. Can protected or friendly features be accessed from different packages? A. No when features are friendly or protected they can be accessed from all the classes in that package but not from classes in another package. Q134. Can abstract class be instantiated? A. No, abstract class cannot be instantiated i.e., you cannot create a new object of this class. Q 135. When are the static variables loaded into the memory? A. During the class load time. Q 136. Can static method use non static features of there class? A. No they are not allowed to use non static features of the class; they can only call static methods and can use static data. Q137. What is JVM? A. Java Virtual Machine. Q138. What is the use of java compiler? A. Java compiler converts source code (.java) into byte code (.class file). Q139. What is JIT? A. Just in Time compiler. It is a code generator that converts Java byte code into machine language instructions. Q140. What is an Expression? A. An expression is a combination of variables, operators and constants. Q141. All Dynamic objects are created on Heap. Q142. All normal objects are created on Stack. Q143. API stands for? A. Application Program Interface. Q144. C++ follows Bottom-up approach. Q145. What is the difference between C and C++? A. C is procedure oriented language and gives importance to procedure that is functions rather than data. C++is object oriented language and gives importance to object that is data. Q146. What is the difference between C++ and java? A. -C++ is the advanced version of c i.e., C with Classes whereas Java is the platform independent as it works on any type of operating systems. -Java is reusable and more reliable, more secure than C++. Q147. What is the difference between a constructor and a method? A. A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator. A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator. Q148. What is Final? A. A final class can't be extended i.e., final class may not be subclassed. A final method can't be overridden when its class is inherited. You can't change value of a final variable (is a constant). Q149. What if the main method is declared as private? A. The program compiles properly but at runtime it will give "Main method not public." message. Q150. What if the static modifier is removed from the signature of the main method? A. Program compiles. But at runtime throws an error "NoSuchMethodError". Q151. What if I write static public void instead of public static void? A. Program compiles and runs properly. Q152. What if I do not provide the String array as the argument to the method? A. Program compiles but throws a runtime error "NoSuchMethodError". Q153. How can one prove that the array is not null but empty using one line of code? A. Print args.length. It will print 0. That means it is empty. But if it would have been null then it would have thrown a NullPointerException on attempting to print args.length. Q154. What environment variables do I need to set on my machine in order to be able to run Java programs? A. CLASSPATH and PATH are the two variables. Q155. Can an application have multiple classes having main method? A. Yes it is possible. While starting the application we mention the class name to be run. The JVM will look for the Main method only in the class whose name you have mentioned. Hence there is not conflict

amongst the multiple classes having main method. Q156. Can I have multiple main methods in the same class? A: No the program fails to compile. The compiler says that the main method is already defined in the class. Q157. Do I need to import java.lang package any time? Why? A: No. It is by default loaded internally by the JVM. Q158. Can I import same package/class twice? Will the JVM load the package twice at runtime? A: One can import the same package or same class multiple times. Neither compiler nor JVM complains about it. And the JVM will internally load the class only once no matter how many times you import the same class. Q159. Are the imports checked for validity at compile time? e.g. will the code containing an import such as java.lang.ABCD compile? A: Yes the imports are checked for the semantic validity at compile time. The code containing above line of import will not compile. It will throw an error saying, can not resolve symbol symbol: class ABCD location: package io import java.io.ABCD; Q160. What is the difference between declaring a variable and defining a variable? A: In declaration we just mention the type of the variable and its name. We do not initialize it. But defining means declaration + initialization. Q161. What is serialization? A: Serialization is a mechanism by which you can save the state of an object by converting it to a byte stream. Q162. How do I serialize an object to a file? A: The class whose instances are to be serialized should implement an interface Serializable. Then you pass the instance to the ObjectOutputStream which is connected to a fileoutputstream. This will save the object to a file. Q163. Does Java provide any construct to find out the size of an object? A: No there is not sizeof operator in Java. So there is not direct way to determine the size of an object directly in Java. Q164. What are runtime exceptions? A: Runtime exceptions are those exceptions that are thrown at runtime because of either wrong input data or because of wrong business logic etc. These are not checked by the compiler at compile time. www.jntuworld.com www.jntuworld.com Q165. What is the difference between error and an exception? A: An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. These JVM errors and you can not repair them at runtime. While exceptions are conditions that occur because of bad input etc. e.g. FileNotFoundException will be thrown if the specified file does not exist. Or a NullPointerException will take place if you try using a null reference. In most of the cases it is possible to recover from an exception (probably by giving user a feedback for entering proper values etc). Q166. What is the difference between a while statement and a do statement? A: A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once. Q167. What is the difference between static and non-static variables? A: A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance. Q168. How are this() and super() used with constructors? A: This() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor. Q169. What is daemon thread and which method is used to create the daemon thread? A: Daemon thread is a low priority thread which runs intermittently in the back ground doing the garbage collection operation for the java runtime system. setDaemon method is used to create a daemon thread. Q170. What method must be implemented by all threads? A: All tasks must implement the run() method, whether they are a subclass of Thread or implement the Runnable interface. Q171 Expain the reason for each keyword of public static void main(String args[])?

A. public- main(..) is the first method called by java environment when a program is executed so it has to accessible from java environment. Hence the access specifier has to be public. static: Java environment should be able to call this method without creating an instance of the class , so this method must be declared as static. void: main does not return anything so the return type must be void The argument String indicates the argument type which is given at the command line and arg is an array for string given during command line. Q172. In System.out.println(), what is System, out and println? A. System is a predefined final class, out is a PrintStream object and println is a built-in overloaded method in the out object. Q173. Explain working of Java Virtual Machine (JVM)? A. 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. Q174. Can main method be declared final? A. Yes, the main method can be declared final, in addition to being public static. Q175. What will be the output of the following statement? System.out.println ("1" + 3); A: It will print 13. Q176. What is serialization? A. Serialization is the process of converting an object data into stream of bytes. Q177. What is JDBC? A. JDBC (Java Database Connectivity) is the technology used to connect java application to the backend database in order to maintain and manage the data related to the java application. Q178. What is a driver? A. Drivers are nothing but the programs, which would act as an interface between the java application and the backend database Q179. How many jdbc drivers are there? And what are they? A. There are 4 types of drivers in JDBC. They are: 1. Type 1: JDBC-ODBC Bridge driver (Bridge) Type 2: Native-API/partly Java driver (Native) Type 3: All Java/Net-protocol driver (Middleware) Type 4: All Java/Native-protocol driver (Pure) Q180. What is the use of driver class? A. Driver class provides all the information abut the drivers to the JVM. Q181. What are the steps to implement JDBC connection? A. 1. Loading Driver 2. Establishing Connection 3. Executing Statements 4. Getting Results Q182. What is the use of Connection object? A. Connection object contains the address of the Database to which we send SQL statements. Q183. What is Statement interface? A. The Statement object is used for executing a static SQL statement and returning the results it produces. Q184. What is the disadvantage of Statement interface? A. The Statement interface increases the overload on driver. In order to overcome this anomaly we use PreparedStatement. www.jntuworld.com www.jntuworld.com Q185. What is PreparedStatement? A. PreparedStatement Object contains all the precompiled SQL Statements. This object can then be used to efficiently execute this statement multiple times. PreparedStatement is the sub interface of Statement Q186. What is a ResultSet interface? A. The object of ResultSet interface maintains a cursor pointing to its current row of data. Initially the cursor is positioned before the first row. The next() method moves the cursor to the next row, and because it returns false when there are no more rows in the ResultSet object, it can be used in a while loop to iterate through the result set.

Q187. What is MVC Architecture? A. MVC (Model View Controller) is a three tier architecture used to separate the business logic and application data from the presentation data to the user. Q188. Explain the terms Client, Server Request, Response. Client: Client is a networking program which is capable of establishing connection to the server and sends the data to the server. Server: Server is a networking program, which can accept requests from different clients in a network and process the client s request and send the result back to the corresponding clients. Request: Any data that is sent by the client to the server can be called as request. Response: The result of the process which is sent to the client from the server is known as response. Q189. What is a servlet container? A. Container is nothing but a set of programs which provide an environment at the server to execute a servlet program. Q190. Where is the address of JVM stored? A. Java_HOME is an environmental variable which contains the address of JVM. Q191. What is a deployment? A. It is a process of making a web supplication (servet programs and its associate HTML files) available to the server and container. Q192. What is XML? -XML stands for EXtensible Markup Language -XML is a markup language much like HTML -XML was designed to carry data, not to display data -XML tags are not predefined. You must define your own tags -XML is designed to be self-descriptive -XML is a W3C Recommendation Q193. What is web.xml? A. web.xml file contains all the details of the servlets which are present in the application. It also maintains alias names of the servlets and the actual names of the servlets and this xml file will mention which alias name is associated with which servlet. Q194. What is HTML page and HTML file? A. Group of HTML statements an html file. And the output of HTML file is a HTML page. Q195. What is JavaScript? -JavaScript was designed to add interactivity to HTML pages -JavaScript is a scripting language -A scripting language is a lightweight programming language -JavaScript is usually embedded directly into HTML pages -JavaScript is an interpreted language (means that scripts execute without preliminary compilation) -Everyone can use JavaScript without purchasing a license Q196. What is JSP? A. JavaServer Pages (JSP) is a Java technology that helps software developers serve dynamically generated web pages based on HTML, XML, or other document types Q197. What is the difference between procedural and object-oriented programs?A. a) In procedural program, programming logic follows certain procedures and the instructions are executed one after another. In OOP program, unit of program is object, which is nothing but combination of data and code. b) In procedural program, data is exposed to the whole program whereas in OOPs program, it is accessible with in the object and which in turn assures the security of the code. Q198. What are JavaBeans? A. Java Beans are usual Java classes which adhere to certain coding conventions: 1. Implements java.io.Serializable interface 2. Provides no argument constructor 3. Provides getter and setter methods for accessing its properties. Q199. What is a Scriptlet? A. scriptlet can contain any number of language statements, variable or method declarations, or expressions that are valid in the page scripting language. Within scriptlet tags, you can declare variables or methods to use later in the file, write expressions valid in the page scripting language, use any of the JSP implicit objects or any object declared with a <jsp:useBean>. Q200. Is JSP technology extensible? A. Yes, it is. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries.

You might also like