Home Interview Questions and Answers Java Interview Questions and Answers For Graduates Part-3

java21.What do you mean by synchronized Non Access Modifier?
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.

22.According to Java Operator precedence, which operator is considered to be with highest precedence?
Postfix operators i.e () [] . is at the highest precedence.

23.Variables used in a switch statement can be used with which datatypes?
Variables used in a switch statement can only be a byte, short, int, or char.

24.When parseInt() method can be used?
This method is used to get the primitive data type of a certain String.

25.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.

26.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.

27.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.

28.Which package is used for pattern matching with regular expressions?
java.util.regex package is used for this purpose.

29.java.util.regex consists of which classes?
java.util.regex consists of three classes − Pattern class, Matcher class and PatternSyntaxException class.

30.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.

You may also like

Leave a Comment