Search This Blog

If you like any posts in this blog then click this icon which is present under the post

Sunday, 5 June 2011

Getting Values of Variables

 The values of the variable are displayed on the VUD by using the following two methods

                     i.            Print ( )
                   ii.            Println ( )

Print ( ) method prints the output on a line until a newline character is encountered.

Println ( ) method prints the output on a line and the control comes to the new line.


The above two methods are invoked by using the object systems. Out as shown below.


                                                        System.out.print  ( );
                                                        System.out.println ( );

Example:

System.out.print (“Good”)
System.out.print (“Luck”)

The output is 
                       Good Luck

System.out.println (“Good”)
System.out.println (“Luck”)

The output is 
                    Good
                     Luck

System.out.print (“Good\n”)
System.out.print (“Luck”)

The output is 
                         Good
                         Luck

Java variables:

A variables refers to the name given to the memory location to store data. A particular memory location is given only one name. yet this name is called a variable because this memory location can store sequence of different values during the execution of the same program.

Rules:
1. A variable name is formed with alphabets, digits, underscore( _ ), dollar sign.

2 . The first character must be an alphabet.


3 . Variable name can be of any length.


4 . Both upper case and lower case letters are used. But they are not treated as same.


5 . It should not be a keyword word.

Example:
1.       The following are some valid variable names.

AO          BASIC_PAY         volume                 B12

2.       The following are some invalid variable names.

Variable
Reason for invalidity
AB
9A
While
Period ( ) not allowed
The first character should be an alphabet
Reserved word

No comments:

Post a Comment

Followers