Last updated on Jan 16, 2023
Java was created at Sun Microsystems, Inc., where James Gosling led a team of researchers in an effort to create a new language that would allow consumer electronic devices to communicate with each other. Work on the language began in 1991, and before long the team's focus changed to a new niche, the World Wide Web.
A 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 class rather than the name of a particular object of the class (though that works too). That's how library methods like System.out.println() work. out is a static field in the java.lang.System class.
A software development environment for writing applets and applications in the Java programming language. Technically, the JDK is the correct name for all versions of the Java platform. Java virtual machine A software "execution engine" that safely and compatibly executes the byte codes in Java class files on a microprocessor (whether in a computer or in another electronic device Java Runtime Environment (JRE) A subset of the Java Development Kit (JDK) for end-users and developers who want to redistribute the runtime environment alone. The Java runtime environment consists of the Java virtual machine1, the Java core classes, and supporting files.
A The null value is not a keyword.
A 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.
A A private variable may only be accessed within the class in which it is declared.
Java was created at Sun Microsystems, Inc., where James Gosling led a team of researchers in an effort to create a new language that would allow consumer electronic devices to communicate with each other. Work on the language began in 1991, and before long the team's focus changed to a new niche, the World Wide Web.
A 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
A you have to implement your own public clone() method, even if it doesn't do anything special and just calls super.clone().
A A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.
A A non-static inner class may have object instances that are associated with instances of the class's outer class. A static inner class does not have any object instances.
A 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. All objects and classes have locks. A class's lock is acquired on the class's Class object.
A Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often safer than inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn't force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is harder to re-use (because it is not a subclass).
A The event-delegation model has two advantages over the event-inheritance model. First, it enables event handling to be handled by objects other than the ones that generate the events (or their containers). This allows a clean separation between a component's design and its use. The other advantage of the event-delegation model is that it performs much better in applications where many events are generated. This performance improvement is due to the fact that the event-delegation model does not have to repeatedly process unhandled events, as is the case of the event-inheritance model.
A Polymorphism allows methods to be written that needn't be concerned about the specifics of the objects they will be applied to. That is, the method can be specified at a higher level of abstraction and can be counted on to work even on objects of yet unconceived classes.
A Because C++ has proven by example that operator overloading makes code almost impossible to maintain. In fact there very nearly wasn't even method overloading in Java, but it was thought that this was too useful for some very basic methods like print(). Note that some of the classes like DataOutputStream have unoverloaded methods like writeInt() and writeByte().
Ans: The process of binding data and corresponding methods (behavior) together into a single unit is called encapsulation in Java. In other words, encapsulation is a programming technique that binds the class members (variables and methods) together and prevents them from being accessed by other classes, thereby we can keep variables and methods safes from outside interference and misuse. If a field is declared private in the class then it cannot be accessed by anyone outside the class and hides the fields within the class. Therefore, Encapsulation is also called data hiding.
Ans: Encapsulation means combining the data of our application and its manipulation in one place. It allows the state of an object to be accessed and modified through behavior. It reduces the coupling of modules and increases the cohesion inside them.
Ans: There are the following advantages of encapsulation
in Java. They are as follows:
1. The encapsulated code is more
flexible and easy to change with new requirements.
2. It prevents
the other classes to access the private fields.
3. Encapsulation
allows modifying implemented code without breaking other code
who have implemented the code.
4. It keeps the data and codes safe
from external inheritance.
5. Thus, Encapsulation helps to achieve
security. It improves the maintainability of the application.
A private variable may only be accessed within the class in which it is declared.
A 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. All objects and classes have locks. A class's lock is acquired on the class's Class object.
A It is referred to as the “modulo” or “remainder” operator. It returns the remainder of dividing the first operand by the second operand.
A The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.
A A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.
A A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.
A The purpose of the System class is to provide access to system resources.
A The Class class is used to obtain information about an object's design.
A During compilation, the values of each case of a switch statement must evaluate to a value that can be promoted to an int value.
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.
A A local inner class may be final or abstract.
A The File class is used to create objects that provide access to the files and directories of a local file system.
A 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.
A There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference
A The Java runtime system generates RuntimeException and Error exceptions.
A this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.
A An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.
A The values true and false are not keywords.
A The File class encapsulates the files and directories of the local file system. The RandomAccessFile class provides the methods needed to directly access data contained in any part of a file.
A The java.lang package is always imported by default.
A If you are running Java on English Windows platforms, it is probably Cp1252. If you are running Java on English Solaris platforms, it is most likely 8859_1.
A notify() is used to unblock one waiting thread; notifyAll() is used to unblock all of them. Using notify() is preferable (for efficiency) when only one blocked thread can benefit from the change (for example, when freeing a buffer back into a pool). notifyAll() is necessary (for correctness) if multiple threads should resume (for example, when releasing a "writer" lock on a file might permit all "readers" to resume).
A The import statement does not bring methods into your local
name space. It lets you abbreviate class names, but not get rid
of them altogether. That's just the way it works, you'll get
used to it. It's really a lot safer this way.
However, there is actually a little trick you can use in some
cases that gets you what you want. If your top-level class
doesn't need to inherit from anything else, make it inherit
from java.lang.Math. That *does* bring all the methods into
your local name space. But you can't use this trick in an
applet, because you have to inherit from java.awt.Applet. And
actually, you can't use it on java.lang.Math at all, because
Math is a "final" class which means it can't be extended.
A Global variables are considered bad form for a variety of reasons: • Adding state variables breaks referential transparency (you no longer can understand a statement or expression on its own: you need to understand it in the context of the settings of the global variables). • State variables lessen the cohesion of a program: you need to know more to understand how something works. A major point of Object-Oriented programming is to break up global state into more easily understood collections of local state. • When you add one variable, you limit the use of your program to one instance. What you thought was global, someone else might think of as local: they may want to run two copies of your program at once. For these reasons, Java decided to ban global variables.
A A final class can no longer be sub classed. Mostly this is done for security reasons with basic classes like String and Integer. It also allows the compiler to make some optimizations, and makes thread safety a little easier to achieve. Methods may be declared final as well. This means they may not be overridden in a subclass. Fields can be declared final, too. However, this has a completely different meaning. A final field cannot be changed after it's initialized, and it must include an initializer statement where it's declared. For example, public final double c = 2.998; It's also possible to make a static field final to get the effect of C++'s const statement or some uses of C's #define, e.g. public static final double c = 2.998;
A An abstract class cannot be instantiated. Only its subclasses can be instantiated. You indicate that a class is abstract with the abstract keyword like this: public abstract class Container extends Component { Abstract classes may contain abstract methods. A method declared abstract is not actually implemented in the current class. It exists only to be overridden in subclasses. It has no body. For example, public abstract float price(); Abstract methods may only be included in abstract classes. However, an abstract class is not required to have any abstract methods, though most of them do. Each subclass of an abstract class must override the abstract methods of its superclasses or itself be declared abstract.
A transient variable is a variable that may not be serialized.
A 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.
A 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
A An object's finalize() method cannot be invoked by the garbage collector while the object is still reachable. However, an object's finalize() method may be invoked by other objects.
A Yes, a for statement can loop indefinitely. For example, consider the following: for(;;) ;
A A task's priority is an integer value that identifies the relative order in which it should be executed with respect to other tasks. The scheduler attempts to schedule higher priority tasks before lower priority tasks.
A These are accessibility modifiers. Private is the most restrictive, while public is the least restrictive. There is no real difference between protected and the default type (also known as package protected) within the context of the same package, however the protected keyword allows visibility to a derived class in a different package.
A As many as you want, but the static initializers and class variable initializers are executed in textual order and may not refer to class variables declared in the class whose declarations appear textually after the use, even though these class variables are in scope.
A Have a look at this demo. public class Test2 { private Test2(){ System.out.println("Test2class"); } class Subclass extends Test2{ public Subclass(){ System.out.println("Subclass"); } } public static void main(String[] args){ Subclass s = new Test2().new Subclass(); } } This works because an inner class is allowed to access private members of its enclosing instance, including the private constructor.
A Normal variables will be collected first. Lets take a simple example: Class A is having a static variable s which is used by obj1, obj2 and obj3 of Class B. Each object of class B is having instance variables a and b (normal variables). Lets say if obj1 is not being in use since long time, then automatically the garbage collector will collect the space occupied by obj1. It will not destroy the static variable S as it is being used by the other two objects obj2 and obj3. Therefore only normal variables will be destroyed first. We can say it in a simple statement that "Variables having less scope will be destroyed first"
A The "JDK" is the Java Development Kit. I.e., the JDK is bundle of software that you can use to develop Java based software. The "JRE" is the Java Runtime Environment. I.e., the JRE is an implementation of the Java Virtual Machine which actually executes Java programs. Typically, each JDK contains one (or more) JRE's along with the various development tools like the Java source compilers, bundling and deployment tools, debuggers, development libraries, etc.
A NO, it's not necessary. Many text books say like this but that’s not true. Value of a final variable can be instance specific also, but in this case we have to initialize the variable in all the constructors. If we want to have a common final value of a variable for all the instances then there are two ways. 1. Initialize the variable at class level (at the time of declaration) or 2. just declare variable at class level and initialize it in any one of the instance blocks i.e. a. class A { final int a; {a=5;}} b. class A { final int a = 5;}
A Numeric promotion is the conversion of a smaller numeric type to a larger numeric type, so that integer and floating-point operations may take place. In numerical promotion, byte, char, and short values are converted to int values. The int values are also converted to long values, if necessary. The long and float values are converted to double values, as required