• Post Reply Bookmark Topic Watch Topic
  • New Topic

how come thread class is visible in following class?  RSS feed

 
kiran kumar reddy
Ranch Hand
Posts: 94
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



here how can Thread class is visible to that(CurrentThreadDemo) class?
 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tell us how the System class is visible to that class?
 
kiran kumar reddy
Ranch Hand
Posts: 94
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik Dey wrote:Tell us how the System class is visible to that class?


might be open to all java programs. technically i don't know? but both are present in java.lang package. is that is answer for my question if yes. can you clarify it please?
 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes are absolutely right.
 
kiran kumar reddy
Ranch Hand
Posts: 94
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik Dey wrote:Yes are absolutely right.

okay good, but can you please explain it, it means classes present in java.lang will be available for any java classes we create. how come internally it will happen? usually we extend classes by other class thus we can make use of one class in other class. OR we can use a class which is present in same package. so here every class we write will come under java.lang package? its so confusing to me.
 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, classes won't go under java.lang package, rather java.lang package will be imported in the class implicitly. Some one else might be able to give a much better explanation on this.
 
kiran kumar reddy
Ranch Hand
Posts: 94
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
will some one here explain it clearly.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kiran kumar reddy wrote:will some one here explain it clearly.



I am not sure if there is anything else to explain (or elaborate)... the Java compiler automatically imports the classes from the java.lang package.

Henry
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kiran kumar reddy wrote:will some one here explain it clearly.

I think swastik has explained it very clearly.

Why don't you tell what you think you should have to do in order to see the Thread class - ie, what is it about the setup that you don't understand?

Winston
 
kiran kumar reddy
Ranch Hand
Posts: 94
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
kiran kumar reddy wrote:will some one here explain it clearly.

I think swastik has explained it very clearly.

Why don't you tell what you think you should have to do in order to see the Thread class - ie, what is it about the setup that you don't understand?

Winston

yes swastik said that Thread class will be imported implicitly. like wise is there any other classes/packages that will as default will load/visible in our class?
does that mean classes present in java.lang will be automatically visible in our class(what we create)?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kiran kumar reddy wrote:
...does that mean classes present in java.lang will be automatically visible in our class(what we create)?

I would really encourage you to try out things on your own instead of just asking and waiting.

For convenience, the Java compiler automatically imports two entire packages for each source file: (1) the java.lang package and (2) the current package (the package for the current file).

Recommended reading http://docs.oracle.com/javase/tutorial/java/package/usepkgs.html
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

...does that mean classes present in java.lang will be automatically visible in our class(what we create)?



Yes, for example String or Exception. Usually we do not ponder long why they are automatically visible: we take them for granted.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kiran kumar reddy wrote:
yes swastik said that Thread class will be imported implicitly. like wise is there any other classes/packages that will as default will load/visible in our class?
does that mean classes present in java.lang will be automatically visible in our class(what we create)?


This is also explained in detail in section 7.4.3 seven of the Java Language Specification...

http://docs.oracle.com/javase/specs/jls/se7/html/jls-7.html#jls-7.4.3


EDIT ... actually, this phrase at the top of the section 7 may be clearer (Observability isn't exactly automatic import).

Section 7 of JLS wrote:A package consists of a number of compilation units (§7.3). A compilation unit automatically has access to all types declared in its package and also automatically imports all of the public types declared in the predefined package java.lang


Henry
 
kiran kumar reddy
Ranch Hand
Posts: 94
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
kiran kumar reddy wrote:
yes swastik said that Thread class will be imported implicitly. like wise is there any other classes/packages that will as default will load/visible in our class?
does that mean classes present in java.lang will be automatically visible in our class(what we create)?


This is also explained in detail in section 7.4.3 seven of the Java Language Specification...

http://docs.oracle.com/javase/specs/jls/se7/html/jls-7.html#jls-7.4.3


EDIT ... actually, this phrase at the top of the section 7 may be clearer (Observability isn't exactly automatic import).

Section 7 of JLS wrote:A package consists of a number of compilation units (§7.3). A compilation unit automatically has access to all types declared in its package and also automatically imports all of the public types declared in the predefined package java.lang


Henry


thank you Henry, now i got it, through your link specified, one thing i couldn't get is why you striked it , even though it cleared my doubt . anyways thank you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!