Page 2 of 2 FirstFirst 12
Results 21 to 35 of 35
Like Tree2Likes

Thread: Finding it difficult to understand java

  1. #21
    Gousia is offline Member
    Join Date
    Feb 2011
    Posts
    38
    Rep Power
    0

    Default

    Quote Originally Posted by sunde887 View Post
    Can you show an example? Type is generally the type of some object, String, Scanner, Integer, etc.

    http://download.oracle.com/javase/tu...methods.html-- The link here mentions the type refernece--

    In this page there is one method declared as
    public static <U> void fillBoxes(U u, List<Box<U>> boxes) {
    for (Box<U> box : boxes) {
    box.add(u);
    }
    }

    I am not able to understand it

  2. #22
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Everywhere you see 'U' it is a placeholder for a Generic type. This means that any type (except primitives) can be passed to the method.
    Java Code:
    public void methodOne(String s) { }
    
    public void methodTwo(K obj) { }
    For the first method you can only pass a String. For the second you can pass any reference type.

  3. #23
    Gousia is offline Member
    Join Date
    Feb 2011
    Posts
    38
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    Everywhere you see 'U' it is a placeholder for a Generic type. This means that any type (except primitives) can be passed to the method.
    Java Code:
    public void methodOne(String s) { }
    
    public void methodTwo(K obj) { }
    For the first method you can only pass a String. For the second you can pass any reference type.


    Thanks for the reply-- I am not able to understand the following line of code:

    public static <U> void fillBoxes(U u, List<Box<U>> boxes)

    Here what is meant by "List<Box <U>> boxes"

    Please if you could help me out

  4. #24
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    I just explained it!

  5. #25
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    That's one of the arguments. Normally you would see something like
    Java Code:
    List<Box<String>>()
    Java Code:
    List<Box<U>>()
    It's a list of boxes where each box has a parameter which is of type U.

  6. #26
    Gousia is offline Member
    Join Date
    Feb 2011
    Posts
    38
    Rep Power
    0

    Default

    Quote Originally Posted by sunde887 View Post
    That's one of the arguments. Normally you would see something like
    Java Code:
    List<Box<String>>()
    Java Code:
    List<Box<U>>()
    It's a list of boxes where each box has a parameter which is of type U.
    Thanks for the reply--

    We have declared a class called Box that has a parameter type U-- Now when we are saying that it is List of Boxes does that mean that we have a list of Box classes-- Please help me out

  7. #27
    Gousia is offline Member
    Join Date
    Feb 2011
    Posts
    38
    Rep Power
    0

    Default

    Thanks for that

  8. #28
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default

    The entire discussion in this thread shows that you are trying to run before you can walk. Go through the tutorial till you reach the lesson on Generics.
    The Java™ Tutorials

    Don't rush it.

    db
    sunde887 likes this.

  9. #29
    bigsonny is offline Senior Member
    Join Date
    Nov 2010
    Posts
    164
    Rep Power
    4

    Default

    Hello Gousia,

    I am going through the Oracle tutorial and they are correct. You just have to go through it step by step and learn as you go. Do all of the exercises at the end and it will give you a better understanding of what is going on. I am actually going through the generics 'chapter' right now and it made no sense the first time, but I re-read it a second time and combining that with what people are saying in this thread, it is beginning to make sense. Hang in there, but try to stay disciplined. I am not saying that it's impossible to fly if you can't walk, just that when you crash people are less likely to help you up if they realized that you never bothered learning to walk, so even if they help you up, you won't go anywhere and will become a burden for them.

    Having read your replies, you do sound like you are going through some sort of tutorial. Your biggest issue appears to be the understanding of the language. Look up the definition of "generic" and you'll understand pretty simply what it means. When it comes to using it, read a lot of code, try to understand them, do sample problems and ask questions. Good luck!

  10. #30
    Martino is offline Member
    Join Date
    Apr 2011
    Posts
    12
    Rep Power
    0

    Default

    I would like to advice you to buy a good book about Java.

    Buy this one:

    Introduction to Java Programming, 8th edition

    Author: Liang

    Link: Introduction to Java Programming, Eighth Edition

    This book will help!

  11. #31
    Joel's Avatar
    Joel is offline Member
    Join Date
    May 2011
    Location
    Placerville, CA
    Posts
    86
    Rep Power
    0

    Default

    Another wonderful book is the 9 in 1 Java for Dummies, by Doug Lowe. That might sound too elementary, but it isn't. Mr. Lowe goes into fantastic details and explains everything about java in fantastic detail in a way that is easy to understand. Also, it is 9 books in one, so it covers everything from Threads to Network programming to Swing in a very organized fashion. You should see mine on the bookshelf - it is literally torn and worn.

  12. #32
    Gousia is offline Member
    Join Date
    Feb 2011
    Posts
    38
    Rep Power
    0

    Default

    Quote Originally Posted by bigsonny View Post
    Hello Gousia,

    I am going through the Oracle tutorial and they are correct. You just have to go through it step by step and learn as you go. Do all of the exercises at the end and it will give you a better understanding of what is going on. I am actually going through the generics 'chapter' right now and it made no sense the first time, but I re-read it a second time and combining that with what people are saying in this thread, it is beginning to make sense. Hang in there, but try to stay disciplined. I am not saying that it's impossible to fly if you can't walk, just that when you crash people are less likely to help you up if they realized that you never bothered learning to walk, so even if they help you up, you won't go anywhere and will become a burden for them.

    Having read your replies, you do sound like you are going through some sort of tutorial. Your biggest issue appears to be the understanding of the language. Look up the definition of "generic" and you'll understand pretty simply what it means. When it comes to using it, read a lot of code, try to understand them, do sample problems and ask questions. Good luck!
    Thanks a lot for such a soft and encouraging reply-- I had made my mind to stop posting any of my query in this forum as i thought that may be this forum is for experts ,but now i feel that i can continue
    Thanks for such a valuable suggestion-- Thanks a lot

  13. #33
    bigsonny is offline Senior Member
    Join Date
    Nov 2010
    Posts
    164
    Rep Power
    4

    Default

    Quote Originally Posted by Gousia View Post
    Thanks a lot for such a soft and encouraging reply-- I had made my mind to stop posting any of my query in this forum as i thought that may be this forum is for experts ,but now i feel that i can continue
    Thanks for such a valuable suggestion-- Thanks a lot
    No problem. Don't be shy. Some answers are harsh, but that's part of the process. The good thing about this forum is that it is full of people with years of experience who are willing and able to help. The beauty of this section is that it's for people who are new to Java. So this will be really helpful for you. Ask a lot of questions, but when you post them (I think it's a rule), show that you try, try to post the code that you are working on and the errors messages that you are getting. Keep up the work!

  14. #34
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    People here tend to be helpful, just don't ask vague questions. If you don't want ridicule/harsh responses, provide good questions, proof that you tried, and use code tags. You also may want to provide full errors anytime they occur(in code tags, copy/paste, don't paraphrase).

    Also, I find the book "Head First Java" a great introductory book. It can teach you all the basics well and prepare you for more advanced topics.

  15. #35
    Joel's Avatar
    Joel is offline Member
    Join Date
    May 2011
    Location
    Placerville, CA
    Posts
    86
    Rep Power
    0

    Default

    The main thing to remember is not to come here to ask the vets to write code for you. The whole fun is treating programming like a puzzle. Very satisfying when you get something to work after a little bit of elbow grease research.
    Gousia likes this.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Difficult Error
    By javaguy2010 in forum New To Java
    Replies: 4
    Last Post: 06-30-2010, 12:13 PM
  2. Replies: 20
    Last Post: 05-26-2010, 06:18 PM
  3. A difficult question
    By tyang in forum New To Java
    Replies: 2
    Last Post: 01-31-2010, 09:45 PM
  4. Difficult compilation
    By pochis40 in forum Java Applets
    Replies: 10
    Last Post: 12-21-2009, 12:35 PM
  5. Java's web world is really difficult..
    By jurka in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 09-02-2008, 05:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •