JAVA STRINGS

Bijen Adhikari
4 min readMay 26, 2024

Java Interview Questions

  1. What Is a Java String?

→ String is a sequence of characters or it is an array of characters.

For example
char [] ch={'b','i','j','e','n'};

NOTE:
String is a non-primitive datatype.
String is a class in java.
String is a predefined class present in java.lang package
Syntax :- 
public final class String implements java.io.Serializable, Comparable<String>, CharSequence, Constable, ConstantDesc {
}

2. To create string or to perform string operations, java has provided some predefined classes:

1. java.lang.String;
2. java.lang.StringBuffer;
3. java.lang.StringBuilder;
4. java.util.StringTokenizer;

3. Why String objects are immutable?

Answer : String objects are immutable which means that if we create any string object, then we cannot change its value.

Whenever we create string class object, objects created are immutable.

NOTE : String is a class and String are not immutable.   String objects are immutable.

4. Why String class is final?

Answer: String class is final because after making final we cannot inherit string class and thus we will not be able to change the string class properties.

OR,

String class is made final in Java in order to make the String class immutable.

--

--

Bijen Adhikari

Hi, I am Bijen from Nepal I write about Electronics, Electrical, Programming, Fitness. Also, I am a certified SSI Master Trainer.