Primitive data types are built in data types which are a part of the wrapper classes. These wrapper classes are encapsulated in the java.lang package. Non primitive datatypes like Scanner class are a part of the utility package for which an object needs to be created. (a) To which package do the Character and Boolean classes belong? (b) Write the statement to access the Scanner class in the program.
Topic: Packages and the Scanner class
Answer
(a) java.lang (b) import java.util.Scanner; (followed by Scanner sc = new Scanner(System.in); to create the object)
(a) All the wrapper classes — Integer, Character, Boolean, Double and the rest — live in java.lang, together with String and Math. java.lang is imported automatically into every program, which is why you never write an import for Math or String. (b) Scanner lives in java.util, which is NOT imported automatically, so it must be brought in explicitly with import java.util.Scanner; (or import java.util.*;). The statement goes at the very top of the file, before the class definition. Read the question carefully: it asks for the statement to ACCESS the class, which is the import; creating the object is the separate second step shown above.