Jump to content

Wikipedia:Reference desk/Archives/Computing/2014 July 11

From Wikipedia, the free encyclopedia
Computing desk
< July 10 << Jun | July | Aug >> Current desk >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


July 11

[edit]

Need a clever solution

[edit]

This is a Wikipedia question that may be best asked here:

Is there a clever solution that would get around the need to rename the archives? Anna Frodesiak (talk) 07:04, 11 July 2014 (UTC)[reply]

Well, if the search function doesn't include the archives, the search function could likely be changed to do so. However, note that most people doing a regular search probably don't want to find archived results, so a separate search of the archives, or perhaps a single search with check boxes for whether to search current articles, archives, or both, might be in order. StuRat (talk) 13:31, 11 July 2014 (UTC)[reply]

CLASS PROFILE IN JAVA

[edit]

i need to view the predefined superclass of a class in java and for that i used javap <classname>.it works fine in jdk6 i mean, i defined a class and just need to show its inherited from java.lang.object.it works but when i tried same thing in jdk7 or jdk8 i dont get java.lang.object i.e the class profile doesnot show the predefined superclass in jdk7and jdk8.i dont understand why?182.18.179.2 (talk) 17:55, 11 July 2014 (UTC)[reply]

It is an intrinsic part of the language and the VM spec that all classes either directly extend java.lang.Object or extend a class that (recursively) does so. For a direct subclass of java.lang.Object, it's redundant for javap to explicitly say "extends java.lang.Object". There are various bugs in the Sun and OpenJDK trackers where they debate what the "right" thing is for it to do, including 6715757 and 7031005. They seem to have finally resolved, in the timeframe you note, that the appropriate thing to do is not to do so. -- Finlay McWalterTalk 18:30, 11 July 2014 (UTC)[reply]
I've looked a bit further at the source repository for JDK7. It's a bit of software patch hokey cokey. Prior to July 2008, the source for javap in JDK7 had code to suppress printing "extends java.lang.Object". Then they added printing it (back) in with this patch. But in March 2011 they took it out, with different code, in this patch. I've not looked in the patchsets for JDK6. -- Finlay McWalterTalk 21:48, 11 July 2014 (UTC)[reply]
Okay, here's the rest of the explanation:
  • Up to and including JDK6, there wasn't special code to handle this case, and it printed "extends java.lang.Object".
  • In 2007, for JDK7, they rewrote javap (details). I've checked the source for the two versions of javap, and the JDK7 version looks to be a clean rewrite with nothing much in common with the legacy version in JDK6 (which seems to date from the dark ages of Java1.x). Whoever did the new version decided not to print it - so they put in explicit code to suppress printing it.
  • That code was removed in 2008, as I noted above
  • New code to suppress it again was added in 2011, again as noted above
And that's where things are now. -- Finlay McWalterTalk 22:13, 11 July 2014 (UTC)[reply]

thank you very much sir @ Finlay McWalter.I am just a beginner in java so i was curious and a bit confused but now i understand it .thanks again.182.18.179.2 (talk) 04:25, 12 July 2014 (UTC)[reply]

If you want to see the full class hierarchy underlying an object, you can inspect it with an IDE like Eclipse. Or you can write code which will walk up the class hierarchy:
import javax.swing.JFrame;

public class Demo {
    public static void main (String[] args){
        JFrame f = new JFrame("hello");

        // print the class of f, and then all its superclasses
        Class c = f.getClass();
        while (c != null) {
            System.out.println(c);
            c = c.getSuperclass();
        }
    }
}
-- Finlay McWalterTalk 09:18, 12 July 2014 (UTC)[reply]