String class in Java

 on Friday, August 30, 2013  

What's this? String class in Java? If we make applications using any programming language, of course we can not escape from a string variable, its a variable that is used to display text messages on the monitor screen. Without this variable, we would be very difficult to make interactive applications. Believeor not?
Java adopts techniques “array -of – char” and “pointer - to- char” in creating a string variable that called Class String . There are two (2 ) types of Class String is used by Java , String are adopting “array to string” and StringBuffer are adopting “pointer to char” .




As we know , Java applications assume all entities as objects , everything is an object , so he says . Well ... String class is also considered an object you know , including his string data . The data string must be written in two quotation marks ( '' ) or two double quotation marks ( " " ) . All that exists between the sign above , will be treated / considered as data , including spaces . To menggelola this data , creates Java String Class . Up here we would have to understand why Java provides and make the String Class . This class is the original class / default of Java that can be used immediately after you install the Java system , because this class is loaded automatically too .

Like what the string data ? Here is an example of a string of data that can be used on Class String :
"Welcome"
" BKJ "
" 10374 "
" CR - 678 "

Then , how to load the data into a variable of type string ? To enter data into a string variable Java , there are two steps that must be implemented , which is a string variable declaration and initialization .

For the declaration can be done as in the following example :
String x2 ;
String jumlahrata2 ;
String dataku ;
In the example above , it is stated that the variables x2 , jumlahrata2 , and my data is declared as a variable of type string . Later , we can save a string data into a variable - the variable is .

The next thing we need to initialize the data . For initialization , there are three (3 ) different ways that can be used .
Method 1 :
String x2 = new String ( " Semarang " ) ;
Method 2 :
String jumlahrata2 ;
jumlahrata2 = new String ( " three -four " ) ;
Method 3 :
String dataku ;
dataku = ( "2007 " ) ;

Method 1 and method 2 is a good example of the use contructor . While the third is a testament to how privilege string , where string can be initialized directly without having to go through contruktor first.

Examples of programs :
class Coba_String
{
public static void main ( String ) [ ] args )
{
String x2 = new String ( " This is the contents x2 " ) ;
String x3 ;
String x4 ;
x3 = new String ( "This is the contents x3 " ) ;
x4 = "If the contents x4 " ;
System.out.println ( x2 ) ;
System.out.println ( x3 ) ;
System.out.println ( x4 ) ;
}

}
String class in Java 4.5 5 Darto Iwan Friday, August 30, 2013 What's this? String class in Java? If we make applications using any programming language, of course we can not escape from a string va...


No comments:

Post a Comment

Silakan berkomentar ....