Posts

String Class in Java

Image
String class in Java This blog is related to the String class present in java. The following points are covered  below:- What is String? How to declare a String? Why String is immutable? What is a String Constant Pool? How to check that String objects have equal values? How to compare two String references? What is String?  Java provides a Stri ng class to manipulate the sequence of characters. The sequence of characters value is considered a String. Once a String object is created, we are not able to change its state. In other words, we can say that It is immutable.  String test="test"; //is equivalent to char c[]={'t','e','s','t'}; String class public final class String extends Object implements Serializable, Comparable<String>, CharSequence How to declare a String? //By using a new keyword String s1=new String(); //String literal String s2="Test"; ...

Call By Value in Java

Image
  Call by value in Java There are two ways we can call a method in Object oriented programming:- 1. Call by value 2. Call by reference In java, we only  used call by value mechanism. Let's first understand  how an object or variable is stored in java. 1. Primitive types :- These are value types. It stores value directly inside a memory.  2. Non-primitive or reference types :- These are reference types. It stores reference inside a memory not an object. The actual object is created somewhere else in heap memory. Here we are only storing reference of this object as a value which points out that object in heap.   The above example shows how the integer value of a variable is stored but for a reference variable it stores the memory information of an object which is created inside the heap memory. Call by Value Call by value is an approach where a method copies the value of an argument( actual parameter) into a formal parameter of that function.  When we pass ...