Java
Programming Examples and Related Topics
Last revision: June 15, 2017
Comments and corrections should
be sent to Dr. T. Andrew Yang at yang@uhcl.edu.
3.
Object-Oriented Programming |
||
4.
Loops |
6.
Arrays |
|
7.
ArrayList |
8.
Packages |
9.
Enum |
10.
Exceptions |
11.
Applets |
|
12.
LinkedList |
13.
Stacks |
14.
Queues |
15.
Recursion (versus Iteration) |
16.
Trees |
17.
Sorting |
18.
Hashing |
|
|
19.
Java Tutorials |
|
|
1.
Proper indentation is important
> Top
2. Data types
2.1. Some important stuff about String
(references)
2.2. StringTest2.java
2.3. A sample program about Integer: IntegerTest.htm
> Top
3. Object-Oriented
Programming
3.1.
GradeBookExercise
//based on Deitel & Deitel, Java: How to
Programming, 9th edition.
3.2.
methodsExercise
//demonstration of method calls
3.3.
instanceVariablesExercise // demonstration
of objects as instance variables of another object
3.4.
AccessModifiersAndPackages.htm // test
access modifiers of instance variables and classes of the same package
3.5.
InheritanceAndPolymorphism
// a simple application that illustrates how polymorphism works
3.6.
AbstractClassDemo
// a simple application that illustrates how abstract classes works
3.7.
AbstractClassDemo2 // a
simple application that illustrates how an abstract class can be used as a generic
type of parameters
3.8.
InterfaceDemo.htm
//demonstration of interface
3.9.
Q&A: Abstract classes and
getInstance( )
> Top
4.1.
The
Oscillator application
//demonstration of nested loops
> Top
5. Files
and Streams
5.1.
FileReaderTest //
Demonstration of reading input from a data file using FileReader class
5.2.
FileInputStreamExample // Demonstration of
reading input from a data file using FileInputStream class // source: http://www.higherpass.com/java/Tutorials/Basic-File-Manipulation-With-Java/
5.3.
Scanning a data file using the Scanner class
5.4.
Reading a data file into an array of bytes and
printing words by words on console output //based on FileReaderTest
5.5.
ObjectInputOutputDemo.java
// demo of saving some objects into a file using ObjectOutputStream and retrieving
them bask using ObjectInputStream
5.6.
FileDemonstration.java
//Fig. 17.3: FileDemonstration.java from Deitel & Deitel, Java How to Program,
9e.
// File
class used to obtain file and directory information.
5.7.
CreateTextFileTest
//Fig. 17.5 每 17.7: from Deitel & Deitel, Java How to Program, 9e.
//
This application demonstrates writing lines of
attributes into a text file.
5.8.
ReadTextFileTest
//Fig. 17.9 每 17.10: from Deitel & Deitel, Java How to Program, 9e.
//
This application demonstrates reading lines of
attributes from a text file.
//
Note: Run CreateTextFileTest first to create the data file for
this application.
5.9.
MenuOptionDemo
// Fig. 17.11 每 17.13: from Deitel & Deitel, Java How to Program, 9e.
5.10. RandomAccessFileDemo
//Demo of using RandomAccessFile
class to create a file for both read and write operations
5.11. AccountRecordSerializableDemo //Fig.
17.15 每 17.17: from Deitel & Deitel, Java How to Program, 9e.
//
This application demonstrates writing objects of AccountRecordSerializable
into a file.
5.12.
ReadSequentialFileTest //Fig. 17.18 每 17.19:
from Deitel & Deitel, Java How to Program, 9e.
//
This application demonstrates reading objects of AccountRecordSerializableDemo
from a file back into the application.
//
Note: Run AccountRecordSerializableDemo first to create the data
file for this application.
> Top
6.1.
Array initialization and OOP
6.2.
ar1.equals(ar2) vs Arrays.equals(ar1,ar2): array comparisons
6.3.
RandomNumbers.htm // from Weiss, "Data
Structures & Problem Solving Using Java" (4th edition)
6.4.
RandomNumbers2.htm //revised version to show
sort( ) and binarySearch( ) methods
6.5.
Reading a data file into an array of bytes and printing
words by words on console output //based on FileReaderTest
6.6.
Arrays
of objects: Person.htm // source:
http://onjava.com/pub/a/onjava/2003/03/12/java_comp.html?page=1
// This application demonstrates how to
implement the compareTo( ) method to compare objects
in an array.
6.7.
Scanner,
array of Student: StudentScannerLoop.htm
>
Top
7. ArrayList
7.1.
ArrayListTest.htm: show how to sort an ArrayList using Collections.sort(
)
7.2.
ArrayListExample.java: a demo
of ArrayList with detailed explanations
//from
http://www.javadeveloper.co.in/java-example/java-arraylist-example.htm
> Top
8. Packages
8.1. JavaPackages.htm
8.2. AccessModifiersAndPackages.htm //
test access modifiers of instance variables and classes of the same package
> Top
9. Enum
9.1. EnumTest.htm
//Fig. 8.10 and 8.11: from Deitel & Deitel, Java How to Program,
9e.
>
Top
10. Exceptions
10.1.
Exceptions
and Stack Unwinding (using getStackTrace( )
and the StackTraceElement
class)
// Fig. 11.5: from Deitel &
Deitel, Java How to Program, 9e.
10.2.
ExceptionTest.htm
//Demonstrations of Java exceptions +
user-defined exceptions (rough)
> Top
11. Applets
11.1. AppletHelloWorld
//The HelloWorld applet and html files
11.2. TicTacToeDemo
//From the JDK demo applets folder
> Top
12.1. LinkedListExample1.htm
(simple LinkedList of int): // from http://www.roseindia.net/java/jdk6/LinkedListExample.shtml
12.2. LinkedListExample3.htm
(LinkedList of int and String): // revised from http://www.idevelopment.info/data/Programming/java/collections/LinkedListExample.java
12.3. ListNode.java
//a simple demo of linked list creation and node removal (with limitations);
see ListNode2.java below for the complete removal
12.4. ListNode2.java:
// Creation and testing of a generic linked list
> Top
13. Stacks
13.1. A very simple program using Stack:
StackDemo.htm (from http://www.javacoffeebreak.com/faq/faq0037.html)
13.2. StackPerson.htm
(revised from StackDemo)
13.3. ArrayStackDemo
(a generic Stack implemented as a dynamic array)
> Top
14. Queues
14.1. Implemented as a dynamic array:
ArrayQueueTest.htm
14.2. Implemented as a linked list: ListQueueTest.htm
> Top
15. Recursion
(and Iteration)
15.1. A simple
recursive function (with exercises)
15.2. Another
recursive function (with exercises)
> Top
16.1. BinaryTreeDemo
(from http://users.cis.fiu.edu/~weiss/dsj4/code/)
> Top
17.1. SortDemo
(from http://users.cis.fiu.edu/~weiss/dsj4/code/)
17.2. QuickSortDemo
> Top
18.1. HashingDemo
(demo of the separate chaining
hashing technique)
> Top
19.1. http://download.oracle.com/javase/tutorial/
19.2. http://www.oracle.com/technetwork/java/basicjava1-135508.html
(part 1)
19.3. http://www.oracle.com/technetwork/java/basicjava2-138746.html
(part 2)
19.4. http://www.cafeaulait.org/javatutorial.html
19.5. http://www.javabeginner.com/
19.6. http://www.tutorialspoint.com/java/index.htm
19.7. http://home.cogeco.ca/~ve3ll/jatutor0.htm
19.8. http://www.java2s.com/Tutorial/Java/CatalogJava.htm
19.9.
> Top