Book Description

About the Author

Table of Contents

Source Code

Send Comments

Author's Homepage
 

Object-Oriented Software Development Using Java

Xiaoping Jia, Ph.D

Chapter 3: Elements of Java

Objectives
In this chapter, we discuss the basic elements of Java, including operators and expressions, data types, garbage collection, control structures, class declaration, parameter passing, packages and exceptions. Some of the more commonly used classes in the Java Class Library are also discussed. A number simple programs are presented to demonstrate string manipulation and simple input and output. A simple animation applet is also presented. 


Contents
3.1 Lexical Elements
      3.1.1 Character Set
      3.1.2 Identifiers
      3.1.3 Primitive Types and Literals
      3.1.4 Operators and Expressions
3.2 Variables and Types
      3.2.1 Variable Declarations
      3.2.2 Type Compatibility and Conversion
      3.2.3 Reference Types
      3.2.4 Arrays
3.3 Statements
      3.3.1 Statement Labels
      3.3.2 Statement Blocks
      3.3.3 Simple Statements
      3.3.4 Compound Statements
      3.3.5 Multi-Level Breaking
3.4 Class Declarations
      3.4.1 Class Syntax
      3.4.2 Creating and Initializing Objects
      3.4.3 Accessing Members
      3.4.4 Method Invocation and Parameter Passing
      3.4.5 Static Fields and Methods
      3.4.6 Object Reference this
      3.4.7 Interfaces and Abstract Classes
      3.4.8 Strings
      3.4.9 Wrapper Classes
3.5 Packages
3.6 Exceptions
3.7 A Simple Animation Applet


Source Code

  • 3-1: Sum an one-dimensional array 
  • 3-2: Sort an one-dimensional array 
  • 3-3: Print command line arguments 
  • 3-4: Copy from stdin to stdout 
  • 3-5: Copy text files 
  • 3-6: Break colon-delimited records
  • 3-7: Break text into words 
  • 3-8: Find minimal value
  • 3-9: Find max-min value
  • 3-10: Digital Clock applet 


  • Other Chapters
    Example 3.1: Sum An One-Dimensional Array 
    This program segment calculates the sum of the values in a one-dimensional integer array: 

    Example 3.2: Sort An One-Dimensional Array 
    This program segment sorts the array from example 3.1 in ascending order and prints the sorted array. The bubble sort algorithm is used. 

    Example 3.3: Print Command Line Arguments
    This Java program prints trailing command line arguments! 

    Example 3.4: Copy From Stdin To Stdout
    This Java program prints copies standard input to standard output, line by line. 

    Example 3.5: Copy Text Files
    This Java program copies the contents of one text file to another text file, line by line. 

    Example 3.6: Break Colon-Delimited Records
    This Java program reads colon-delimited records from standard input and breaks each record into fields. 

    Example 3.7: Break Text Into Words
    This Java program reads text from standard input, and uses StringTokenizer to break the text into words. The words are written to Standard output, line by line. 

    Example 3.8: Find Minimal Value
    This program segment finds the minimum value of an array. 

    Example 3.9: Find the Max-Min Value 
    This program segment finds the max-min value of a two-dimensional array; i.e., the maximum of the minimums of each column:


                  max min mat[i][j
                  0<=j<=m 0<=i<=n 

    where m and n are the number of rows and columns, respectively. 


    Example 3.10: Digital Clock Applet
    This applet displays the current time in hours, minutes, and seconds in the following format: 


                  HH:MM:SS 


    Book Description - About the Author - Table of Contents
    Source Code - Send Comments - Author's Homepage

    Webmaster: rpasenko@shrike.depaul.edu