CC102
Computer Programming 1
Java
Input/Output
Ms. Gemmarie T. Muñoz
TABLE OF CONTENTS
Module 4: Java Input / Output
01 Built-In Packages
04 Input Types
02 Importing Packages
05 User Input
03 [Link]
06
07 JOptionClass
04
Java Package
A package in Java is used
to group related classes.
We use packages to
avoid name conflicts, and
to write a better
maintainable code.
Built-In Packages
Java API(Application Program
Interface) is a library of
prewritten classes, that are
free to use, included in the
Java Development
Environment
to help the programmer
manages input, databases
and etc.
Java Input/Output
▪ is used to process the input and produce the output.
▪ Java uses the concept stream to make I/O operations fast.
▪ The [Link] package contains all the classes required for input
and output operations.
Java Output
Importing Packages
IMPORT SPECIFIC CLASS
import [Link];
IMPORT WHOLE PACKAGE
import packagename.*;
[Link];
A class in the [Link] package that
can help programmers handle inputs
from the user.
Scanner Class
The Scanner class is used to get user input,
and it is found in the [Link] package.
Input Types
Method Description
nextBoolean() Reads a boolean value from the user
nextDouble() Reads a double value from the user
nextFloat() Reads a float value from the user
nextByte() Reads a byte value from the user
nextInt() Reads a int value from the user
nextShort() Reads a short value from the user
nextLong() Reads a long value from the user
nextLine() Reads a String value from the user
next().charAt(0); Reads a character value from the user
Note: We use different methods to read data of various types
User Input
String x;
Scanner s = new Scanner([Link]);
x = [Link]();
JOptionPane class
• The class JOptionPane is a component which provides standard methods to pop
up a standard dialog box for a value or informs the user of something.
• [Link];
Different Message Type
messageType Description
JOptionPane.ERROR_MESSAGE The error icon ( X ) is displayed in the dialog box
JOptionPane.INFORMATION_MESSAGE The information icon ( i ) is displayed in the dialog box
JOptionPane.PLAIN_MESSAGE
No icon appears in the for dialog box.
The question icon ( ? ) is displayed in the
JOptionPane.QUESTION_MESSAGE
dialog box
The warning icon ( ! ) is displayed in the dialog
JOptionPane.WARNING_MESSAGE
box
Example Output
Thank You
Do you have any questions for me before we go?