Paul Berry

Greenhorn
+ Follow
since Apr 07, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Paul Berry

OK, I got it set up so I can compile servlet code. As far as I can tell, you have to download GlassFish and there is no option to exclude it from installation.

Thanks
13 years ago
This bit of text in the servlet instructions has a link to Sun for downloading the EE JDK

Download the J2EE SDK(Java 2 Enterprise Edition Software Development Kit) from Sun, and install it. It is a supplement to the JDK you already have installed. You need to include the javaee.jar in your classpath.

I found the download at Oracle, but it has something called Glass Fish. Do I need/want it?

Thanks,

Paul
13 years ago
OK guys thank you. I'll have to remember that even though something is obvious to me, the compiler may not have enough information to determine; or guarantee.
13 years ago
Me and generics have yet to make peace. For something that *seems* so simple, it has been battle after battle.

I'm trying to make a Comparator to help with a sorting task. Below is a hacked down version of the class which still gives the error.
I'm not understanding why it won't compile. The error message doesn't help, because to me it says "Error ...apple does not equal apple!"
I gave it <T extends String> after having problems with a simple <T>. I figured that it didn't have enough information so I added the constraint. ("extends String" means String or lower in inheritance right?) But still it will not compile if I try to use any String methods on what I believe to be a String. Other attempts just yielded "cannot find symbol" errors. String is in java.lang, so it must be able to find it right? Anyway, any help on this would be great.

Thanks,
Paul



TestComparator.java:7: error: incompatible types
T myVariable = o1.toString();
^
required: T
found: String
where T is a type-variable:
T extends String declared in class TestComparator
1 error
13 years ago
Passed 8-GeekWatch after a few tries. Then passed OOP-1 DaysOld the first time! (it had to happen eventually, but I know wont happen often).
13 years ago
Rameshwar,
Throwing an exception is a requirement of the assignment.

Campbell Ritchie,
>>You must do something with that Exception, either catching it or declaring it and passing the Exception on to the next method.

So you're saying that I either declare it (which causes it to be passed to the next method) OR handle it right there, but not both declare it AND handle it right there? OK, so I passed it to main() and the handler in toInt wasn't used and main() had no way to deal with it. I think I get it now.

Thank you both!
13 years ago
I have a static method that throws an exception, but I am unable to declare the exception at that method. I get a compile errror in main():
unreported exception Exception; must be caught or declared to be thrown

then I delcare the exception at main() (where the errant method is called), and it compiles and runs fine. Why is my declaration at the method that actually throws the exception not accepted? I know if the exception is not handled where it is thrown, then the exception object is passed to the next method on the stack, but why does it get passed?

Thanks,
Paul


13 years ago
Oh yeah....no return type. Well that killed an hour this morning trying to figure out.

Thank you all!
13 years ago
Must be something very basic, but I can't see why this will not compile. The second attempt will compile, but not print the message in the constructor. What's going wrong?




The errors are:


C:\Documents and Settings\Paul\Desktop\ClassTest>javac MyClass.java
MyClass.java:6: error: constructor MyClass in class MyClass cannot be applied to
given types;
MyClass myClassInstance = new MyClass( i );
^
required: no arguments
found: int
reason: actual and formal argument lists differ in length
1 error


Also, if I modify it as below (remove the constructor argument and add a message to print) then it will compile but not print the message in the constructor when run.

13 years ago
OK, thanks for all the replies!

It will take some time to digest it all, but it's already clearer.
13 years ago
I'm somewhat familiar with multidimensional arrays in BASIC varieties, but not quite understanding the arrays of arrays.

In an array of arrays of integers it seems that everything up to but excluding the last index points to a reference variable. So in the case of

int myArray [] [] [] [] = new int [5] [4] [3] [2]
(pretend I filled the arrays with ints)

There are 5*4*3*2 = 120 integers as my data, and 5*4*3 = 60 reference variables that point to arrays (any of which I can manipulate or copy as a separate entity).

A few questions:
Is the above correct.....or am I as lost as I feel?

Isn't that a lot of waste (a high proportion of reference variable data as compared to my data)?

Is it a big advantage to have the ability cut an array into pieces by using all those reference variables?

Thank you,
Paul


13 years ago
Or if you looked anyway....

How do you delete or move a message (to the correct forum)?
13 years ago
I should say that there was an example in the book, but it was short and targeted to make their point and didn't help with my supplimental question.... super() or this() have to be first, but it didn't say why, or address running code prior to.

I get the impression that it would be bad style to put a lot of additional code in each overloaded constructor. Probably a maintenance nightmare to follow a bunch of branches after you call new. Ask for a new instance and just do what is necessary to get that new object instead of branching all over the place during object creation.

Thanks for the help!
14 years ago
Thanks for the replies!

OK, I can see how several different argument types can be handled, but....

What if the argument is not exactly what it needs to be (like an int instead of a float), or some other sort of manipulation/decision needs to happen *before* passing it down the line to another constructor? How would I have code that processes the arguments passed *before* calling this() ?

It seems that there is a deliberate design to keep that from happening. Is it just bad programming practice (like I should always process arguments before using "new"), or will something really bad happen if I could have code before "this()" ?

14 years ago
Hello everyone!

I'm reading Java Head First (pg 256), and am not understanding the stated use of this() for overloaded constructors. The scenario is that you have overloaded constructors that "all do the same thing", except they handle different argument types. So the use is to put a call to this() in all but one constructor and then put all the code in the 'real' constructor so you don't have to maintain the same code in multiple constructors. Ok, so............

I thought there might be some minor code in each constructor which 'massages' the parameters so they fit into the one main constructor then you call it with this(args). However since this() has to be the first thing in the constructor, I'm not seeing how that scheme is useful at all. I seem to be completely missing the point. Can I get some clarification?

Thank you,
Paul
14 years ago