This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Questions :confused:  RSS feed

 
Amit Sethi
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q1.can some one plaese tell me the Full functionality of import statement ? & how it works? when we import certain packages or classes what is actually happen in jre ?

Q2. what is class namespace ? is there any thing called package namespace?

Q3. What is reference of thread mean ? how can a thread have refrence?


Q4.when we see classes through javap it only shows the decleration of methods ,where is actual implementation of methods ?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q1: The import statement is for the compiler only. It tells the compiler where (in which packages) to find classes that you are using in your source code. Nothing happens in the JRE while your program runs, because it's for the compiler only, and it's not in your code at runtime.

Q2: I guess you mean class scope here (instead of namespace). The class scope is the scope between the opening { and the closing } of the class. You can have member variables, methods, inner classes etc. in the class scope. There is nothing called a "package namespace".

Q3: I don't know what you mean with this question.

Q4: Try the -c command line option of javap (so: "javap -c ...") if you want to see the disassembled byte code. Read the documentation of the javap tool.
 
Campbell Ritchie
Marshal
Posts: 55799
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't use so many graemlins. And use a thread title which actually describes what you are asking about. And don't put so many different questions in the same posting.

As far as I remember: import statements have nothing to do with the JRE; it is the compiler which handles them.

There are four ways to import:-
  • import javax.swing.*; The compiler will go round the swing package and look for any classes named in the class code, and use their functionality wherever it is mentioned.
  • import javax.swing.JOptionPane; The compiler looks in the swing package to find the functionality whenever the JOptionPane class is mentioned. Probably the best way to use imports. Particularly useful if there are two classes with the same name (eg java.util.Timer and javax.swing.Timer)
  • import static java.lang.Math.*; If an identifier like cos(x) is used, the compiler looks for it in the Math class. This is a static import and can shorten your coding, but should be used sparingly to avoid confusion with other identifiers. It only works for static members of the Math class.
  • import static java.lang.Math.cos; A specific static import. The compiler will look in the Math class whenever the method identifier cos() is found.

  • I will let others answer your other 3 questions.

    CR
     
    marc weber
    Sheriff
    Posts: 11343
    Java Mac Safari
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Q3: Threads are objects too!
     
    Amit Sethi
    Ranch Hand
    Posts: 45
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Question no. 3 & 4 are not clear yet.

    If i m right then javap don't have any option to print function defination.(reffered java doc) But again the question is why sun don't want it's programmer to see method defination ?


    Thanks guys for ur support & answers.
     
    marc weber
    Sheriff
    Posts: 11343
    Java Mac Safari
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Amit Sethi:
    Question no. 3 & 4 are not clear yet.

    If i m right then javap don't have any option to print function defination.(reffered java doc) But again the question is why sun don't want it's programmer to see method defination ? ...

    I don't know that it's a question of "wanting." It's simply that javap is a "disassembler" -- not a "decompiler."

    With respect to the thread question, what exactly are you looking for?
     
    Amit Sethi
    Ranch Hand
    Posts: 45
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I really appriciate your feelings for a newbie & Thanks a lot Marc for your quick responces.

    Q2 is not clear yet.

    => can you suggest me any easy but in depth tutorial for multithreading.

    I have tried every option of javap but no option gives me the detailed implementation of methods in classes, can you suggest me any way how to get it?

    regards
    Amit Sethi
     
    marc weber
    Sheriff
    Posts: 11343
    Java Mac Safari
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Amit Sethi:
    ...=> can you suggest me any easy but in depth tutorial for multithreading...

    Try Java Tutorial - Threads.

    I have tried every option of javap but no option gives me the detailed implementation of methods in classes, can you suggest me any way how to get it?

    You would need a "decompiler" for that. I don't know of any to suggest -- try searching the internet for "java decompiler".
     
    Jim Yingst
    Wanderer
    Sheriff
    Posts: 18671
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    For Q3, you can see a very detailed implementation of the mthods using javap -c. It's in Java assemply language, defined by the JVM Specification. If you want to know that the original Java source file looked like, your best best is a decompiler, as the others have suggested.

    Q4 is probably going to remain unclear, because it's nonsense. Although perhaps it's asking about ThreadLocal?
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!