CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Thread: Linked List

  1. #1
    Join Date
    Jul 2009
    Location
    USA
    Posts
    49

    Thumbs up 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

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Linked List

    Quote Originally Posted by coder752 View Post
    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.

  3. #3
    Join Date
    Jul 2005
    Location
    Currently in Mexico City
    Posts
    568

    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!

  4. #4
    Join Date
    Jul 2009
    Location
    USA
    Posts
    49

    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.

  5. #5
    Join Date
    May 2002
    Location
    Lindenhurst, NY
    Posts
    867

    Re: Linked List

    Quote Originally Posted by coder752 View Post
    Not uh!
    Huh?

    Quote Originally Posted by coder752 View Post
    In case you didn't try to compile it urselves.
    Xeel said he just tried it!

    Quote Originally Posted by coder752 View Post
    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

  6. #6
    Join Date
    Jul 2005
    Location
    Currently in Mexico City
    Posts
    568

    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!

  7. #7
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    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.

  8. #8
    Join Date
    Jul 2005
    Location
    Currently in Mexico City
    Posts
    568

    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!

  9. #9
    Join Date
    Jul 2009
    Location
    USA
    Posts
    49

    Question 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();

  10. #10
    Join Date
    May 2009
    Location
    Lincs, UK
    Posts
    298

    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.

  11. #11
    Join Date
    Jul 2005
    Location
    Currently in Mexico City
    Posts
    568

    Re: Linked List

    Quote 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?

    Quote 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!

  12. #12
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    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 &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  13. #13
    Join Date
    Jul 2009
    Location
    USA
    Posts
    49

    Re: Linked List

    Quote Originally Posted by jcaccia View Post
    @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
  •  





Click Here to Expand Forum to Full Width

Featured