Search This Blog

21 June, 2011

String in Java

String is a class in java.


System.out.println(Somedata);


Consider the following example:-


class aaa
{
public void sam(int e)
{
System.out.println(e);
}
}
class bbb
{
public static aaa m= new aaa(); 
/*here m is a pointer or reference variable which points to an object of type aaa.*/
}
class ppp
{
public static void main(String mm[])
{
bbb.m.sam(20);
/* here m (which points to an object of type aaa) who gets invoked sam method. */
}
}


In the above example, bbb is a class which contains a static pointer named as (m) which points to an object of type aaa whose method sam gets invoked because of the bbb.m.sam(20); statement.
-----------------------------------------------------------------


The following class is predefined.


class PrintStream
{
public void print(long e)
{
//Some code to print the value of e.
}
/*print method has been overloaded to print long,int ,short,byte,double,float,char and boolean values.*/


public void println(long e)
{
//some code to print the value of e with \n 
}


/*print method has also been overloaded to print long , int, short, byte, double, float, char, and boolean values.*/
/*The only difference between print and println is that of a new line. */
}
class System
{
public static PrintStream out = new PrintStream();
}
/*The PrintStream and the System class are predefined and you should remember not to define them.*/
class ppp
{
public static void main(String mm[])
{
System.out.println('A');
System.out.println(20);
System.out.println('D');
}
}


As understood in the previous example bbb is a class which contains a static pointer named as(m) which points to an object of type aaa whose method sam gets invoked because of the bbb.m.sam(20); statement.


Predefined code:-


class sss
{
public void sam(int e)
{
System.out.println('D');
}
}


In the above example System is class which contains a Static pointer named as (out) which points to and object of type PrintStream whose method print or println gets invoked because of the System.out.println('D'); statement.
-----------------------------------------------------------------

No comments:

Post a Comment

Meetme@