Results 1 to 4 of 4
  1. #1
    nu01 is offline Member
    Join Date
    Feb 2017
    Posts
    2
    Rep Power
    0

    Question understanding java syntax

    i am a programmer but not java programmer, I just started java and can write many different programs with regular flow and syntax.

    I am studying hadoop examples. I see following

    public class newexample extends MapReduceBase
    implements Reducer<Text, IntWritable, Text, IntWritable> {
    public void reduce (Text key, Iterator<IntWritable> values,
    OutputCollector<Text, IntWritable> output, Reporter reporter)
    {
    ....


    I need some help or pointers to docs which will explain when the
    < , , , > (above marked red)is used in java and what is the term to say this in java

    Passing arguments to class or method is something i use but it is simple and I define the type. I have never seen this <,,,> syntax and would like to understand it. Any help with doc or someone who knows can response will help.

  2. #2
    SurfMan's Avatar
    SurfMan is online now Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,991
    Rep Power
    8

    Default Re: understanding java syntax

    That is called generics. Lots of information is to be found with teh Googels.

    Why Use Generics? (The Java™ Tutorials > Learning the Java Language > Generics (Updated))
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,342
    Rep Power
    12

    Default Re: understanding java syntax

    The guides are your best resource, but a dumb/fast example might look like this, consider:

    Java Code:
    ArrayList<String> myList = new ArrayList();
    By declaring the ArrayList in this way, you ensure that only Strings are allowed in "myList". If you omit the type, it defaults to Object, which may or may not be a bad thing - knowing the type of the contained objects is useful, and enforcing that type might be as well.

    This mechanism can also be used to write code for others to use without knowing the specifics of the data types they will be using. Allowing a generic type means they can specify types as I did above with the ArrayList. Your example shows code that was written with generics in mind - they are allowing you to declare the type of data used, for instance, the Iterator<IntWritable> is an iterator that iterates over "IntWritable" objects.

  4. #4
    nu01 is offline Member
    Join Date
    Feb 2017
    Posts
    2
    Rep Power
    0

    Default Re: understanding java syntax

    Thank you for both for your tips :) this was helpful.

Similar Threads

  1. Understanding the syntax for static and instance methods
    By Sam_JavaTheHut5580 in forum New To Java
    Replies: 13
    Last Post: 09-05-2016, 01:24 AM
  2. Java syntax
    By Icandoit in forum New To Java
    Replies: 8
    Last Post: 10-16-2014, 09:11 AM
  3. Don't understand this Java syntax.
    By Kareng in forum New To Java
    Replies: 9
    Last Post: 09-25-2012, 04:05 PM
  4. Replies: 0
    Last Post: 05-01-2012, 11:10 PM
  5. Understanding -- new Class() -- syntax.
    By AcousticBruce in forum New To Java
    Replies: 8
    Last Post: 12-14-2010, 12:53 AM

Posting Permissions

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