Useful Java Classes                                    

In this lesson we will learn about some basic Java classes that are really useful . These useful classes are provided in the java.langpackage.

The first one is the Object class. The Object class is the base class of all the java classes. All Java classes are implicitly derived from the Object class. The Object class provides a number of useful methods like toString() etc. As all classes in Java are implicitly derived from the Object class, all the methods defined in the Object class are automatically available in every Java class.

The second useful Java class is the String class. Like in C++ the String class in Java issued to manipulate text.

String Creation:
String S1 = "hello", // initialize from a string literal
S2 = new String("bye"), // use new and the String constructor
S3 = new String(S1); // use new and a different constructor

String concatenation
String S1 = “hello” + “world”;
String S2 = S1 + “!”;
String S3 = S1 + 10;

The java.lang.String class has many useful methods. If you are interested, just explore the Srtring class in the Java documentation.

Java SDK also provides classes for primitive types. These include: Boolean, Integer, Double, Float etc. Note that variables of type bool, int, double, float etc. are not objects whereas variable of type Boolean, Integer, Double, Float etc. are objects.