Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
11 views

Module-4-JAVA-INPUT-OUTPUT

java

Uploaded by

Raven
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Module-4-JAVA-INPUT-OUTPUT

java

Uploaded by

Raven
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

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 java.util.Scanner
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 java.io package contains all the classes required for input
and output operations.

Java Output
Importing Packages

IMPORT SPECIFIC CLASS


import packagename.classname;

IMPORT WHOLE PACKAGE


import packagename.*;
java.util.Scanner;

A class in the java.util 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 java.util 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(System.in);

x = s.nextLine();
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.
• javax.swing.JOptionPane;
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?

You might also like