• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Questions :confused:

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
     
    Sheriff
    Posts: 11343
    Mac Safari Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Q3: Threads are objects too!
     
    Amit Sethi
    Ranch Hand
    Posts: 45
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    Mac Safari Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    Mac Safari Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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".
     
    Wanderer
    Posts: 18671
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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?
     
    We cannot change unless we survive, but we will not survive unless we change. Evolving tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic