Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Stupid question on the use of < >

  1. #1
    Member
    Join Date
    Jun 2014
    Posts
    33
    My Mood
    Inspired
    Thanks
    9
    Thanked 1 Time in 1 Post

    Default Stupid question on the use of < >

    I've been noticing these > and < markers in some code and in the Java API, but not been able to find any documentation on what exactly they are used for and how they work. If I only knew what they are called (especially in the Java context) I could of course google the answer... Do feel free to explain here or point me in the right direction, by all means.

    Just a basic concept where I'm not really sure what I'm looking at.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Stupid question on the use of < >

    Explore this trail, Java Operators.

  3. #3
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Stupid question on the use of < >

    These are used for multiple purposes. The most obvious would be for comparison of numbers, the '<' compares whether the left value is smaller then the value on the right or not.
    The '>' does it the other way around.
    They are also used for bit-shifting and they are used to define generic type parameters.

  4. The Following User Says Thank You to Cornix For This Useful Post:

    Baldyr (July 10th, 2014)

  5. #4
    Member
    Join Date
    Jun 2014
    Posts
    33
    My Mood
    Inspired
    Thanks
    9
    Thanked 1 Time in 1 Post

    Default Re: Stupid question on the use of < >

    define generic type parameters
    This is probably what I was wondering about. Off to practice my Google-fu, then:
    Generic Types (The Java™ Tutorials > Learning the Java Language > Generics (Updated))

    --- Update ---

    This is probably the answer:
    The type parameter section, delimited by angle brackets (<>), follows the class name. It specifies the type parameters (also called type variables) T1, T2, ..., and Tn.

  6. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Stupid question on the use of < >

    Ahh. Yes. More context, like MyClass<String>, would have been helpful.

  7. #6
    Member
    Join Date
    Jun 2014
    Posts
    33
    My Mood
    Inspired
    Thanks
    9
    Thanked 1 Time in 1 Post

    Default Re: Stupid question on the use of < >

    Quote Originally Posted by GregBrannon View Post
    MyClass<String>
    I guess part of my question was how to read something like that. Is this explained somewhere?

  8. #7
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Stupid question on the use of < >

    My shorthand 'context' is/was probably not the best, but this Oracle trail on generics should help you. The third page talks about the "generic declaration," but you should review the whole trail.

Similar Threads

  1. This may sound stupid but pls help
    By ahmer in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 9th, 2013, 01:39 PM
  2. what the stupid problem in using netbeans
    By ms_ceng in forum Java IDEs
    Replies: 3
    Last Post: December 13th, 2011, 03:28 AM
  3. Is this a stupid idea?
    By Kerr in forum Java Theory & Questions
    Replies: 4
    Last Post: November 30th, 2011, 01:29 PM
  4. "The import ___ cannot be resolved" (stupid noob question)
    By RobG in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 18th, 2010, 03:09 PM
  5. My doubt may be stupid
    By kalees in forum Object Oriented Programming
    Replies: 2
    Last Post: September 22nd, 2009, 02:38 AM