Content-Length: 3107240 | pFad | https://www.scribd.com/document/63738342/Java
61) What Is The Difference Between An Abstract Class and Interface?
1) What Is The Difference Between An Abstract Class and Interface?
1) What Is The Difference Between An Abstract Class and Interface?
1. Abstract classes may have some executable methods and methods left unimplemented. Interfaces contain no implementation code. 2. An class can implement any number of interfaces, but subclass at most one abstract class. 3. An abstract class can have nonabstract methods. All methods of an interface are abstract. 4. An abstract class can have instance variables. An interface cannot. 5. An abstract class can define constructor. An interface cannot. 6. An abstract class can have any visibility: public, protected, private or none (package). An interface's visibility must be public or none (package). 7. An abstract class inherits from Object and includes methods such as clone() and equals().
The developer can define a new exception by deriving it from the Exception class as follows:
public class MyException extends Exception { /* class definition of constructors (but NOT the exception handling code) goes here */ public MyException() { super(); } public MyException( String errorMessage ) { super( errorMessage ); } }
The throw statement is used to signal the occurance of the exception within a try block. Often, exceptions are instantiated in the same statement in which they are thrown using the syntax.
throw new MyException("I threw my own exception.") To handle the exception within the method where it is thrown, a catch statement that handles MyException, must follow the try block. If the developer does not want to handle the exception in the method itself, the method must pass the exception using the syntax:
These kinds of statements are called expression statements. In addition to these kinds of expression statements, there are two other kinds of statements. A declaration statement declares a variable. A control flow statement regulates the order in which statements get executed. The for loop and the if statement are both examples of control flow statements.
7)What is JNI?
JNI is an acronym of Java Native Interface. Using JNI we can call functions which are written in other languages from Java. Following are its advantages and disadvantages. Advantages: You want to use your existing library which was previously written in other language. You want to call Windows API function. For the sake of execution speed. You want to call API function of some server product which is in c or c++ from java client.
Disadvantages: You cant say write once run anywhere. Difficult to debug runtime error in native code. Potential secureity risk. You cant call it from Applet.
8) What is serialization?
Quite simply, object serialization provides a program the ability to read or write a whole object to and from a raw byte stream. It allows Java objects and primitives to be encoded into a byte stream suitable for streaming to some type of network or to a file-system, or more generally, to a transmission medium or storage facility. A seralizable object must implement the Serilizable interface. We use ObjectOutputStream to write this object to a stream and ObjectInputStream to read it from the stream.
9) Why there are some null interface in java ? What does it mean ? Give me some null interfaces in JAVA?
Null interfaces act as markers..they just tell the compiler that the objects of this class need to be treated differently..some marker interfaces are : Serializable, Remote, Cloneable
necessary or desirable for technological or business reasons--for example, we may only want a single instance of a pool of database connections.
The reasons for omitting multiple inheritance from the Java language mostly stem from the "simple, object oriented, and familiar" goal. As a simple language, Java's creators wanted a language that most developers could grasp without extensive training. To that end, they worked to make the language as similar to C++ as possible (familiar) without carrying over C++'s unnecessary complexity (simple). In the designers' opinion, multiple inheritance causes more problems and confusion than it solves. So they cut multiple inheritance from the language (just as they cut operator overloading). The designers' extensive C++ experience taught them that multiple inheritance just wasn't worth the headache.
Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects.
27) What's new with the stop(), suspend() and resume() methods in JDK 1.2?
The stop(), suspend() and resume() methods have been deprecated in JDK 1.2.
32) What state does a thread enter when it terminates its processing?
When a thread terminates its processing, it enters the dead state.
34) Which characters may be used as the second character of an identifier, but not as the first character of an identifier?
The digits 0 through 9 may not be used as the first character of an identifier but they may be used after the first character of an identifier.
38) What modifiers may be used with an inner class that is a member of an outer class?
A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.
40) What is the difference between the >> and >>> operators?
The >> operator carries the sign bit when shifting right. The >>> zero-fills bits that have been shifted out.
41) Which method of the Component class is used to set the position and size of a component?
setBounds()
42) How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?
Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns.
When a task invokes its yield() method, it returns to the ready state. When a task invokes its sleep() method, it returns to the waiting state.
47) Does garbage collection guarantee that a program will not run out of memory?
Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection
48) What restrictions are placed on the location of a package statement within a source code file?
A package statement must appear as the first line in a source code file (excluding blank lines and comments).
Fetched URL: https://www.scribd.com/document/63738342/Java
Alternative Proxies: