DEV Community

Abishek
Abishek

Posted on

Interesting Thing That I Learned !!

Boring thing to other but interesting to me !!

  1. System.out.print()
  2. System.out.println()
  3. System.out.print("\n")

What is the different between this three lines code ?

  1. System.out.print();
  • prints text without adding a new line at the end
System.out.print("Hello ");
System.out.print("World!");
Enter fullscreen mode Exit fullscreen mode

o/p
Hello World

where to use:

  • When you want to continue printing on the same line.
  • Example: Loading indicators, progress messages.
  1. System.out.println()
  2. Prints text and moves to the next line automatically.
System.out.println("Hello");
System.out.println("World!");
Enter fullscreen mode Exit fullscreen mode

o/p
Hello
World

where to use:

  • When you want each output to appear on a new line.
  • Example: Displaying lists, logging, or structured outputs.

3.System.out.print("\n")

  • same as println but you manually insert a newline using \n.
System.out.print("Hello\n");
System.out.print("World!");
Enter fullscreen mode Exit fullscreen mode

o/p
Hello
World

where to use:

  • When you need custom placement of newlines inside a single string.
  • Example: Multi-line messages, formatted tables.

Found a shortcut to type easily System.out.println() in IntelliJ

--> Type sout in the intellij, it automatically print System.out.println(). i think it's only work in inteelij.

Recalling my memories

what is declaration and initialization in java?

Declaration:
declared the int (int)

public class Variable {  
    public static void main(String[]args){  
        int a;  
        System.out.println(a);  
    }  
}
Enter fullscreen mode Exit fullscreen mode

o/p
java: variable a might not have been initialized

Initialization:
initializing the value (int=5)

public class Variable {  
    public static void main(String[]args){  
        int a=5;  
        System.out.println(a);  
    }  
}
Enter fullscreen mode Exit fullscreen mode

o/p
5

## HAPPY 19th BIRTHDAY !!!

  • now i'm a part of linux mint community.little weight distro and beginner friendly.
  • It is one of the best alternatives to Microsoft Windows and Apple MacOS.
  • Linux Mint is a community-developed Linux distribution based primarily on Ubuntu, with an alternative version based on Debian known as Linux Mint Debian Edition (LMDE). It is available for x86-64 systems, while LMDE also supports the IA-32 architecture. First released in 2006, Linux Mint is often noted for its ease of use, out-of-the-box functionality, and appeal to desktop users.[7][8] It comes bundled with a selection of free and open-source software. The default desktop environment is Cinnamon, developed by the Linux Mint team, with MATE and Xfce available as alternatives more to know https://en.wikipedia.org/wiki/Linux_Mint

signing off!!!

Top comments (0)