




















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Examples and explanations of various java input/output (i/o) classes and data types, including printstream, bufferedreader, stringtokenizer, abstractclasses, interfaces, file, fileinputstream, randomaccessfile, and generic types. Topics covered include printing textual representations of java data types, reading strings from the console, string equality testing, and file i/o operations.
Typology: Slides
1 / 60
This page cannot be seen from the preview
Don't miss anything!





















































1
2
Type Contains Size, Coding, or
Values
boolean Truth value true, false
char Character Unicode characters (
bytes)
byte Signed integer 8 bit 2’s compliment
short Signed integer 16 bit 2’s compliment
int Signed integer 32 bit 2’s compliment
long Signed integer 64 bit 2’s compliment
float Real number 32 bit IEEE 754 floating point
double Real number 64 bit IEEE 754 floating point
5
7
// put this into a file named “A.java”
public class A {
// need the following method in a ‘main’ program // need the “Strings args[]” public static void main(String args[]) { //program code System.out.println("Hello world"); }
}
// Compile: javac A.java
// Run: java A Docsity.com
8
public static PrintStream err; public static PrintStream out; public static InputStream in;
public static void exit(int status);
10
Output: value of r: 100
11
public class print {
public static void main(String args[]) { int r = 100; System.out.println("value of r: " + r); // overloaded “+”: String concatenation }
} (^) Output:
value of r: 100
13
if (1 == 2) { System.out.println("Oh my god!");
} else {
System.out.println("Life is good.");
}
14
while (x > 0) { System.out.print("x= " + x + "\n"); x--;
}
for loops , do while,
break & continue,
switch
Same as in C and C++ languages
16
// example of reading a string from the console import java.io.BufferedReader; import java.io.InputStreamReader;
public class ReadFromConsole { public static void main(String args[]) throws Exception { System.out.print("Please enter a string: "); BufferedReader bufIn = new BufferedReader(new InputStreamReader(System.in)); String s = bufIn.readLine(); System.out.println("You entered: " + s); } }
17
String formatString = "%1$4s %2$10s %3$10s%n";
String name = console.readLine("[Please Provide Your Name]: "); // String returned from readLine doesn’t contain newline
http://www.javalobby.org/java/forums/t84689.html
19
20
public static String valueOf