0% found this document useful (0 votes)
20 views

Input - Output Files

The document discusses three ways to obtain input in Java programs: 1. The Scanner class in the java.util package can be used to read primitive types and strings from the console. 2. The Console class provides methods to read text and passwords from the command line without displaying passwords. 3. Implementing the Serializable interface allows Java classes to have their objects converted into a stream for serialization.

Uploaded by

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

Input - Output Files

The document discusses three ways to obtain input in Java programs: 1. The Scanner class in the java.util package can be used to read primitive types and strings from the console. 2. The Console class provides methods to read text and passwords from the command line without displaying passwords. 3. Implementing the Serializable interface allows Java classes to have their objects converted into a stream for serialization.

Uploaded by

Chippy T
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36

2.

Using Scanner class

● It is a class in java. util package


● used for obtaining the input of the primitive types like int, double, etc. and
strings.
● It is the easiest way to read input in a Java program
Using console class

● The Java Console class is be used to get input from console(command


line).
● It provides methods to read texts and passwords.
● If you read password using Console class, it will not be displayed to the
user.
Example
EXAMPLE
java.io.Serializable interface
Serializable is a marker interface (has no data member and method). It is used to
"mark" Java classes so that the objects of these classes may get a certain capability.

import java.io.Serializable;
public class Student implements Serializable{
int id;
String name;
public Student(int id, String name) {
this.id = id;
this.name = name; } }

In the above example, Student class implements Serializable interface. Now its objects
can be converted into stream.

You might also like