Our website is made possible by displaying online advertisements to our visitors.Please consider supporting us by disabling your ad blocker.
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Translate it in your own Language

Print this Job Post

Print Friendly and PDF

Tuesday, May 27, 2014

Core Java: String Handling Interview Questions

There is given a list of string handling interview questions with short and pointed answers. If you know any string handling interview question, kindly post it in the comment section.

Question-84:What is the meaning of immutable in terms of String?
Answer:
The simple meaning of immutable is unmodifiable or unchangeable. Once string object has been created, its value can’t be changed.


Question-85: Why string objects are immutable in java?
Answer:
Because java uses the concept of string literal. Suppose there are 5 reference variables,allreferes to one object “sachin”.If one reference variable changes the value of the object, it will be affected to all the reference variables. That is why string objects are immutable in java.


Question-86: How many ways we can create the string object?
Answer:
There are two ways to create the string object, by string literal and by new keyword.


Question-87: How many objects will be created in the following code?
String s1=”Welcome”;

String s2=”Welcome”;

String s3=”Welcome”;
Answer:
Only one object


Question-88: Why java uses the concept of string literal?
Answer:
To make Java more memory efficient (because no new objects are created if it exists already in string constant pool.


Question-89: How many objects will be created in the following code?
String s=new String(“Welcome”);
Answer:
Two objects, one in string constant pool and other in non-pool(heap).


Question-90: What is the basic difference between string and stringbuffer object?
Answer:
String is an immutable object. StringBuffer is a mutable object.


Question-91: What is the difference between StringBuffer and StringBuilder ?
Answer:
StringBuffer is synchronized whereas StringBuilder is not synchronized.


Question-92: How can we create immutable class in java ?
Answer:
We can create immutable class as the String class by defining final class .


Question-93: What is the purpose of toString() method in java ?
Answer:
The to String() method returns the string representation of any object. If you print any object, java compiler internally invokes the toString() method on the object. So overriding the toString() method, returns the desired output, it can be the state of an object etc. depends on your implementation. Core Java : Nested classes and Interfaces Interview Questions


Question-94: What is nested class?
Answer:
A class which is declared inside another class is known as nested class. There are 4 types of nested class member inner class, local inner class, annonymous inner class and static nested class.


Question-95: Is there any difference between nested classes and inner classes?
Answer:
Yes ofcourse! inner classes are non-static nested classes i.e. inner classes are the part of nested classes.


Question-96: Can we access the non-final local variable, inside the local inner class?
Answer:
No, local variable must be constant if you want to access it in local inner class.


Question-97: What is nested interface ?
Answer:
Any interface i.e. declared inside the interface or class, is known as nested interface. It is static by default.


Question-98: Can a class have an interface?
Answer:
Yes, it is known as nested interface.


Question-99: Can an Interface have a class?
Answer:
Yes, they are static implicitly.

Core Java : Multi Threading Interview Questions


No comments:

Post a Comment

Copyright @ CrackMNC 2014-2024
Divas Nikhra Theme by Crack MNC