An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation.
Program throws “NoSuchMethodError” error at runtime.
Null, unless it is defined explicitly.
No, a top level class can not be private or protected. It can have either “public” or no modifier.
We can pass them around as method parameters where a method expects an object. It also provides utility methods.
An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. Exceptions are conditions that occur because of bad input etc. e.g. FileNotFoundException will be thrown if the specified file does not exist.
It is not necessary that each try block must be followed by a catch block. It should be followed by either a catch block or a finally block.
A thread is in the ready state as initial state after it has been created and started.
The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region.
Synchronized methods are methods that are used to control access to an object. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.
Runtime polymorphism or dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile-time. In this process, an overridden method is called through the reference variable of a superclass.
Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at run-time.
No, constructor cannot be inherited.
ArrayList can grow dynamically and provides more powerful insertion and search mechanisms than arrays.
Deletion in linked list is fast because it involves only updating the next pointer in the node before the deleted node and updating the previous pointer in the node after the deleted node.
If you need to frequently add and remove elements from the middle of the list and only access the list elements sequentially, then LinkedList should be used. If you need to support random access, without inserting or removing elements from any place other than the end, then ArrayList should be used.
It is a collection returned by the values() method of the Map Interface, It contains all the objects present as values in the map.
The dot operator(.) is used to access the instance variables and methods of class objects.It is also used to access classes and sub-packages from a package.
Private constructor is used if you do not want other classes to instantiate the object and to prevent subclassing.T
Type casting means treating a variable of one type as though it is another type.
A thread is a execution in a program. The life cycle of a thread include −
- Newborn state
- Runnable state
- Running state
- Blocked state
- Dead state
The >> operator carries the sign bit when shifting right. The >>> zero-fills bits that have been shifted out.
setBounds() method is used for this purpose.
The range of the short type is -(2^15) to 2^15 – 1.
No, Java does not allow Default Arguments.
Octal Numbers are denoted by leading zero in java, example: 06
Hexadecimal Numbers are denoted by leading 0x or 0X in java, example − 0XF
Yes, an example can be break one;
Import statement is allowed at the beginning of the program file after package statement.
It is used to pause or temporarily stop the execution of the thread.
It is used to find out whether a thread is still running or not.
It is a public static method used to obtain a reference to the current thread.
The main thread is created automatically and it begins to execute immediately when a program starts. It ia thread from which all other child threads originate.
Life cycle involves the following steps −
It initializes the applet and is the first method to be called.
getImage(URL object, filename) is used for this purpose.
It is used to specify the name of the applet class.
It is a simple drawing surface which are used for painting images or to perform other graphical operations.
It refers to writing programs that execute across multiple devices (computers), in which the devices are all connected to each other using a network.
Sockets provide the communication mechanism between two computers using TCP. A client program creates a socket on its end of the communication and attempts to connect that socket to a server.
Sockets are flexible and sufficient. Efficient socket based programming can be easily implemented for general communications. It cause low network traffic.
Socket based communications allows only to send packets of raw data between applications. Both the client-side and server-side have to provide mechanisms to make the data useful in any way.
java.net.ServerSocket class is used by server applications to obtain a port and listen for client requests
java.net.Socket class represents the socket that both the client and server use to communicate with each other.
Generics provide compile-time type safety that allows programmers to catch invalid types at compile time. Java Generic methods and generic classes enable programmers to specify, with a single method declaration, a set of related methods or, with a single class declaration, a set of related types.
CLASSPATH and PATH are the two variables.
No, there is no need to import this package. It is by default loaded internally by the JVM.
If a class is declared within a class and specify the static modifier, the compiler treats the class just like any other top-level class. Nested top-level class is an Inner class.
Externalizable is an interface which contains two methods readExternal and writeExternal. These methods give you a control over the serialization mechanism.
No in this case the finally block will not execute because when you say System.exit (0); the control immediately goes out of the program, and thus finally never executes.
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.
All tasks must implement the run() method
The GregorianCalendar provides support for traditional Western calendars
The SimpleTimeZone class provides support for a Gregorian calendar .
The size is the number of elements actually stored in the vector, while capacity is the maximum number of elements it can store at a given instance of time.
Yes a Vector can contain heterogenous objects. Because a Vector stores everything in terms of Object.
An enumeration is an interface containing methods for accessing the underlying data structure from which the enumeration is obtained. It allows sequential access to all the elements stored in the collection.
Path and Classpath are operating system level environment variales. Path is defines where the system can find the executables(.exe) files and classpath is used to specify the location of .class files.
No, it’s not possible to accessed outside it’s package.
A static method should not refer to instance variables without creating an instance and cannot use “this” operator to refer the instance.
Yes an Interface can inherit another Interface, for that matter an Interface can extend more than one Interface.
An object’s lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object’s lock.
It is the casting from a general to a more specific type, i.e. casting down the hierarchy.
Order of precedence determines the order in which operators are evaluated in expressions. Associatity determines whether an expression is evaluated left-to-right or right-to-left.
A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.
When a class is defined within a scope of another class, then it becomes inner class. If the access modifier of the inner class is static, then it becomes nested class.
Overridden methods must have the same name, argument list, and return type. The overriding method may not limit the access of the method it overrides.
A child object constructor always first needs to construct its parent. In Java it is done via an implicit call to the no-args constructor as the first statement.
Yes, a double value can be cast to a byte.
When an exception is thrown within the body of a try statement, the catch clauses of the try statement are examined in the order in which they appear. The first catch clause that is capable of handling the exception is executed. The remaining catch clauses are ignored.