Depth of Inheritance 
June 29th, 2009, 03:31 AM
| | Newbie | | Join Date: Jun 2009
Posts: 14
| | |
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
| 
June 29th, 2009, 05:44 AM
|  | Lives Here | | Join Date: Jan 2007 Location: India (West-Bengal)
Posts: 2,452
| | | re: Depth of Inheritance Quote:
Originally Posted by chrisjohn2009 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 | 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.
| 
July 1st, 2009, 09:22 AM
| | Newbie | | Join Date: Jun 2009
Posts: 14
| | | re: Depth of Inheritance
Sir,
could u help me out by explaining me a little bit in detail pl...
| 
July 1st, 2009, 09:27 AM
| | Newbie | | Join Date: Jun 2009
Posts: 14
| | | re: Depth of Inheritance
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
| 
July 1st, 2009, 09:27 AM
|  | Expert | | Join Date: Mar 2007
Posts: 10,633
Provided Answers: 2 | | | re: Depth of Inheritance Quote:
Originally Posted by chrisjohn2009 Sir,
could u help me out by explaining me a little bit in detail pl... | 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
| 
July 1st, 2009, 09:30 AM
| | Newbie | | Join Date: Jun 2009
Posts: 14
| | | re: Depth of Inheritance
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
| 
July 1st, 2009, 09:56 AM
|  | Expert | | Join Date: Mar 2007
Posts: 10,633
Provided Answers: 2 | | | re: Depth of Inheritance Quote:
Originally Posted by chrisjohn2009 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 | 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
| 
July 1st, 2009, 09:58 AM
| | Newbie | | Join Date: Jun 2009
Posts: 14
| | | re: Depth of Inheritance
Thank you sir :)
i will concentrate on it
| 
July 9th, 2009, 06:26 PM
| | Newbie | | Join Date: Jun 2009
Posts: 14
| | | re: Depth of Inheritance
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
| 
July 9th, 2009, 07:49 PM
|  | Expert | | Join Date: Mar 2007
Posts: 10,633
Provided Answers: 2 | | | re: Depth of Inheritance Quote:
Originally Posted by chrisjohn2009 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.. | 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
| 
July 10th, 2009, 01:33 PM
|  | Lives Here | | Join Date: Jan 2007 Location: India (West-Bengal)
Posts: 2,452
| | | re: Depth of Inheritance Quote:
Originally Posted by chrisjohn2009 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 | First of all this is a different question, no relation with this thread.
Anyway for your solution, see File.listFiles.
| 
July 18th, 2009, 04:00 AM
| | Newbie | | Join Date: Jun 2009
Posts: 14
| | | re: Depth of Inheritance
Why do programmers are not comfortable with command line arguments or y they dont opt this techinique???
| 
July 18th, 2009, 08:23 AM
|  | Expert | | Join Date: Mar 2007
Posts: 10,633
Provided Answers: 2 | | | re: Depth of Inheritance Quote:
Originally Posted by chrisjohn2009 Why do programmers are not comfortable with command line arguments or y they dont opt this techinique??? | 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
| 
July 19th, 2009, 04:21 PM
| | Newbie | | Join Date: Jun 2009
Posts: 14
| | | re: Depth of Inheritance
Thanks sir :)
Kind Regards,
john
| 
July 22nd, 2009, 01:40 AM
| | Newbie | | Join Date: Jun 2009
Posts: 14
| | | re: Depth of Inheritance -
public class ListFilesSubs {
-
-
-
private static void doSimpleFileListing(String dirName) {
-
-
System.out.println();
-
System.out.println("Simple file listing...");
-
System.out.println("----------------------");
-
-
File dir = new File(dirName);
-
-
String[] children = dir.list();
-
-
printFiles(children, dirName);
-
-
}
-
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
Last edited by JosAH; July 22nd, 2009 at 07:03 AM.
Reason: added [code] ... [/code] tags
| 
July 22nd, 2009, 01:41 AM
| | Newbie | | Join Date: Jun 2009
Posts: 14
| | | re: Depth of Inheritance -
import java.io.File;
-
import java.io.FilenameFilter;
-
import java.io.FileFilter;
-
-
-
public class ListFilesSubs {
-
-
-
private static void doSimpleFileListing(String dirName) {
-
-
System.out.println();
-
System.out.println("Simple file listing...");
-
System.out.println("----------------------");
-
-
File dir = new File(dirName);
-
-
String[] children = dir.list();
-
-
printFiles(children, dirName);
-
-
}
-
-
-
/**
-
* Used to list the files / subdirectories in a given directory and also
-
* provide a filter class.
-
* @param dir Directory to start listing from
-
* @param ff A string that can be used to filter out files from the
-
* returned list of files. In this example, the String
-
* values is used to only return those values that start
-
* with the given String.
-
*/
-
private static void doFileFilterListing(String dirName, String ff) {
-
-
System.out.println("Filter file listing...");
-
System.out.println("----------------------");
-
-
final String fileFilter = ff;
-
-
File dir = new File(dirName);
-
FilenameFilter filter = null;
-
-
if (fileFilter != null) {
-
-
// It is also possible to filter the list of returned files.
-
// This example uses the passed in String value (if any) to only
-
// list those files that start with the given String.
-
filter = new FilenameFilter() {
-
public boolean accept(File dir, String name) {
-
return name.startsWith(fileFilter);
-
}
-
};
-
}
-
-
String[] children = dir.list(filter);
-
-
printFiles(children, dirName);
-
-
}
-
-
-
/**
-
* Used to list the files / subdirectories in a given directory and also
-
* provide a filter class that only lists the directories.
-
* @param dir Directory to start listing from
-
*/
-
private static void doFileFilterDirectoryListing(String dirName) {
-
-
System.out.println("Filter Directory listing...");
-
System.out.println("---------------------------");
-
-
File dir = new File(dirName);
-
-
// The list of files can also be retrieved as File objects. In this
-
// case, we are just listing all files in the directory. For the sake
-
// of this example, we will not print them out here.
-
File[] files = (new File(dirName)).listFiles();
-
-
// This filter only returns directories
-
FileFilter dirFilter = new FileFilter() {
-
public boolean accept(File dir) {
-
return dir.isDirectory();
-
}
-
};
-
-
files = dir.listFiles(dirFilter);
-
-
for (int i=0; i<files.length; i++) {
-
System.out.println("[D] : " + files[i]);
-
}
-
System.out.println();
-
-
-
}
-
-
-
/**
-
* Utility method to print the list of files to the terminal
-
* @param children A String array of the file names to print out
-
* @param dirName The given directory to start the listing at.
-
*/
-
private static void printFiles(String[] children, String dirName) {
-
-
if (children == null) {
-
System.out.println("Error with " + dirName);
-
System.out.println("Either directory does not exist or is not a directory");
-
} else {
-
for (int i=0; i<children.length; i++) {
-
// Get filename of file or directory
-
String filename = children[i];
-
if ((new File(dirName + File.separatorChar + filename)).isDirectory()) {
-
System.out.print("[D] : ");
-
} else {
-
System.out.print("[F] : ");
-
}
-
System.out.println(dirName + File.separatorChar + filename);
-
}
-
}
-
System.out.println();
-
-
}
-
-
/**
-
* Sole entry point to the class and application.
-
* @param args Array of String arguments.
-
*/
-
public static void main(String[] args) {
-
-
// Call the simple file listing method
-
doSimpleFileListing("new_dir");
-
-
// Now do the file listing but pass in a String to filter the file list
-
if (args.length == 0) {
-
doFileFilterListing("new_dir", null);
-
} else {
-
doFileFilterListing("new_dir", args[0]);
-
}
-
-
// Now do another example that only prints out the directories
-
doFileFilterDirectoryListing("new_dir");
-
-
}
-
}
Last edited by JosAH; July 22nd, 2009 at 07:04 AM.
Reason: added [code] ... [/code] tags
| 
July 22nd, 2009, 01:42 AM
| | Newbie | | Join Date: Jun 2009
Posts: 14
| | | re: Depth of Inheritance
I need help as soon as possible .
Kind regards.
john
| 
July 22nd, 2009, 07:07 AM
|  | Expert | | Join Date: Mar 2007
Posts: 10,633
Provided Answers: 2 | | | re: Depth of Inheritance Quote:
Originally Posted by chrisjohn2009 I need help as soon as possible .
Kind regards.
john | 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
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,535 network members.
|