Friday, May 15, 2009

Questions from Java "newbies"

I enjoyed being in a class with a wonderful group of students this week. The class was Intertech’s Complete Java. The group was not new to programming and they had a variety of software development backgrounds (some .NET developers, some mainframe developers, some Javascripters, some QA testers, and even a Python developer). This made for a lively class, full of great questions and plenty of prior experiences they (and I) could use to explore Java syntax and object-oriented programming concepts. A few of their questions required me to do a bit of research and therefore have earned their way as topics for discussion and learning in this blog.

1. In Eclipse, is there a way to run the Javadoc tool against my code? [Thanks Pradeep]
The answer is yes! While I knew this was possible, I wasn’t exactly sure of how this is done. It turns out using Javadoc from within Eclipse is a piece of cake. Given your Eclipse IDE is already configured to use the tools from a JDK, chances are good that it is already setup to generate Javadocs for your code with a simple menu selection. In Eclipse, look for the Project menu option on the Eclipse menu bar. Select Generate Javadoc… from the Project pull-down menu.

This should cause the Generate Javadoc window to open where you can specify what members should be included (private up to public) and where the documents generated should be put. If the JDK’s bin folder and/or the javadoc.exe tool can’t be found, the same window allows you to point Eclipse to a valid Javadoc generating tool and configure it per your needs.

Once the Javadocs are created, the documents are used by Eclipse to produce hovers over the classes, methods, variables, etc.

2. Can a list of stored procedures in a database be obtained from JDBC’s DatabaseMetaData class? [Thanks Bill]
Again the answer is yes! A DatabaseMetaData object provides all sorts of information about the database and database driver. The DatabaseMetaData interface defines 40+ fields and 100+ methods. The DatabaseMetaData object includes data about what schemas and tables are defined in the database. It allows developers to determine database capabilities programmatically, such as whether the database supports column aliasing. It also includes information such as the database name and version. To get a DatabaseMetaData object, request it from the JDBC Connection object.

Connection conn =
DatabaseMetaData md = conn.getMetaData();

With a DatabaseMetaData object, you can get the list of stored procedures from the database (provided your database supports stored procedures) by calling ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) on the DatabaseMetaData object. The ResultSet that is returned contains columns of data (listed below per the JDBC documentation) that describe the stored procedures.

· PROCEDURE_CAT String => procedure catalog (may be null)
· PROCEDURE_SCHEM String => procedure schema (may be null)
· PROCEDURE_NAME String => procedure name
· reserved for future use
· reserved for future use
· reserved for future use
· REMARKS String => explanatory comment on the procedure
· PROCEDURE_TYPE short => kind of procedure:
· procedureResultUnknown - Cannot determine if a return value will be returned
· procedureNoResult - Does not return a return value
· procedureReturnsResult - Returns a return value
· SPECIFIC_NAME String => The name which uniquely identifies this procedure within its schema.
Thanks to my students. If you have a "newbie" Java question, please, send it to me at

1 comment: