in black and white
Main menu
Share a book About us Home
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics

More Java Pitfalls Share Reactor - Daconta M,C.

Daconta M,C. More Java Pitfalls Share Reactor - Wiley publishing, 2003. - 476 p.
ISBN: 0-471-23751-5
Download (direct link): morejavapitfallssharereactor2003.pdf
Previous << 1 .. 37 38 39 40 41 42 < 43 > 44 45 46 47 48 49 .. 166 >> Next

30 s[i] = rmeta.getColumnName(i);
31 }
33 // check to see if db columns are correct
34 assertTrue(s[1].equals("State"));
35 assertTrue(s[2].equals("AutomobileDealers"));
36 assertTrue(s[3].equals("BikeTrails"));
37 assertTrue(s[4].equals("Gyms"));
38 assertTrue(s[5].equals("Hospitals"));
39 assertTrue(s[6].equals("Laundromats"));
40 assertTrue(s[7].equals("Parks"));
41 assertTrue(s[8].equals("Physicians"));
42 assertTrue(s[9].equals("PetStores"));
43 assertTrue(s[10].equals("Restaurants"));
44 assertTrue(s[11].equals("RestAreas"));
45 }
46 catch(Exception e) {}
47 }
48 public void testCase3() {
50 try {
52 dbQueryBean db = new dbQueryBean();
53 assertTrue(db != null);
55 // Get the resultset meta-data
Listing 12.5 (continued)
JUnit: Unit Testing Made Simple 107
56 ResultSet rslt = db.getResultSet();
57 ResultSetMetaData rmeta = rslt.getMetaData();
59 // Use meta-data to determine column #ís in each row
60 int numColumns = rmeta getColumnCount();
61 String[] s = new String[numColumns];
63 for (int i=1; i < numColumns; i++) {
64 s[i] = rmeta.getColumnName(i)
65 }
67 while ( {
68 for (int i=1; i < numColumns; ++i) {
69 if (rslt.getString(i .trim().equals("Alabama")) {
70 t l s r s l a S' E t r e s s a getString(i).trim(), 2
71 t l s r s l a & E t r e s s a 1 + i g( n i r t S t e g .trim(), 2
72 t l s r s l a & E t r e s s a 2 + i g( n i r t S t e g .trim(), 2
"Bama Path");
73 t l s r s l a & E t r e s s a 3 + i g( n i r t S t e g .trim(), 2
"Mr. Muscles");
74 t l s r s l a & E t r e s s a 4) + i g( n i r t S t e g .trim(), 2
"St. Lukes");
75 t l s r s l a & E t r e s s a 5 + i g( n i r t S t e g .trim(), 2
"Mr. Clean");
76 t l s r s l a & E t r e s s a 6 + i g( n i r t S t e g .trim(), 2
77 t l s r s l a & E t r e s s a 7 + i g( n i r t S t e g .trim(), 2
"Dr. Nick");
78 t l s r s l a & E t r e s s a 8 + i g( n i r t S t e g .trim(), 2
"Mr. Pickles");
79 t l s r s l a & E t r e s s a 9 + i g( n i r t S t e g .trim(), 2
"Joes Pizzaria");
80 t l s r s l a & E t r e s s a getString(i+10).trim(), 2
81 t l s r s l a & E t r e s s a getString(i+11).trim(), 2
"Mr. Goodshoes");
82 break;
83 }
84 }
85 }
87 }
88 catch(Exception e) {}
89 }
90 public void testCase(int arg) {
91 }
92 }
Listing 12.5 (continued)
108 Item 13
JUnit allows developers and testers to assess module interfaces to ensure that information flows properly in their applications. Local data structures can be examined to verify that data stored temporarily maintains its integrity, boundaries can be checked for logic constraints, and error handling tests can be developed to ensure that potential errors are captured. All developers should implement the JUnit framework to test their software components and to make certain that development teams don't accept inconsistencies in their programs.
Item 13: The Failure to Execute
Executable JAR files, CLASSPATHs, and JAR conflicts challenge developers as they deploy their Java applications. Frequently, developers run into problems because of inadequate understanding of the Java extension mechanism. This pitfall costs a developer time and effort, and it can lead to substantial configuration control issues. I have seen numerous developers have problems with executable JAR files. They build desktop applications and deploy them via executable JAR files. However, for some reason, sometimes the JAR file will not execute.
When executed using the conventional java classname command, the code runs fine. The developer adds all of the classes to a JAR file and sets the main class attribute. Executing the java -jar jarname command, the following error returns:
Exception in thread "main" java.lang.NoClassDefFoundError:
at execution.application.ExecFrame.<init>( at execution.application.ExecApp.<init>( at execution.application.ExecApp.main(
This is one example of this familiar error for these developers. It is unable to find a particular class, in this case, com.borland.jbcl.layout.XYLayout. In this case, the developer did not select the proper JAR packaging for the JBuilder IDE. This is not unique to JBuilder, though, nor IDEs. This is part of a bigger issue in regard to tracking the classpath of applications.
Another classic example of this issue, prior to JDK 1.4, was the use of XML libraries like Xerces. This instance is not a problem in JDK 1.4, because XML is now part of the JVM, but developers cannot wait for every additional JAR to be bundled into the JDK.
So since these developers still haven't learned the underlying problem, they try something else. They try to ensure that the JAR was made correctly, the CLASSPATH is correct, and the JAR is uncompressed and executed in the conventional manner. Everything works right. Recompress it and it no longer works.
Previous << 1 .. 37 38 39 40 41 42 < 43 > 44 45 46 47 48 49 .. 166 >> Next