This week's book giveaway is in the Testing forum.
We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!
See this thread for details.

H Melua

Ranch Hand
+ Follow
since Jan 04, 2005
Merit badge: grant badges
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by H Melua

Hi friends

I have a question please (just for the sake of understanding!)... Suppose that I have an ArrayList that holds any type of object... and that I will not know in advance what sort of objects it holds,

How can I automate the code below? Notice that I put "???" in the code because I don't know what the class is! Is there a way to find out automatically what the class is?
I know that Object.getClass() will return the class... but I don't know how to use it to make the code automatic!



At the moment there is no reason why I want to do something like this... I just want to understand how things work... ... I appreciate your patience!

Thanks
HannaH
8 years ago
^^^ ooh I see, thanks very much for that :D ...
9 years ago
@E Armitage

I see! The issue was confusing to me because I kept reading that interfaces "hide the implementation" (which is true ), then I thought, as a result the constructors will also not appear, since the interfaces don't include this detail...! But from your answer I understood that, there will be another step for gluing things together :D ... so thanks for that...

@Ulf Dittmer

:D I still remember you, one of the ever so helpful member, <3

Thanks for your help, that answer is a spot on! Because I was wondering, in the real world, how do people benefit from interfaces? If for example someone puts up a code on his website that people can use through the interface, without knowing the constructors! Now it makes all the sense that there should be a source for that...
At least for my simple use, I can request a method in the interface that returns an object of type someInterface, and just use that to check my syntax for the mean time...

Thanks again <3

@Campbell Ritchie
I remember you too :D ... I feel home again haha!!

His terminology makes full sense to me, because implementation in my view reflects the class that implements the interface... (I understand it may confuse others...)

@Winston Gutkowski
Thanks for your answer...
I meant I can't construct something like "someInterface s = new someInterface()".... because it doesn't have a constructor... I understand that you can still have s being of type someInterface, but the constructor has to be of the implementing class...

Yes I completely understand that I can create my own dummy class.... but the confusion is really on "does the interface hide all the details of the implementation given the fact interfaces do not list constructors"? Now I understand that it is possible using the method Ulf had mentioned...

Thanks again

@fred rosenberger

Thanks for your help... I understand that, I was also looking into how interfaces allow us to have common types to compare different objects... which I find very interesting :D ...


Thanks all... I really appreciate your help and the discussion that had taken place... please continue I'm learning new stuff <3

HannaH
9 years ago
Hi All

I have a simple question, but I just can't seem to get it :( ...

Suppose that we are two programmers in the group... and that we have agreed on the below interface... how can I benefit from his implementation if his class is hidden from me? I can't construct an object of type interface because it isn't a class... does that mean I always need to know his class name in order to use his implementation? And also the constructors?

What if the class is not yet implemented?



Thanks for your help :D
9 years ago
Thanks Campbell..

My tool is called LTSA version 2.3.

I am attempting to run the following command line "C:\j2re1.4.1_07\bin\java -cp .;lib\framework.jar;lib\ltsa.jar com.chatley.magicbeans.PluginManager ltsa.mb"

Both classes are in the ltsa.jar and in particular in a package called ic.doc.ltsa.lts;

The class was written in Java 5 source code, but was compiled in 1.4 compiler.

Class A overrides one of the *public* methods in its superclass B, and adds 3 move public methods. Class B does have private methods but those private methods are not called from A.

You may want to look at the code... you'll find A here A.java

and B here B.java

Both source codes are decompiled from the class originally compiled using the 1.4 compiler.

Thanks a lot
HannaH
13 years ago
Hello Friends

I'm having a problem getting on with an existing tool that would just not work kindly!

Being in a fighting process with this tool, I have managed somehow in getting it to run partially, but there are still remaining problems.

Well today's problem is called "java.lang.IllegalAccessError: class A cannot access its superclass B"

I feel I understand what the problem is... Class B is somehow protected from being access by class A! Now, if B was protected by making it private then the compiler should have caught that. But my problem arises during run time execution.
Both classes A & B are in the same package! And having looked at the code I can't see where B might have been protected .

Note: I am running the tool on Java 1.4 (yes! An old and dusted version of Java, but I have no choice other wise the tool experiences state explosion problem on Java 5 & 6!)

Any advice, ideas, suggestions... my mind is open to try anything!!

Thanks
HannaH
13 years ago
Hello

Is there a command that allows me to view all the directories in a classpath?

In other words, if I have a class path that is a collection of several jar files, e.g.
-cp hello.jar;help.jar;thankyou.jar;...

is there a way to see the exact directories inside these jars all at once, instead of viewing every single one at a time?

Thank you
HannaH
13 years ago
Thanks a lot Steve, Ernest

Well the problem is that the tool doesn't work well with Java 5, it crashes and goes into a state-explosion problem

But thanks for your help, I'll try your advise and see what happens.
13 years ago

Ernest Friedman-Hill wrote:Class file version 49 is JDK 1.5 (aka Java 5), so your "old JDK" is a little too old!



Does that mean the framework.jar file has been compiled by a newer version than my 1.4 java.exe?
and should I to recompile the framework.jar again using 1.4?

Thanks
13 years ago
Hello Java ranch!

I was given a tool to run that I need for my work, and I simply don't know how to fix these errors!
(I can post the tool if anyone wants to see it, its freely accessible by the author)

Now my problem is that it throws this exception
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/chatley/magicbeans/PluginManager (Unsupported major.minor version 49.0)

The files are already compiled! and as far as I'm aware from the author is that it works fine! I was told to run it using an old version of java, and that's what I'm doing... running it on j2re1.4.1_07
The files supposed to be compiled by the same Java version that I'm using to run it.
Question: how do I check the compiler version that was used to compile the classes?

I understand the problem as follows: I'm attempting to run the tool using an old version of JDK when the files have been compiled by a new compiler version. But this shouldn't apply because the author was running his files without a problem!

This is the command line I'm using (given to me by the author in the same file)...
C:\j2re1.4.1_07\bin\java -cp .;lib\framework.jar;lib\custom.jar;lib\xml.jar;lib\scenebeans.jar;lib\jel.jar;lib\jdom.jar;lib\LTL2Buchi.jar;lib\jcommon-0.6.1.jar;lib\jfreechart-0.8.1.jar com.chatley.magicbeans.PluginManager lib\framework.jar lib\ltsa.jar ic.doc.ltsa.HPWindow

The file that is causing the problem is in "lib\framework.jar"...

What would you advise me to do? Recompile the package again on the same compiler version as 1.4.1?

Thank you
HannaH
13 years ago
Thanks guys very much
That works
14 years ago
Hello

I was wondering, if I have an interface that is implemented by several classes, (lets say Shape)
and I've created an object of this type like this

Shape s;
s = new Rectangle();
// after few method calls I change the type of s to be triangle
s = new Triangle();

then how can I determine what type of shape s in this case? in other words, how can I know if s is now a triangle or rectangle?

is there a method in Java that checks the actual type of the object?

Thanks
HannaH
14 years ago

Originally posted by Joe Ess:


It doesn't matter. The default is the default (though with JDK 1.6, the default has changed).



thanks very much
14 years ago
Sorry Joe
what Gavin highlighted is correct, the journal does say for "applet"...

Sun�s JVM allowed the applet to allocate up to 60% of
the physical memory, but not more.


[ September 19, 2008: Message edited by: H Melua ]
14 years ago
Hello

I read in a journal that the default amount of memory available to SUN's JVM is 60%, how true is that?

Thanks
14 years ago