Java™ Programming Applications
ISBN 978-1-4652-8992-6
First Edition
Michael Robinson
Florida International University
Book Available at:
Kendall Hunt Publishing
Barnes and Nobles FIU Bookstore
The purpose of this book is to teach you computer programming concepts using the
Java Programming Language
. Previous programming knowledge is not required.
Every topic in each chapter contains at least one fully documented program that implements the topic being taugh.
Every program presented in this book is posted at
Source Code
so that you can download them, compile them and run them.
We recommend that you modify each program so that you can learn more, by modifying each program.
To make this work better, please email me your recommendations to:
michael.robinson@cs.fiu.edu or dmsdata@bellsouth.net
Thank you and Happy Programming!!
Michael Robinson
Contents
Preface
Purpose/Goals
The World's First Computer Programmer
Our Logo’s Meaning
Plan Your Work then Work Your Plan
Acknowledgments
Your Feedback is Needed!
Further Reading
Colophon
Chapter One: The Basics
What is Java?
What is an Operating System?
What is a Computer Program Language?
What do We Need?
A Computer
The Java JDK
Editors
Graphical User Interface (GUI)
IDE Programming Editors
NetBeans
Using NetBeans
Eclipse
Using Eclipse
Text Editors
Notepad in Linux
Gedit in Linux
Nano in Linux
Terminal Mode/Command Line
Creating Java programs
What is Compiling in Java?
PseudoCode
PseudoCode Example
Summary
Key Terms
Exercises
References
Chapter Two: Getting Started
Let's Start Programming
Documenting a Program
Javadoc Comments
What are Imports?
What is a Class?
Creating a Class
What is a Method?
Creating a Method
Indentation
Print Commands
System.out.print
System.out.println
System.out.printf
Summary
Key Terms
Exercises
References
Chapter Three: Basic Tools
Numerical Systems
Decimal Numerical System
Binary Numerical System
Why Binary?
8 Bits Byte Samples
Hexadecimal Numerical System
ASCII Codes Table
Unicode Standard
Data Types
Primitive Data Types
byte
char
int
short
long
float
double
boolean
What Can We Do with Primitives?
Problems Choosing the Wrong Data Types
Creating a Variable and Assigning a Value to it
Numerical Operators
Other Operators
Operators > and <
Operators >= and <=
Operators =, ==, !=
Operators &&
Operators ||
Operator %
Math Using Primitives
Wrapper Data Types
String Class Data Types
First String Program
Summary
Key Terms
Exercises
References
Chapter Four: Building a House
Wrapper Data Types
Calling Methods
Methods That Do Not Pass Any Data
Methods That Pass Data
Methods That Return Data
Pause Program
Variables
Global Variables
Private - Final Variables
Local Variables
Reading The Keyboard Using Scanner Class
Summary
Key Terms
Exercises
References
Chapter Five: if commands
if command
Plain if
Other Plain if Example
if_else
if else if
nested if
ternary If
Summary
Key Terms
Exercises
References
Chapter Six: Loops
Loops
for Loops
while Loop
Boolean Conditions in while Loops
Endless while Loop
do while Loops
Enhanced for Loops (Summary)
switch
Limitations of the switch Command
switch Command Using int as Input
switch Command Using char as Input
Summary
Key Terms
Exercises
References
Chapter Seven: Data Structures - Arrays
Data Structures Arrays One Dimension Array
Declaring/Creating One Dimension Array
Allocating Space to Declared Arrays
Declare and Allocate at the Same Time
Create, Allocate and Load Data into Arrays
Load Data to a Declared Array
Print all Values Inside This Array
Multi Dimensional Arrays
Two Dimension Arrays
Two Dimensional int Arrays
Two Dimensional String Arrays (Using Array's Length)
Three Multidimensional Arrays
Parallel Arrays
Enhanced for Loops
String Tokenizer
Summary
Key Terms
Exercises
References
Chapter Eight: Data Structures - ArrayList
ArrayList
Iterator
Using Iterator in an ArrayList
Copying Arrays into an ArrayList Modify and Back
Object Data Types
Summary
Key Terms
Exercises
References
Chapter Nine: Data Structures - Files
Files
What is a File
What is a Record
Catching Errors Exceptions in Data Files
Text Files
Text Files Using FileWriter, PrintWriter, FileReader and BufferedReader
Text Files Using the File Class
Exceptions Handling
Text Files Using the Formatter Class
Text Files Using the Scanner Class
Large Files. Writing and Reading
Printing Numbers Using Decimal Format
Binary Files
Summary
Key Terms
Exercises
References
Chapter Ten: External Classes, Methods, This, Constructors
External Classes
Final Variables
toString
What is this?
What is a Constructor?
Simple Constructors
What is Variable-Length Argument List in Methods?
Object Data Types
What is the Meaning of main( String arg[] )?
Summary
Key Terms
Exercises
References
Chapter Eleven: GUI Simple Applications
What is GUI (Graphical User Interface)?
What are Dialog Boxes?
Message Dialog Boxes
Input Dialog Boxes
What is a Frame?
Creating a Frame
Creating a Small Frame
Creating a Full Size Frame
Summary
Key Terms
Exercises
References
Chapter Twelve: Sorting and Recursion
What is Sorting?
Swap - Placing Data in Order
Bubble Sort
Recursion
Summary
Key Terms
Exercises
References
Chapter Thirteen: Inheritance and Polymorphism
What is Inheritance?
Polymorphism
Final Methods
Final Classes
Protected Classes Methods and Variables
Summary
Key Terms
Exercises
References
Chapter Fourteen: Interfaces and Abstraction
What is an Interface?
Data Abstraction
Data Abstraction vs Interfaces
Summary
Key Terms
Exercises
References
Chapter Fifteen: Data Structures Implementations
LinkedList
Overloading
Stacks
Queue
Summary
Key Terms
Exercises
References
Chapter Sixteen: Complex Programming
Abstract Classes
Caller Methods
Classes Inside Classes
Extends/Inhereting
Interfaces
Summary
Key Terms
Exercises
References
Chapter Seventeen: Miscellaneous
Generic Methods
Introduction to Java Collection Interface
Overriding equals and toString Methods
How to Reduce Typing
ASCII Codes Program
Javadoc
Summary
Key Terms
Exercises
References
Glossary
Index