Home > Enterprise >  Queries on System.Out.Println
Queries on System.Out.Println

Time:10-04

I have a question pertaining the method in the java, I have checked for online resources but i could not get the answer that i wanted. I would like to know why the "out" and "println" in the statement below has to be in lowercase letters ?

System.Out.Println()

CodePudding user response:

System is the name of a class (java.lang.System) and follows normal conventions.

out is a static field. This is conventionally named, but it's quite rare to see public fields for anything other than constants.

The type of out is PrintStream, and println() is just a method on PrintStream - again, conventionally named.

It may help (in terms of understanding) to break things up:

PrintStream outputStream = System.out; // Access to the out field
outputStream.println();                // Just a method call

Now as for why you have to use a lower case 'o' and a lower case 'p' in the code System.out.println() - that's just because Java is case sensitive, and the names are out and println(), not Out and Println(). They could have been named in the latter way, but that would violate normal Java naming conventions.

CodePudding user response:

The System part is a class. out and println() are both instances of a type and a class respectively. Someone can correct me if I'm wrong. Unless this isn't exactly what OP asked

CodePudding user response:

As Jon Skeet explained in his answer:

  1. Java is case sensitive,
  2. this (System, out and println) is how the respective identifiers for the class, field and method (respectively) have been specified, and
  3. this choice of identifiers conforms to the normal Java naming conventions.

There is however one small wrinkle.

The out variable is declared as a static final field and is (from a certain perspective) a constant. It arguably could therefore have been named as OUT rather than out.

Q: Why isn't it?

A: A couple of reasons:

  1. The conventions for what qualifies for "constant-ness" are unclear.
  2. While you cannot assign a value to System.out, the object it refers to is mutable by design.
  3. In fact, there is an official / supported way to change System.out ... despite it being declared as static final. (The System.setOut method.)
  • Related