Java: The Complete Reference, Ninth Edition

Herbert Schildt

Language: English

Pages: 1312

ISBN: 0071808558

Format: PDF / Kindle (mobi) / ePub

The Definitive Java Programming Guide

Fully updated for Java SE 8, Java: The Complete Reference, Ninth Edition explains how to develop, compile, debug, and run Java programs. Bestselling programming author Herb Schildt covers the entire Java language, including its syntax, keywords, and fundamental programming principles, as well as significant portions of the Java API library. JavaBeans, servlets, applets, and Swing are examined and real-world examples demonstrate Java in action. New Java SE 8 features such as lambda expressions, the stream library, and the default interface method are discussed in detail. This Oracle Press resource also offers a solid introduction to JavaFX.

Coverage includes:

  • Data types, variables, arrays, and operators
  • Control statements
  • Classes, objects, and methods
  • Method overloading and overriding
  • Inheritance
  • Interfaces and packages
  • Exception handling
  • Multithreaded programming
  • Enumerations, autoboxing, and annotations
  • The I/O classes
  • Generics
  • Lambda expressions
  • String handling
  • The Collections Framework
  • Networking
  • Event handling
  • AWT and Swing
  • The Concurrent API
  • The Stream API
  • Regular expressions
  • JavaFX
  • JavaBeans
  • Applets and servlets
  • Much, much more





















First, main( ) sets up an exception context and then calls demoproc( ). The demoproc( ) method then sets up another exception-handling context and immediately throws a new instance of NullPointerException, which is caught on the next line. The exception is then rethrown. Here is the resulting output: Caught inside demoproc. Recaught: java. lang. NullPointerException: demo The program also illustrates how to create one of Java’s standard exception objects. Pay close attention to this line: throw new NullPointerException("demo"); Here, new is used to construct an instance of NullPointerException.

At any time, a thread can be terminated, which halts its execution immediately. Once terminated, a thread cannot be resumed. Thread Priorities Java assigns to each thread a priority that determines how that thread should be treated with respect to the others. Thread priorities are integers that specify the relative priority of one thread to another. As an absolute value, a priority is meaningless; a higher-priority thread doesn’t run any faster than a lower-priority thread if it is the only thread running.

Out. println("Value of ap: " + ap); System. out. println(); ap = Apple. GoldenDel; // Compare two enum values. if(ap == Apple. GoldenDel) System. out. println("ap contains GoldenDel. \n"); // Use an enum to control a switch statement. switch(ap) { case Jonathan: System. out. println("Jonathan is red. "); break; case GoldenDel: System. out. println("Golden Delicious is yellow. "); break; case RedDel: System. out. println("Red Delicious is red. "); break; case Winesap: System. out. println("Winesap is red. "); break; case Cortland: System.

Out. println("display: outer_x = " + outer_x); } } Inner inner = new Inner(); inner. display(); } } } class InnerClassDemo { public static void main(String args[]) { Outer outer = new Outer(); outer. test(); } } The output from this version of the program is shown here: display: outer_x = 100 display: outer_x = 100 display: outer_x = 100 display: outer_x = 100 display: outer_x = 100 display: outer_x = 100 display: outer_x = 100 display: outer_x = 100 display: outer_x = 100 display: outer_x = 100 While nested classes are not applicable to all situations, they are particularly helpful when handling events.

Print("Number of args: " + v. length + " Contents: "); for(int x : v) System. out. print(x + " "); System. out. println(); } public static void main(String args[]) { // Notice how an array must be created to // hold the arguments. int n1[] = { 10 }; int n2[] = { 1, 2, 3 }; int n3[] = { }; vaTest(n1); // 1 arg vaTest(n2); // 3 args vaTest(n3); // no args } } The output from the program is shown here: Number of args: 1 Contents: 10 Number of args: 3 Contents: 1 2 3 Number of args: 0 Contents: In the program, the method vaTest( ) is passed its arguments through the array v.

Download sample


Rated 4.36 of 5 – based on 5 votes