1

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()
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
ray
  • 11
  • 1
  • That's because that's how the java API implemented it. The `System` is the class, thus it's uppercase by convention. The `out` is a variable, thus lowercase and `println()` is a method in `PrintStream`, thus lowercase by convention as well. In general Coding is *usually* case-sensitive so watch out for that. – 0xff Oct 03 '21 at 06:34
  • 1
    @BasilBourque: When editing the question and formatting the last part as code, you changed the capitalization - which I had taken to be the OP's *expected* capitalization. Given that the capitalization is the topic of the question, perhaps it's worth reverting that aspect? (I admit it's somewhat unclear given that the code snippet is just tacked on the end without any explanation of "this is what I have to write" or "this is what I expected to write".) – Jon Skeet Oct 03 '21 at 06:44
  • @JonSkeet I do not see how my edit changes the nature of the question, as the prose explicitly says *why "out" and "println" has the be in lowercase*. Showing uppercase immediately after asking "why lowercase" seems confusing to me. But given your name, sure, I'll make the rollback. – Basil Bourque Oct 03 '21 at 06:48
  • @BasilBourque: It says they *have* to be - but given the use of capitals in both the title and the question, I read that as "This is the code I'd expect to write." I don't *think* it was an accidental capitalization there. – Jon Skeet Oct 03 '21 at 06:49
  • Related: [*What is System, out, println in System.out.println() in Java*](https://stackoverflow.com/q/12002170/642706) and [*What's the meaning of System.out.println in Java?*](https://stackoverflow.com/q/3406703/642706) – Basil Bourque Oct 03 '21 at 06:57

3 Answers3

4

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
0

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

  • The `out` is a variable while the `println()` is a method of `out` which is of Type `PrintStream` – 0xff Oct 03 '21 at 06:40
  • 2
    I don't know what you mean by "instances of a type and a class respectively", but `out` is a field and `println()` is a method – Jon Skeet Oct 03 '21 at 06:40
0

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.)
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216