Skip to main content

The second simple program in java

Second simple program in java

                    In this post, we will discuss about the difference between println() and print()

println():
                  println() method shows the text as it is on the screen which is provided in println() method, which is followed by a new line. The cursor goes to the next line.


print():
                 print() method shows the text as it is on the screen which is provided in print() method, which is not followed by a new line. The cursor is still on the same line and not goes to the next line.


Following is the example, which helps us to understand the difference
Code:
          

Output:



As discussed above, we can see, the 3rd line contains print() method and 4th line contains println() method. So, after executing 3rd line, 
cursor still on the same line in output and print the 4th line of code on same line. After executing the 4th line, cursor goes to the next line in the terminal. This is the small difference in these methods.
Thanks.

Comments

Popular posts from this blog

Identifiers

Identifiers:                                         A name in java program is called identifier, which can be used for identification purposes. It can be a method name, variable name, class name, or label name . Rules for defining java identifiers: The only allowed characters in java identifiers are a - z, A - Z, 0 - 9, $, and _. If we are using other characters, we will get a compile-time error. Identifiers can't start with digits. Java identifiers are case sensitive. Of course, java is treated as case sensitive programming language. There is no limit for java identifiers but it is not recommended to take too lengthy identifiers. We can't use reserved words as identifiers. All predefined java class name and interface name we can use as identifiers.                     e.g.                         int String = 888 ;                         int Runnable = 999 ;                         Even this is valid, but it is not good programming practice. Examples Que 1) How many identi

Literals

Literals:                 Any constant value which can be assigned to the variable is called literal.     1 . Integer Literals:                                        For integral data types ( byte, short, int, long ), we can specify a literal value in the following base...                         a) Decimal literal (base 10):                                                     Allowed digits are 0 to 9.                                                                e.g.  int x = 10;                         b) Octal literal (base 8):                                                 Allowed digits are 0 to 7.                                             Literal should be prefixed with '0' (Zero).                                                       e.g.   int x = 010;                         c) Hexa decimal literal (base 16):                                                   Allowed digits are 0 to 9, a to f. For extra digits (a to f), we can use both lowercase and uppercase c

Reserved words

Reserved Words:                                    In java, some words are reserved to represent some meaning or functionality such types of words are called reserved words. Data type related keywords:                     1. byte                         2. short                         3. int                         5. long                         6. float                         7. double                         8. char Flow control-related keywords:                     1. if                         2. else                         3. switch                         4. case                         5. default                         6. do                         7. while                         8. for                         9. continue                         10. return                         11. break Modifiers related keywords:                     1. public                         2. private                         3. protected                         4. static