You are previewing Beginning Java 8 APIs, Extensions and Libraries Swing, JavaFX, JavaScript, JDBC and Network Programming APIs.
O'Reilly logo
Beginning Java 8 APIs, Extensions and Libraries Swing, JavaFX, JavaScript, JDBC and Network Programming APIs

Book Description

Beginning Java 8 APIs, Extensions and Libraries completes the Apress learning Java journey and is a comprehensive approach to learning the Java programming language extensions and available APIs and libraries, including the new JavaFX APIs.

This book covers the key extensions of the Java programming language such as Swing, JavaFX, network programming, and JDBC. Each topic starts with a discussion of the topic's background. A step-by-step process, with small snippets of Java code, provides easy-to-follow instructions. At the end of a topic, a complete and ready-to-run Java program is provided. This book contains over 130 images and diagrams to help you visualize and better understand the topics. More than 130 complete programs allow you to practice and quickly learn the topics.

The Swing chapters discuss various aspects of working with a GUI, from the very basic concepts of developing a Swing application, to the most advanced topics, such as decorating a Swing component with a JLayer, drag-and-drop features, Synth Skinnable L&F, etc.

The chapter on network programming covers the basics of network technologies first, and then, the advanced topics of network programming, using a Java class library. It covers IPv4 and IPv6, addressing schemes, subnetting, supernetting, multicasting, TCP/IP sockets, UPD sockets, asynchronous socket I/O, etc.

The chapter on JDBC provides the details of connecting and working with databases such as Oracle, SQL Server, MySQL, DB2, Java DB (Apache Derby), Sybase, Adaptive Server Anywhere, etc. It contains a complete discussion on processing a ResultSet and a RowSet. It discusses how to use the RowSetFactory, to obtain a RowSet object of a specific type. Working with Large Objects (LOBs), such as Blob, Clob, and NClob, is covered in detail with Java code examples and database scripts.

