469,275 Members | 1,601 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

Depth of Inheritance

I need a java program to find the Depth of Inheritance of a java program source code is given as input file :)
Can any1 help me out with this
If so:) Thanks in Advance for Helping
Jun 29 '09 #1
17 3599
dmjpro
2,476 2GB
@chrisjohn2009
Are you talking about level of inheritance?
Then no need to have the source file, instead you need Class files of all the dependent classes.
Now have a look at Class.
Then look at Class.getSuperClass.
Jun 29 '09 #2
Sir,
could u help me out by explaining me a little bit in detail pl...
Jul 1 '09 #3
Sir,
i'm doing a Phd work on quality metrics . So basically i'm developing a tool for just checking out the number of classes,elements,inheritances & level of inheritance in a given source code like of morilla firefox ,rhino...

could me help me out with this sir... pl
Thanks in Advance for reply....& Guidance
Jul 1 '09 #4
JosAH
11,448 Expert 8TB
@chrisjohn2009
Have you read the API documentation for the Class class? Have a look at the very first article in this group; it contains a link to the API download site (from Sun). Download the API documentation and read it.

kind regards,

Jos
Jul 1 '09 #5
Thank you sir :)
i will read the documentation and if there is any sort of doubt i ll ask you sir...
Thank you for ur guidence sir :)


with Regards,
john
Jul 1 '09 #6
JosAH
11,448 Expert 8TB
@chrisjohn2009
You're welcome of course; that API documentation is a must read and you should have it stored on your hard drive; without it you're in the dark. Look at the Object class first; it's the 'mother of all classes'. It has a getClass() method that gives you a Class object; it describes the class the particular object is instantiated from. Next look at the API documentation for the Class class; it can return another Class object that represents the super class of the current class if any; otherwise it returns null. That is the building block for what you want to calculate.

kind regards,

Jos
Jul 1 '09 #7
Thank you sir :)
i will concentrate on it
Jul 1 '09 #8
i need to find the number of files & folders available in a particular folder...
i need to develop a program using java...
can any1 help me out with this using some code... pl
thanks for ur help in advance..

In regards,
john
Jul 9 '09 #9
JosAH
11,448 Expert 8TB
@chrisjohn2009
There's hardly any code to write because the File class does about all; have a look at the list() or listFiles() methods in that class.

kind regards,

Jos
Jul 9 '09 #10
dmjpro
2,476 2GB
@chrisjohn2009
First of all this is a different question, no relation with this thread.
Anyway for your solution, see File.listFiles.
Jul 10 '09 #11
Why do programmers are not comfortable with command line arguments or y they dont opt this techinique???
Jul 18 '09 #12
JosAH
11,448 Expert 8TB
@chrisjohn2009
Programmers who aren't comfortable with shells etc. are just junior programmers, too much influenced by a windows, graphical environment. Granted, the shell/cmd in Microsoft Windows isn't worth much but still ...

kind regards,

Jos
Jul 18 '09 #13
Thanks sir :)

Kind Regards,
john
Jul 19 '09 #14
Expand|Select|Wrap|Line Numbers
  1. public class ListFilesSubs {
  2.  
  3.  
  4.     private static void doSimpleFileListing(String dirName) {
  5.  
  6.         System.out.println();
  7.         System.out.println("Simple file listing...");
  8.         System.out.println("----------------------");
  9.  
  10.         File dir = new File(dirName);
  11.  
  12.         String[] children = dir.list();
  13.  
  14.         printFiles(children, dirName);
  15.  
  16.     }
  17.  
This is a sample code taken from the internet .
Could you help me with this. i get an error as
Error with new_dir
Either directory does not exist or is not a directory
i need to run this program .Pl do help me with this.
Thanks for ur help in advance :)

