Results 1 to 3 of 3

Thread: Some keywords

  1. #1
    guisome is offline Member
    Join Date
    Feb 2011
    Posts
    7
    Rep Power
    0

    Default Some keywords

    Can any of you explain a bit these lines or just point out a tutorial.

    /**
    *Output:
    28
    */

    import java.util.Scanner;
    public class MainClass {
    public static void main(String args[]) {
    String instr = "Name: Joe Age: 28 ID: 77";

    Scanner conin = new Scanner(instr);

    conin.findInLine("Age:"); // find Age

    if (conin.hasNext())
    System.out.println(conin.next());
    else
    System.out.println("Error!");

    }
    }


    Scanner: findInLine(String str) : Scanner*«*java.util*«*Java by API

    What's the "conin" variable? What's the funcition of the "new" with "Scanner"? And the "(instr)" ? the part "conin.findInLine" is to make that specific API uses the conin's stored information? I don't mind reading tutorials if you want to point out some.

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

    Default

    Scanner is a class in the Java API since ver 1.5. It is a convenience class that allows you to read input.

    The new keyword you should have learnt in class. It is used anytime you want to create a new instance of a class.

    Passing instr to the Scanner constructor simply means that the String value in the instr variable is what the Scanner object will read.

    findInLine is a method of the Scanner class. Go to the Java API and read what it does.

  3. #3
    guisome is offline Member
    Join Date
    Feb 2011
    Posts
    7
    Rep Power
    0

    Default

    Thanks for answering this thread.

    Yes I got, I was just a bit confused regarding both "Scanner", but after reading a tutorial I realized it's a class variable not a comum type.

Similar Threads

  1. Lucene - Keywords and Strings
    By lucenenew in forum Lucene
    Replies: 0
    Last Post: 11-08-2009, 06:22 PM
  2. Demonstration of break and continue keywords
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 07:47 PM
  3. Reserved Keywords
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 11-30-2007, 09:54 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
  •