Table of Contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Author
  8. About the Technical Reviewer
  9. Acknowledgments
  10. Foreword
  11. Introduction
  12. Chapter 1: Introduction to Swing
    1. What Is Swing?
    2. The Simplest Swing Program
    3. Components of a JFrame
    4. Adding Components to a JFrame
    5. Some Utility Classes
      1. The Point Class
      2. The Dimension Class
      3. The Insets Class
      4. The Rectangle Class
    6. Layout Managers
      1. FlowLayout
      2. BorderLayout
      3. CardLayout
      4. BoxLayout
      5. GridLayout
      6. GridBagLayout
      7. SpringLayout
      8. GroupLayout
      9. The null Layout Manager
    7. Creating a Reusable JFrame
    8. Event Handling
    9. Handling Mouse Events
    10. Summary
  13. Chapter 2: Swing Components
    1. What Is a Swing Component?
    2. JButton
    3. JPanel
    4. JLabel
    5. Text Components
      1. JTextComponent
      2. JTextField
      3. JPasswordField
      4. JFormattedTextField
      5. JTextArea
      6. JEditorPane
      7. JTextPane
    6. Validating Text Input
    7. Making Choices
    8. JSpinner
    9. JScrollBar
    10. JScrollPane
    11. JProgressBar
    12. JSlider
    13. JSeparator
    14. Menus
    15. JToolBar
    16. JToolBar Meets the Action Interface
    17. JTable
    18. JTree
    19. JTabbedPane and JSplitPane
    20. Custom Dialogs
    21. Standard Dialogs
    22. File and Color Choosers
      1. JFileChooser
      2. JColorChooser
    23. JWindow
    24. Working with Colors
    25. Working with Borders
    26. Working with Fonts
    27. Validating Components
    28. Painting Components and Drawing Shapes
    29. Immediate Painting
    30. Double Buffering
    31. JFrame Revisited
    32. Summary
  14. Chapter 3: Advanced Swing
    1. Using HTML in Swing Components
    2. Threading Model in Swing
    3. Pluggable Look and Feel
    4. Skinnable Look-and-Feel
    5. Drag and Drop
    6. Multiple Document Interface Application
    7. The Toolkit Class
    8. Decorating Components Using JLayer
    9. Translucent Windows
    10. Shaped Window
    11. Summary
  15. Chapter 4: Applets
    1. What Is an Applet?
    2. Developing an Applet
    3. Writing an Applet
    4. Deploying an Applet
      1. Creating the HTML Document
      2. Deploying Applets in Production
      3. Deploying Applets for Testing
    5. Installing and Configuring Java Plug-in
      1. Installing the Java Plug-in
      2. Opening the Java Control Panel
      3. Configuring Java Plug-in
    6. Viewing an Applet
    7. Using the appletviewer to Test Applets
    8. Using the codebase Attribute
      1. Example 1
      2. Example 2
      3. Example 3
    9. The Life Cycle of an Applet
      1. The init() Method
      2. The start() Method
      3. The stop() Method
      4. The destroy() Method
    10. Passing Parameters to Applets
    11. Publishing the Applet’s Parameter Information
    12. Publishing the Applet’s Information
    13. Other Attributes of the <applet> Tag
    14. Using Images in an Applet
    15. Playing Audio Clips in an Applet
    16. Interacting with the Applet’s Environment
    17. Communion of Applet, HTML, and JavaScript
    18. Packaging Applets in Archives
    19. The Event Dispatching Thread and Applets
    20. Painting in Applets
    21. Is the Java Code Trusted?
    22. Security Restrictions for Applets
    23. Signing Applets
      1. Step 1: Developing an Applet
      2. Step 2: Packaging Class Files into a JAR File
      3. Step 3: Generating Private/Public Key Pair
      4. Step 4: Signing the JAR File
      5. Step 5: Creating the HTML File
      6. Step 6: Viewing the Signed Applet
    24. Summary
  16. Chapter 5: Network Programming
    1. What Is Network Programming?
    2. Network Protocol Suite
    3. IP Addressing Scheme
      1. IPv4 Addressing Scheme
      2. IPv6 Addressing Scheme
    4. Special IP Addresses
      1. Loopback IP Address
      2. Unicast IP Address
      3. Multicast IP Address
      4. Anycast IP Address
      5. Broadcast IP Address
      6. Unspecified IP Address
    5. Port Numbers
    6. Socket API and Client-Server Paradigm
      1. The Socket Primitive
      2. The Bind Primitive
      3. The Listen Primitive
      4. The Accept Primitive
      5. The Connect Primitive
      6. The Send/Sendto Primitive
      7. The Receive/ReceiveFrom Primitive
      8. The Close Primitive
    7. Representing a Machine Address
    8. Representing a Socket Address
    9. Creating a TCP Server Socket
    10. Creating a TCP Client Socket
    11. Putting a TCP Server and Clients Together
    12. Working with UDP Sockets
    13. Creating a UDP Echo Server
    14. A Connected UDP Socket
    15. UDP Multicast Sockets
    16. URI, URL, and URN
    17. URI and URL as Java Objects
    18. Accessing the Contents of a URL
    19. Non-Blocking Socket Programming
    20. Socket Security Permissions
    21. Asynchronous Socket Channels
      1. Setting Up an Asynchronous Server Socket Channel
      2. Setting up an Asynchronous Client Socket Channel
      3. Putting the Server and the Client Together
    22. Datagram-Oriented Socket Channels
      1. Creating the Datagram Channel
      2. Setting the Channel Options
      3. Sending Datagrams
    23. Multicasting Using Datagram Channels
      1. Creating the Datagram Channel
      2. Setting the Channel Options
      3. Binding the Channel
      4. Setting the Multicast Network Interface
      5. Joining the Multicast Group
      6. Receiving a Message
      7. Closing the Channel
    24. Further Reading
    25. Summary
  17. Chapter 6: JDBC API
    1. What Is the JDBC API?
    2. System Requirements
    3. Types of JDBC Drivers
      1. JDBC Native API Driver
      2. JDBC-Net Driver
      3. JDBC Driver
    4. A Brief Overview of Java DB
      1. Java DB Installation Files
      2. Configuring Java DB
      3. Running the Java DB Server
    5. Creating a Database Table
      1. Oracle Database
      2. Adaptive Server Anywhere Database
      3. SQL Server Database
      4. DB2 Database
      5. MySQL Database
      6. Java DB Database
    6. Connecting to a Database
      1. Obtaining the JDBC Driver
      2. Setting up the CLASSPATH
      3. Registering a JDBC Driver
      4. Setting the jdbc.drivers System Property
      5. Loading the Driver Class
      6. Using the registerDriver() Method
      7. Constructing a Connection URL
      8. Establishing the Database Connection
    7. Setting the Auto-Commit Mode
    8. Committing and Rolling Back Transactions
    9. Transaction Isolation Level
      1. Dirty Read
      2. Non-Repeatable Read
      3. Phantom Read
    10. JDBC-Types-to-Java-Types Mapping
    11. Knowing About the Database
    12. Executing SQL Statements
      1. Results of Executing a SQL Statement
      2. Using the Statement Interface
      3. Using the PreparedStatement Interface
      4. CallableStatement Interface
    13. Processing Result Sets
      1. What Is a ResultSet?
      2. Getting a ResultSet
      3. Getting the Number of Rows in a ResultSet
      4. Bidirectional Scrollable ResultSets
      5. Scrolling Through Rows of a ResultSet
      6. Knowing the Cursor Position in a ResultSet
      7. Closing a ResultSet
    14. Making Changes to a ResultSet
      1. Inserting a Row Using a ResultSet
      2. Updating a Row Using a ResultSet
      3. Deleting a Row Using a ResultSet
    15. Handling Multiple Results from a Statement
    16. Getting a ResultSet from a Stored Procedure
      1. MySQL Database
      2. Adaptive Server Anywhere Database
      3. Oracle Database
      4. SQL Server Database
      5. DB2 Database
      6. Java DB Database
    17. ResultSetMetaData
    18. Using RowSets
    19. Working with a Large Object (LOB)
      1. Retrieving LOB Data
      2. Creating a LOB Data
    20. Batch Updates
    21. Savepoints in a Transaction
    22. Using a DataSource
    23. Retrieving SQL Warnings
    24. Enabling JDBC Trace
    25. Summary
  18. Chapter 7: Java Remote Method Invocation
    1. What Is Java Remote Method Invocation?
    2. The RMI Architecture
    3. Developing an RMI Application
      1. Writing the Remote Interface
      2. Implementing the Remote Interface
      3. Writing the RMI Server Program
      4. Writing the RMI Client Program
    4. Separating the Server and Client Code
    5. Generating Stub and Skeleton
    6. Running the RMI Application
      1. Running the RMI Registry
      2. Running the RMI Server
      3. Running an RMI Client Program
    7. Troubleshooting an RMI Application
      1. java.rmi.StubNotFoundException
      2. java.rmi.server.ExportException
      3. java.security.AccessControlException
      4. java.lang.ClassNotFoundException
    8. Debugging an RMI Application
    9. Dynamic Class Downloading
    10. Garbage Collection of Remote Objects
    11. Summary
  19. Chapter 8: Java Native Interface
    1. What Is the Java Native Interface?
    2. System Requirements
    3. Getting Started with the JNI
      1. Writing the Java Program
      2. Compiling the Java Program
      3. Creating the C/C++ Header File
      4. Writing the C/C++ Program
      5. Creating a Shared Library
      6. Running the Java Program
    4. Native Function Naming Rules
    5. Data Type Mapping
    6. Using JNI Functions in C/C++
    7. Working with Strings
    8. Working with Arrays
    9. Accessing Java Objects in Native Code
      1. Getting a Class Reference
      2. Accessing Fields and Methods of a Java Object/Class
      3. Creating Java Objects
    10. Exception Handling
      1. Handle the Exception in Native Code
      2. Handling the Exception in Java Code
      3. Throwing a New Exception from Native Code
    11. Creating an Instance of the JVM
    12. Synchronization in Native Code
    13. Summary
  20. Chapter 9: Introduction to JavaFX
    1. What Is JavaFX?
    2. The History of JavaFX
    3. System Requirements
    4. The JavaFX Runtime Library
    5. JavaFX Source Code
    6. Your First JavaFX Application
      1. Creating the HelloJavaFX Class
      2. Overriding the start() Method
      3. Showing the Stage
      4. Launching the Application
      5. Adding the main() Method
      6. Adding a Scene to the Stage
    7. Improving the HelloFX Application
    8. The Life Cycle of a JavaFX Application
    9. Terminating a JavaFX Application
    10. What Are Properties and Bindings?
    11. Properties and Bindings in JavaFX
      1. Using Properties in JavaFX Beans
      2. Handling Property Invalidation Events
      3. Handling Property Change Events
      4. Property Bindings in JavaFX
    12. Observable Collections
    13. Event Handling
      1. Event Processing Mechanism
      2. Creating Event Filters and Handlers
      3. Registering Event Filters and Handlers
    14. Layout Panes
    15. Controls
    16. Using 2D Shapes
    17. Drawing on a Canvas
    18. Applying Effects
    19. Applying Transformations
    20. Animation
      1. Using the Timeline Animation
    21. FXML
    22. Printing
    23. Summary
  21. Chapter 10: Scripting in Java
    1. What Is Scripting in Java?
    2. Executing Your First Script
    3. Using Other Scripting Languages
    4. Exploring the javax.script Package
      1. The ScriptEngine and ScriptEngineFactory Interfaces
      2. The AbstractScriptEngine Class
      3. The ScriptEngineManager Class
      4. The Compilable Interface and the CompiledScript Class
      5. The Invocable Interface
      6. The Bindings Interface and the SimpleBindings Class
      7. The ScriptContext Interface and the SimpleScriptContext Class
      8. The ScriptException Class
      9. Discovering and Instantiating ScriptEngines
    5. Executing Scripts
    6. Passing Parameters
      1. Passing Parameters from Java Code to Scripts
      2. Passing Parameters from Scripts to Java Code
    7. Advanced Parameter Passing Techniques
      1. Bindings
      2. Scope
      3. Defining the Script Context
      4. Putting Them Together
    8. Using a Custom ScriptContext
    9. Return Value of the eval() Method
    10. Reserved Keys for Engine Scope Bindings
    11. Changing the Default ScriptContext
    12. Sending Scripts Output to a File
    13. Invoking Procedures in Scripts
    14. Implementing Java Interfaces in Scripts
    15. Using Compiled Scripts
    16. Using Java in Scripting Languages
      1. Declaring Variables
      2. Importing Java Classes
      3. Creating and Using Java Objects
      4. Using Overloaded Java Methods
      5. Using Java Arrays
      6. Extending Java Classes Implementing Interfaces
      7. Using Lambda Expressions
    17. Implementing a Script Engine
      1. The Expression Class
      2. The JKScriptEngine Class
      3. The JKScriptEngineFactory Class
      4. Preparing for Deployment
      5. Packaging the JKScript Files
      6. Using the JKScript Script Engine
    18. The jrunscript Command-line Shell
      1. The Syntax
      2. Execution Modes of the Shell
      3. Listing Available Script Engines
      4. Adding a Script Engine to the Shell
      5. Using Other Script Engines
      6. Passing Arguments to Scripts
    19. The jjs Command-Line Tool
    20. JavaFX in Nashorn
    21. Summary
  22. Index