Mark Patrick

Ranch Hand
+ Follow
since Feb 22, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Mark Patrick

Neither compiles.

You can't add a number to an object using the '+' operator.

From the language specification...


15.15.3 Unary Plus Operator +

The type of the operand expression of the unary + operator must be a primitive numeric type, or a compile-time error occurs.

20 years ago
Justin,

As Marc stated, by default literal numbers are of type int, however, the literal you have in your code '109275027171421' is too big to fit into an int. It has to be able to be able to fit into an int before it can be casted to long. However, you can append 'L' to the end of the literal to tell the compiler that this number should be treated as a long instead of an int. Then it will compile.

20 years ago
Also, make sure that you put SEMConnector.class in a directory that matches your package 'com.rexam.sem.db.semDB', ie... \com\rexam\sem\db\semDB. That's basically what a package does, it specifies the directory where the class can be found.
20 years ago
What are you trying to accomplish by executing the OS "CD" command?
20 years ago
null means "nothing".

"" is a String object with in length of 0.
null means no object

Similar to Oracle. In Oracle, you can't perform math on NULL because NULL is non-existant. In Java, instead of meaning no-value, null means no object is assigned to the variable.
20 years ago
First, you need a variable name in there for it to be legal.


Question: does line 2 initialize 'b' to an empty string?

Line 1 create a String object and assigns it the reference 'a'.
Line 2 only creates a reference( 'b' ) to a String object. It will need to be assigned a String object before it can be used. If you try to use before-hand, you'll get a null pointer exception.

Which one is correct? Preference.
20 years ago
You have not overridden the toString() method inherited from the Object class.


This is what you actually have in your Storag class. You've actually overloaded toString(), not overridden it.



Which version of 'toString' is being called?
20 years ago
Without sorting the array, you'll have to loop through the array one time and test for the int value to be greater the previous greatest value:

20 years ago
I would say that none of those answers are correct.

1 is not true. That would mean than an inner class can only subclass the class that it is in.

2 is not correct because because you can extend any class, not just the Object class.

3 is not correct because you cannot extend an interface, the are implemented.

4 is not correct for the same reason as number 3.
PS...You can always try to compile and run the example to see what it does....
Answer 1 will not compile. The compiler checks that the method exist in the reference type, not the object type. At runtime, the JVM will dynamically bind the method that executes based on object type.

In this case, at compile time the compiler will confirm that every method called against variable 'a' is defined (at least abstract) in class Base. Attempting to call a.getFields() generates a compile error because getFields() is not defined in class Base.

It's easy in this case to see that variable 'a' will always contain an object of type Agg, but in more complex examples the compiler may not be able to confirm at compile-time the exact object type that the reference will contain...Hence, for safety sake, the compiler must complain.
Nick,

I know you have to do individual checks. Something like:


Doesn't seem that round-about.

How many different combinations of
would you need to handle this situation and how much harder would the code be to read. Your code only finds if 'a' is the greatest. You also couldn't easily put that kind of logic in a loop to find the largest number in a big array, but it could easily be done use Math.max().

20 years ago
Nick,

I know you have to do individual checks. Something like:


Doesn't seem that round-about.

How many different combinations of
would you need to handle this situation and how much harder would the code be to read. Your code only finds if 'a' is the greatest. You also couldn't easily put that kind of logic in a loop to find the largest number in a big array, but it could easily be done use Math.max().

20 years ago
You can't do it in one statement. Compare one statement to another and store the greatest value in a temp variable. Then compare the temp variable to the third variable and store the greate value in the temp variable...etc, until you've gone through all of the values.

Math.max() is a useful method for this comparison.
20 years ago
Look at class java.text.SimpleDateFormat.
20 years ago