Kind Regards,
john
Jul 22 '09 #15
Expand|Select|Wrap|Line Numbers
  1. import java.io.File;
  2. import java.io.FilenameFilter;
  3. import java.io.FileFilter;
  4.  
  5.  
  6. public class ListFilesSubs {
  7.  
  8.  
  9.     private static void doSimpleFileListing(String dirName) {
  10.  
  11.         System.out.println();
  12.         System.out.println("Simple file listing...");
  13.         System.out.println("----------------------");
  14.  
  15.         File dir = new File(dirName);
  16.  
  17.         String[] children = dir.list();
  18.  
  19.         printFiles(children, dirName);
  20.  
  21.     }
  22.  
  23.  
  24.     /**
  25.      * Used to list the files / subdirectories in a given directory and also
  26.      * provide a filter class.
  27.      * @param dir Directory to start listing from
  28.      * @param ff  A string that can be used to filter out files from the
  29.      *            returned list of files. In this example, the String
  30.      *            values is used to only return those values that start
  31.      *            with the given String.
  32.      */
  33.     private static void doFileFilterListing(String dirName, String ff) {
  34.  
  35.         System.out.println("Filter file listing...");
  36.         System.out.println("----------------------");
  37.  
  38.         final String fileFilter = ff;
  39.  
  40.         File dir = new File(dirName);
  41.         FilenameFilter filter  = null;
  42.  
  43.         if (fileFilter != null) {
  44.  
  45.             // It is also possible to filter the list of returned files.
  46.             // This example uses the passed in String value (if any) to only
  47.             // list those files that start with the given String.
  48.             filter = new FilenameFilter() {
  49.                 public boolean accept(File dir, String name) {
  50.                      return name.startsWith(fileFilter);
  51.                 }
  52.             };
  53.         }
  54.  
  55.         String[] children = dir.list(filter);
  56.  
  57.         printFiles(children, dirName);
  58.  
  59.     }
  60.  
  61.  
  62.     /**
  63.      * Used to list the files / subdirectories in a given directory and also
  64.      * provide a filter class that only lists the directories.
  65.      * @param dir Directory to start listing from
  66.      */
  67.     private static void doFileFilterDirectoryListing(String dirName) {
  68.  
  69.         System.out.println("Filter Directory listing...");
  70.         System.out.println("---------------------------");
  71.  
  72.         File dir = new File(dirName);
  73.  
  74.         // The list of files can also be retrieved as File objects. In this
  75.         // case, we are just listing all files in the directory. For the sake
  76.         // of this example, we will not print them out here.
  77.         File[] files = (new File(dirName)).listFiles();
  78.  
  79.         // This filter only returns directories
  80.         FileFilter dirFilter = new FileFilter() {
  81.             public boolean accept(File dir) {
  82.                 return dir.isDirectory();
  83.             }
  84.         };
  85.  
  86.         files = dir.listFiles(dirFilter);
  87.  
  88.         for (int i=0; i<files.length; i++) {
  89.             System.out.println("[D] : " + files[i]);
  90.         }
  91.         System.out.println();
  92.  
  93.  
  94.     }
  95.  
  96.  
  97.     /**
  98.      * Utility method to print the list of files to the terminal
  99.      * @param children A String array of the file names to print out
  100.      * @param dirName  The given directory to start the listing at.
  101.      */
  102.     private static void printFiles(String[] children, String dirName) {
  103.  
  104.         if (children == null) {
  105.             System.out.println("Error with " + dirName);
  106.             System.out.println("Either directory does not exist or is not a directory");
  107.         } else {
  108.             for (int i=0; i<children.length; i++) {
  109.                 // Get filename of file or directory
  110.                 String filename = children[i];
  111.                 if ((new File(dirName + File.separatorChar + filename)).isDirectory()) {
  112.                     System.out.print("[D] : ");
  113.                 } else {
  114.                     System.out.print("[F] : ");
  115.                 }
  116.                 System.out.println(dirName + File.separatorChar + filename);
  117.             }
  118.         }
  119.         System.out.println();
  120.  
  121.     }
  122.  
  123.     /**
  124.      * Sole entry point to the class and application.
  125.      * @param args Array of String arguments.
  126.      */
  127.     public static void main(String[] args) {
  128.  
  129.         // Call the simple file listing method
  130.         doSimpleFileListing("new_dir");
  131.  
  132.         // Now do the file listing but pass in a String to filter the file list
  133.         if (args.length == 0) {
  134.             doFileFilterListing("new_dir", null);
  135.         } else {
  136.             doFileFilterListing("new_dir", args[0]);
  137.         }
  138.  
  139.         // Now do another example that only prints out the directories
  140.         doFileFilterDirectoryListing("new_dir");
  141.  
  142.     }
  143. }
Jul 22 '09 #16
I need help as soon as possible .
Kind regards.
john
Jul 22 '09 #17
JosAH
11,448 Expert 8TB
@chrisjohn2009
Don't rush us; first copy/paste the actual error message you get; don't make us guess. Then tell us what you expected and what the actual output of your program was. Your problem isn't more urgent to us than the other problems posted here.

kind regards,

Jos
Jul 22 '09 #18

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Hoagie | last post: by
4 posts views Thread by Ingo Nolden | last post: by
2 posts views Thread by Raed Sawalha | last post: by
22 posts views Thread by Matthew Louden | last post: by
2 posts views Thread by Onwuka Emeka | last post: by
6 posts views Thread by datamodel | last post: by
13 posts views Thread by softwaredoug | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.