Monday, 23 October 2017

JAVA Interview Questions Page2


Constructor gets invoked when a new object is created. Every class has a constructor. If we do not explicitly write a constructor for a class the java compiler builds a default constructor for that class.
An Object is first declared, then instantiated and then it is initialized.
Default value of byte datatype is 0.
Default value of float and double datatype in different as compared to C/C++. For float its 0.0f and for double it’s 0.0d
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.
Class variables also known as static variables are declared with the static keyword in a class, but outside a method, constructor or a block.
Java provides access modifiers to set access levels for classes, variables, methods and constructors. A member has package or default accessibility when no accessibility modifier is specified.
Variables, methods and constructors which are declared protected in a superclass can be accessed only by the subclasses in other package or any class within the package of the protected members' class.
Java provides these modifiers for providing functionalities other than Access Modifiers, synchronized used to indicate that a method can be accessed by only one thread at a time.
Postfix operators i.e () [] . is at the highest precedence.
Variables used in a switch statement can only be a string, enum, byte, short, int, or char.
This method is used to get the primitive data type of a certain String.
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.
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.
Use StringBuilder whenever possible because it is faster than StringBuffer. But, if thread safety is necessary then use StringBuffer objects.
java.util.regex package is used for this purpose.

No comments:

Post a Comment