Hello friends !! My todays topic is wrapper class and Escape sequence...
Wrapper class: As we have already studied about the primitive data type ,sometimes we go through a situation where we need to use objects instead of primitive data type(int ,char,float, double…..etc).In order to achieve such case Java introduce the concept of wrapper class for each primitive data type..
This wrapping is taken care of by the compiler.
When a primitive is used when an object is required the compiler boxes the primitive type in its wrapper class. …(this process is called boxing)…..
||’larly, the compiler unboxes the object to a primitive as well.
Number is an example of boxing and unboxing….
Example…
public class abc
{
public static void main(String args[])
{
Integer x = 7; // boxes int to an Integer object
x = x + 10; // unboxes the Integer to a int
System.out.println(x);
}
}
Output:
17
When x is assigned value 7 i.e. integer values, the complier boxes the integer bcoz x is integer objects..later, x is unboxed so that they can be added as integers.
Escape sequences:
Some character preceded by backslash (\) is known as escape sequence and has meaning known to compiler.
Here is a table which defines the use of some escape sequences:
Escape Sequence | Description |
\t | Insert a tab in the text at this point. |
\b | Insert a backspace in the text at this point. |
\n | Insert a newline in the text at this point. |
\r | Insert a carriage return in the text at this point. |
\f | Insert a form feed in the text at this point. |
\' | Insert a single quote character in the text at this point. |
\" | Insert a double quote character in the text at this point. |
\\ | Insert a backslash character in the text at this point. |
2 comments:
I would like to ask you to recommend other resources that have data about this topic if you are aware of any.
try this webiste http://www.roseindia.net/
Post a Comment
Hey thanax alot to comment i will revert you back soon...