Java Flashcards
List any five features of Java?
Some features include Object Oriented, Platform Independent, Robust, Interpreted, Multi-threaded
Why is Java Architectural Neutral?
It’s compiler generates an architecture-neutral object file format, which makes the compiled code to be executable on many processors, with the presence of Java runtime system.
How Java enabled High Performance?
Java uses Just-In-Time compiler to enable high performance. Just-In-Time compiler is a program that turns Java bytecode, which is a program that contains instructions that must be interpreted into instructions that can be sent directly to the processor.
Why Java is considered dynamic?
It is designed to adapt to an evolving environment. Java programs can carry extensive amount of run-time information that can be used to verify and resolve accesses to objects on run-time.
What is Java Virtual Machine and how it is considered in context of Java’s platform independent feature?
When Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by virtual Machine (JVM) on whichever platform it is being run.
What is Singleton class?
Singleton class control object creation, limiting the number to one but allowing the flexibility to create more objects if the situation changes.
List the three steps for creating an Object for a class?
An Object is first declared, then instantiated and then it is initialized.
When a byte datatype is used?
This data type is used to save space in large arrays, mainly in place of integers, since a byte is four times smaller than an int.
Variables used in a switch statement can be used with which datatypes?
Variables used in a switch statement can only be a string, enum, byte, short, int, or char.
When parseInt() method can be used?
This method is used to get the primitive data type of a certain String.
Why is String class considered immutable?
The String class is immutable, so that once it is created a String object cannot be changed. Since String is immutable it can safely be shared between many threads ,which is considered very important for multithreaded programming.
Why is StringBuffer called mutable?
The String class is considered as immutable, so that once it is created a String object cannot be changed. If there is a necessity to make alot of modifications to Strings of characters then StringBuffer should be used.
What is the difference between StringBuffer and StringBuilder class?
Use StringBuilder whenever possible because it is faster than StringBuffer. But, if thread safety is necessary then use StringBuffer objects.
What is finalize() method?
It is possible to define a method that will be called just before an object’s final destruction by the garbage collector. This method is called finalize( ), and it can be used to ensure that an object terminates cleanly.
Explain Runtime Exceptions?
It 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.
Which are the two subclasses under Exception class?
The Exception class has two main subclasses : IOException class and RuntimeException Class.
When throws keyword is used?
If a method does not handle a checked exception, the method must declare it using the throws keyword. The throws keyword appears at the end of a method’s signature.
When throw keyword is used?
An exception can be thrown, either a newly instantiated one or an exception that you just caught, by using throw keyword.
How finally used under Exception Handling?
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.
What things should be kept in mind while creating your own exceptions in Java?
While creating your own exception −
- All exceptions must be a child of Throwable. - If you want to write a checked exception that is automatically enforced by the Handle or Declare Rule, you need to extend the Exception class. - You want to write a runtime exception, you need to extend the RuntimeException class.
Define Inheritance?
It is the process where one object acquires the properties of another. With the use of inheritance the information is made manageable in a hierarchical order.
When super keyword is used?
If the method overrides one of its superclass’s methods, overridden method can be invoked through the use of the keyword super. It can be also used to refer to a hidden field.
What is Polymorphism?
Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object.
What is Abstraction?
It refers to the ability to make a class abstract in OOP. It helps to reduce the complexity and also improves the maintainability of the system.
What is Abstract class?
These classes cannot be instantiated and are either partially implemented or not at all implemented. This class contains one or more abstract methods which are simply method declarations without a body.