Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is the main difference between ...

 
krishna Gajarla
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi every body, can any one pl.tell

what is the main difference between

out.println() and

System.out.println()
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
out.println typically won't compile, without out being defined somewhere. Where did you see this?
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont believe you can use just out.println();.

have to have the System.out.println().

System.out = monitor.
System.in = from keyboard.

-Justin-
 
Henry Wong
author
Marshal
Pie
Posts: 21114
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think we are going to see a lot more "out.println()" in code -- especially after people start to get comfortable with abusing the static import feature of Java 5.

Henry
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In light of Henry's answer, the full answer is:

In JDK 1.4 and earlier, "out.println()" is a compile error, while "System.out.println()" works.

In JDK 1.5 and later, "out.println()" is a compile error unless the line

import static System.out;

(or equivalent) is included in the source file. If this line is included, then out.println() is identical to System.out.println().
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
In light of Henry's answer, the full answer is:

In JDK 1.4 and earlier, "out.println()" is a compile error, while "System.out.println()" works.

In JDK 1.5 and later, "out.println()" is a compile error unless the line

import static System.out;

(or equivalent) is included in the source file. If this line is included, then out.println() is identical to System.out.println().


Ouch, yes. I think Henry used the word "abuse" very wisely...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic