Java The Complete Reference, Seventh Edition
288 Part I: The Java Language The Predefined Streams As you know, all Java programs automatically import thejava.langpackage. Th ...
Chapter 13: I/O, Applets, and Other Topics 289 In Java, console input is accomplished by reading fromSystem.in. To obtain a char ...
290 Part I: The Java Language // read characters do { c = (char) br.read(); System.out.println(c); } while(c != 'q'); } } Here i ...
Chapter 13: I/O, Applets, and Other Topics 291 System.out.println(str); } while(!str.equals("stop")); } } The next example creat ...
292 Part I: The Java Language Writing Console Output Console output is most easily accomplished withprint( )andprintln( ), descr ...
To write to the console by using aPrintWriter, specifySystem.outfor the output stream and flush the stream after each newline. F ...
294 Part I: The Java Language Here,fileNamespecifies the name of the file that you want to open. When you create an input stream ...
Chapter 13: I/O, Applets, and Other Topics 295 // read characters until EOF is encountered do { i = fin.read(); if(i != -1) Syst ...
296 Part I: The Java Language // open output file try { fout = new FileOutputStream(args[1]); } catch(FileNotFoundException e) { ...
Chapter 13: I/O, Applets, and Other Topics 297 Many of the issues connected with the creation and use of applets are found in Pa ...
298 Part I: The Java Language After you enter the source code forSimpleApplet, compile in the same way that you have been compil ...
Chapter 13: I/O, Applets, and Other Topics 299 Execute the applet viewer, specifying the name of your applet’s source file. The ...
300 Part I: The Java Language Using instanceof Sometimes, knowing the type of an object during run time is useful. For example, ...
Chapter 13: I/O, Applets, and Other Topics 301 if(a instanceof A) System.out.println("a is instance of A"); if(b instanceof B) S ...
c is instance of C c can be cast to A ob now refers to d ob is instance of D ob now refers to c ob cannot be cast to D ob can be ...
Chapter 13: I/O, Applets, and Other Topics 303 keyword, which is used to declare native code methods. Once declared, these metho ...
304 Part I: The Java Language The library is loaded by theloadLibrary( )method, which is part of theSystemclass. This is its gen ...
Chapter 13: I/O, Applets, and Other Topics 305 After producing the necessary header file, you can write your implementation ofte ...
306 Part I: The Java Language Problems with Native Methods Native methods seem to offer great promise, because they enable you t ...
Chapter 13: I/O, Applets, and Other Topics 307 Here is an example that usesassert. It verifies that the return value ofgetnum( ) ...
«
12
13
14
15
16
17
18
19
20
21
»
Free download pdf