|
-
July 29th, 2009, 08:44 PM
#1
Linked List
How can I compile this code found on this site?
http://www.javafaq.nu/java-example-code-90.html
The code is too long to paste here.
It's a linked list example.
No, its not a dumb question because I know normally you use javac (the file).java
But for this example at this site, something technical is going on.
So thanks,
Coder752
-
July 30th, 2009, 05:12 AM
#2
Re: Linked List
 Originally Posted by coder752
But for this example at this site, something technical is going on.
it's code - it's expected to be technical - unless 'technical' has some new meaning I'm not familiar with...
So what happens when you try to compile it?
Being abstract is something profoundly different from being vague... The purpose of abstraction is not to be vague, but to create a new semantic level in which one can be absolutely precise...
E. Dijkstra
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
July 30th, 2009, 12:07 PM
#3
Re: Linked List
Emmm... you just compile it and run it... as any other java class. The class has no errors and compiles perfectly. I've just tried it.
Ye, it's not a dumb question, it's "how to compile a java class" question. Here's your answer:
- http://v1.dione.zcu.cz/java/docs/jdk...n32/javac.html (basic)
- http://ptolemy.eecs.berkeley.edu/~jo...compiling.html (alternative)
- http://www.iam.ubc.ca/guides/javatut....1/stepbystep/ (native method support)
A common error is wrong classpath settings for javac. Double-check them and it WILL work...
Last edited by Xeel; July 30th, 2009 at 12:10 PM.
Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?
I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)
//always looking for job opportunities in AU/NZ/US/CA/Europe :P
willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));
USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!
-
July 30th, 2009, 12:14 PM
#4
Re: Linked List
Not uh!
It's not as easy as pie.
In case you didn't try to compile it urselves.
This is what I get.
Note: LinkedListExample.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
-
July 30th, 2009, 01:08 PM
#5
Re: Linked List
 Originally Posted by coder752
Not uh!
Huh?
 Originally Posted by coder752
In case you didn't try to compile it urselves.
Xeel said he just tried it!
 Originally Posted by coder752
This is what I get.
Note: LinkedListExample.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

http://lmgtfy.com/?q=uses+unchecked+...afe+operations
-
July 30th, 2009, 01:45 PM
#6
Re: Linked List
LinkedListExample.java uses unchecked or unsafe operations
The reason for that is that you use Java v1.5+ compiler and that the class uses generics in this example. To the same List object String, Integer and ListIteratior objects are being added there. So it's impossible to define one data type for the List.
You can set a generic data type for every declaration and constructor, or just add @SuppressWarnings("unchecked") line before doLinkedListExample() method declaration so the compiler ignore the warnings.
Last edited by Xeel; July 30th, 2009 at 01:59 PM.
Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?
I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)
//always looking for job opportunities in AU/NZ/US/CA/Europe :P
willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));
USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!
-
July 30th, 2009, 02:35 PM
#7
Re: Linked List
A Google for "uses unchecked or unsafe operations" gives plenty of explanations of that warning. The OP seems unable to do a simple web search 
One can think effectively only when one is willing to endure suspense and to undergo the trouble of searching...
J. Dewey
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
July 30th, 2009, 03:50 PM
#8
Re: Linked List
A Google for "uses unchecked or unsafe operations" gives plenty of explanations of that warning. The OP seems unable to do a simple web search
I always thought it's more time consuming to type the posts on a forum and check answers later... Well, this is one of the miracles of imperfect human psychology... It's easier to ask how to make a cofee here than to search for the info even if the answer will be behind the very first link.
Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?
I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)
//always looking for job opportunities in AU/NZ/US/CA/Europe :P
willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));
USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!
-
July 30th, 2009, 06:20 PM
#9
Re: Linked List
So I put that line above that, and I get 2 errors. Now what?
Here's the new main.
Code:
/**
* Sole entry point to the class and application.
* @param args Array of String arguments.
*/
public static void main(String[] args) {
LinkedListExample listExample = new LinkedListExample();
@SuppressWarnings("unchecked") //the new line I added as suggested above.
listExample.doLinkedListExample();
}
}
It now says <identifier expected>
listExample.doLinkedListExample();
and <identifier expected>
listExample.doLinkedListExample();
-
July 30th, 2009, 06:48 PM
#10
Re: Linked List
@SuppressWarnings("unchecked") goes just before public void doLinkedListExample(), not when it is used.
Another way to avoid the warnings (without suppressing them) would be to declare the lists as List<Object> (to allow the addition of Integers and Strings to the same list), but then you would get an error with Collection.sort. If, instead of <Object> you use <String> (you'll also need to convert the integers to String) you'll have no problems with sort.
-
July 30th, 2009, 06:54 PM
#11
Re: Linked List
 Originally Posted by coder752
So I put that line above that, and I get 2 errors. Now what?
Do you understand what "method declaration" means?
 Originally Posted by jcaccia
Another way to avoid the warnings (without suppressing them) would be to declare the lists as List<Object> (to allow the addition of Integers and Strings to the same list), but then you would get an error with Collection.sort. If, instead of <Object> you use <String> (you'll also need to convert the integers to String) you'll have no problems with sort.
I've tried this already, can be solved with generic types. It's much easier just to suppress the warnings. In classes like this a programmer usually knows what he/she is doing so there is no real need for types definition anyways, same for casts.
Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?
I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)
//always looking for job opportunities in AU/NZ/US/CA/Europe :P
willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));
USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!
-
July 31st, 2009, 04:20 AM
#12
Re: Linked List
Again, if the OP had Googled @SuppressWarnings("unchecked"), the first link returned is to the Java Tutorial on Annotations, complete with full description and examples of use of that specific annotation... 
Surely this is the minimum amount of effort to expect?
I cannot teach anybody anything, I can only make them think...
Socrates
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
July 31st, 2009, 09:55 AM
#13
Re: Linked List
 Originally Posted by jcaccia
@SuppressWarnings("unchecked") goes just before public void doLinkedListExample(), not when it is used.
Another way to avoid the warnings (without suppressing them) would be to declare the lists as List<Object> (to allow the addition of Integers and Strings to the same list), but then you would get an error with Collection.sort. If, instead of <Object> you use <String> (you'll also need to convert the integers to String) you'll have no problems with sort.
Thanks! I just put that line in its new location, it works now.
I don't think I could do the other method Xeel said earlier since I didn't learn generics yet.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|