You are previewing Java™ in 24 Hours, Sams Teach Yourself (Covering Java 8), Seventh Edition.
O'Reilly logo
Java™ in 24 Hours, Sams Teach Yourself (Covering Java 8), Seventh Edition

Book Description

Sams Teach Yourself Java in 24 Hours, Seventh Edition

Covers Java 8 and Android Development

In just 24 lessons of one hour or less, you can learn the fundamentals of Java programming.

In this book's straightforward, step-by-step approach, each lesson builds on everything that's come before, helping readers learn Java's core features and techniques from the ground up.

Friendly, accessible, and conversational, this book offers a practical grounding in the language, without ever becoming overwhelming or intimidating. Full-color figures and clear instructions visually show you how to program with Java.

Popular author Rogers Cadenhead helps you master the skills and technology you need to create desktop and web programs, web services, and even an Android app in Java.

Learn how to…

  • Set up your Java programming environment

  • Write your first working program in just minutes

  • Control program decisions and behavior

  • Store and work with information

  • Build straightforward user interfaces

  • Create interactive web programs

  • Use threading to build more responsive programs

  • Read and write files and XML data

  • Master best practices for object-oriented programming

  • Create flexible, interoperable web services with JAX-WS

  • Use Java to create an Android app

  • Expand your skills with closures, the powerful new capability introduced in Java 8

  • Contents at a Glance

    PART I: Getting Started

    1 Becoming a Programmer

    2 Writing Your First Program

    3 Vacationing in Java

    4 Understanding How Java Programs Work

    PART II: Learning the Basics of Programming

    5 Storing and Changing Information in a Program

    6 Using Strings to Communicate

    7 Using Conditional Tests to Make Decisions

    8 Repeating an Action with Loops

    PART III: Working with Information in New Ways

    9 Storing Information with Arrays

    10 Creating Your First Object

    11 Describing What Your Object Is Like

    12 Making the Most of Existing Objects

    PART IV: Programming a Graphical User Interface

    13 Building a Simple User Interface

    14 Laying Out a User Interface

    15 Responding to User Input

    16 Building a Complex User Interface

    PART V: Moving into Advanced Topics

    17 Storing Objects in Data Structures

    18 Handling Errors in a Program

    19 Creating a Threaded Program

    20 Using Inner Classes and Closures

    21 Reading and Writing Files

    22 Creating Web Services with JAX-WS

    23 Creating Java2D Graphics

    24 Writing Android Apps

    Appendixes

    A Using the NetBeans Integrated Development Environment

    B Where to Go from Here: Java Resources

    C This Book’s Website

    D Setting Up an Android Development Environment

    Table of Contents

    1. About This eBook
    2. Title Page
    3. Copyright Page
    4. Table of Contents
    5. About the Author
    6. Dedication
    7. Acknowledgments
    8. We Want to Hear from You!
    9. Reader Services
    10. Introduction
    11. Part I: Getting Started
      1. Hour 1. Becoming a Programmer
        1. Choosing a Language
        2. Telling the Computer What to Do
        3. How Programs Work
        4. When Programs Don’t Work
        5. Choosing a Java Programming Tool
        6. Installing a Java Development Tool
        7. Summary
        8. Workshop
      2. Hour 2. Writing Your First Program
        1. What You Need to Write Programs
        2. Creating the Saluton Program
        3. Beginning the Program
        4. Storing Information in a Variable
        5. Saving the Finished Product
        6. Compiling the Program into a Class File
        7. Fixing Errors
        8. Running a Java Program
        9. Summary
        10. Workshop
      3. Hour 3. Vacationing in Java
        1. First Stop: Oracle
        2. Going to School with Java
        3. Lunch in JavaWorld
        4. Watching the Skies at NASA
        5. Getting Down to Business
        6. Stopping by SourceForge for Directions
        7. Running Java on Your Phone
        8. Summary
        9. Workshop
      4. Hour 4. Understanding How Java Programs Work
        1. Creating an Application
        2. Sending Arguments to Applications
        3. The Java Class Library
        4. Summary
        5. Workshop
    12. Part II: Learning the Basics of Programming
      1. Hour 5. Storing and Changing Information in a Program
        1. Statements and Expressions
        2. Assigning Variable Types
        3. Naming Your Variables
        4. Storing Information in Variables
        5. All About Operators
        6. Using Expressions
        7. Summary
        8. Workshop
      2. Hour 6. Using Strings to Communicate
        1. Storing Text in Strings
        2. Displaying Strings in Programs
        3. Using Special Characters in Strings
        4. Pasting Strings Together
        5. Using Other Variables with Strings
        6. Advanced String Handling
        7. Presenting Credits
        8. Summary
        9. Workshop
      3. Hour 7. Using Conditional Tests to Make Decisions
        1. if Statements
        2. if-else Statements
        3. switch Statements
        4. The Ternary Operator
        5. Watching the Clock
        6. Summary
        7. Workshop
      4. Hour 8. Repeating an Action with Loops
        1. for Loops
        2. while Loops
        3. do-while Loops
        4. Exiting a Loop
        5. Naming a Loop
        6. Testing Your Computer Speed
        7. Summary
        8. Workshop
    13. Part III: Working with Information in New Ways
      1. Hour 9. Storing Information with Arrays
        1. Creating Arrays
        2. Using Arrays
        3. Multidimensional Arrays
        4. Sorting an Array
        5. Counting Characters in Strings
        6. Summary
        7. Workshop
      2. Hour 10. Creating Your First Object
        1. How Object-Oriented Programming Works
        2. Objects in Action
        3. What Objects Are
        4. Understanding Inheritance
        5. Building an Inheritance Hierarchy
        6. Converting Objects and Simple Variables
        7. Creating an Object
        8. Summary
        9. Workshop
      3. Hour 11. Describing What Your Object Is Like
        1. Creating Variables
        2. Creating Class Variables
        3. Creating Behavior with Methods
        4. Putting One Class Inside Another
        5. Using the this Keyword
        6. Using Class Methods and Variables
        7. Summary
        8. Workshop
      4. Hour 12. Making the Most of Existing Objects
        1. The Power of Inheritance
        2. Establishing Inheritance
        3. Working with Existing Objects
        4. Storing Objects of the Same Class in Array Lists
        5. Creating a Subclass
        6. Summary
        7. Workshop
    14. Part IV: Programming a Graphical User Interface
      1. Hour 13. Building a Simple User Interface
        1. Swing and the Abstract Windowing Toolkit
        2. Using Components
        3. Summary
        4. Workshop
      2. Hour 14. Laying Out a User Interface
        1. Using Layout Managers
        2. Laying Out an Application
        3. Summary
        4. Workshop
      3. Hour 15. Responding to User Input
        1. Getting Your Programs to Listen
        2. Setting Up Components to Be Heard
        3. Handling User Events
        4. Completing a Graphical Application
        5. Summary
        6. Workshop
      4. Hour 16. Building a Complex User Interface
        1. Sliders
        2. Change Listeners
        3. Using Image Icons and Toolbars
        4. Tables
        5. Summary
        6. Workshop
    15. Part V: Moving into Advanced Topics
      1. Hour 17. Storing Objects in Data Structures
        1. Array Lists
        2. Hash Maps
        3. Summary
        4. Workshop
      2. Hour 18. Handling Errors in a Program
        1. Exceptions
        2. Throwing Exceptions
        3. Throwing and Catching Exceptions
        4. Summary
        5. Workshop
      3. Hour 19. Creating a Threaded Program
        1. Threads
        2. Working with Threads
        3. The Constructor
        4. Catching Errors as You Set Up URLs
        5. Starting the Thread
        6. Handling Mouse Clicks
        7. Displaying Revolving Links
        8. Summary
        9. Workshop
      4. Hour 20. Using Inner Classes and Closures
        1. Inner Classes
        2. Closures
        3. Summary
        4. Workshop
    16. Part VI: Writing Internet Applications
      1. Hour 21. Reading and Writing Files
        1. Streams
        2. Writing Data to a Stream
        3. Reading and Writing Configuration Properties
        4. Summary
        5. Workshop
      2. Hour 22. Creating Web Services with JAX-WS
        1. Defining a Service Endpoint Interface
        2. Creating a Service Implementation Bean
        3. Publishing the Web Service
        4. Using Web Service Definition Language Files
        5. Creating a Web Service Client
        6. Summary
        7. Workshop
      3. Hour 23. Creating Java2D Graphics
        1. Using the Font Class
        2. Using the Color Class
        3. Creating Custom Colors
        4. Drawing Lines and Shapes
        5. Baking a Pie Graph
        6. Summary
        7. Workshop
      4. Hour 24. Writing Android Apps
        1. Introduction to Android
        2. Creating an Android App
        3. Running the App
        4. Designing a Real App
        5. Summary
        6. Workshop
    17. Appendixes
      1. Appendix A. Using the NetBeans Integrated Development Environment
        1. Installing NetBeans
        2. Creating a New Project
        3. Creating a New Java Class
        4. Running the Application
        5. Fixing Errors
      2. Appendix B. Where to Go from Here: Java Resources
        1. Other Books to Consider
        2. Oracle’s Official Java Site
        3. Other Java Websites
        4. Job Opportunities
      3. Appendix C. This Book’s Website
      4. Appendix D. Setting Up an Android Development Environment
        1. Getting Started
        2. Installing Eclipse
        3. Installing the Android Plug-in for Eclipse
        4. Setting Up Your Phone
    18. Index