ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

What is a Java Scanner Class and How to Use it?

Updated on February 23, 2013

Things to know about Java Scanner Class

1. What is a Java Scanner Class?

2. How to use the Java Scanner Class?

What is a Java Scanner Class

Scanner class in java is a widely use pre-defined function by the Java programmers. It has many sets of methods but it is commonly use to read the input declared on different data types like int, double, and string.

How to use the Java Scanner Class?

Almost all of the programs uploaded in this website used Scanner class. You can see various of examples at the end of this hub. In Java Programming, whether the class is pre-defined or not, they both need to use a declared object in order to access the specific class. So, to access scanner we must declare an object first under the class scanner. The declaration of object is as follows:

Declaration # 1: Scanner declared_object_here = new Scanner (System.in);

Since Java is divided into pre-defined packages and packages holds pre-defined classes, scanner class is also inside a package called util. That means before you can use the scanner class inside the util, we must import it first in order to use the above declaration.

Declaration # 2: import java.util.Scanner;

The code above must be placed above the main class. But if you are using Netbeans IDE, just click the bulb-like with a red spot inline with the code of declaration #1, then ‘Add import java.util.Scanner’, it will automatically declare the util at the top of the main class. See the pictures below.

Java Scanner Class Implementation

To see the actual implementation of the java scanner class to running programs, check the free Java Source code samples that are given below.

If you find this hub helpful to you in any way, please rate and share it. Happy Programming!

Comments

    0 of 8192 characters used
    Post Comment

    • profile image

      amrender 2 years ago

      i want learn java program. i want a become java developers. how is tit possible .please tell me?

    • profile image

      kowrikanaka@gmail.com 21 months ago

      I have to learn java quickly.could you please say me procedure to learn java.

    Click to Rate This Article