Learn basic language constructs to start writing applications with the Java programming language.
Basics
- Hello World This sample is from the Java Tutorial.
- Class Bicycle This is an example of a class from the Java Tutorial.
- Inheritance Example This examples demonstrates how to use inheritance, taken from the Java Tutorial.
Arrays
- ArrayDemo.java creates an array, puts some values in it, and displays the values. For supporting information see The Java Tutorial: Object Basics and Simple Data Objects.
- ArrayCopyDemo.java uses the arrayCopy method to copy some elements from one array to another. For supporting information see The Java Tutorial: Object Basics and Simple Data Objects.
- ArrayofArraysDemo.java creates an array and uses an initializer to populate it with four subarrays. For supporting information see The Java Tutorial: Object Basics and Simple Data Objects.
- ArrayofArraysDemo2.java creates an array of arrays by explicitly writing code to create each subarray. For supporting information see The Java Tutorial: Object Basics and Simple Data Objects.
- ArrayofStringsDemo.java uses an array initializer to create an array containing three string objects and puts the strings in all lowercase letters. For supporting information see The Java Tutorial: Object Basics and Simple Data Objects.
Control Flow
- if-then-else Statement This if-then-else statement is taken from the Java Tutorial.
- BreakDemo.java contains a for loop that searches for a particular value within an array. For supporting information see The Java Tutorial: Nuts and Bolts.
*BreakWithLabelDemo.java searches for a value in a two-dimensional array. For supporting information see The Java Tutorial: Nuts and Bolts.
- ContinueDemo.java steps through a string buffer and checks each letter. For supporting information see The Java Tutorial: Nuts and Bolts.
- ContinueWithLabelDemo.java uses nested loops to search for a substring within another string. For supporting information see The Java Tutorial: Nuts and Bolts.
- DoWhileDemo.java shows how to use a do-while statement to continually execute a block of code while a condition remains true. For supporting information see The Java Tutorial: Nuts and Bolts.
- ForDemo.java uses a for statement to iterate over the elements of an array and print them. For supporting information see The Java Tutorial: Nuts and Bolts.
- IfElseDemo.java uses an if-else statement to assign a grade based on the value of a test score. For supporting information see The Java Tutorial: Nuts and Bolts.
- SwitchDemo.java uses the switch statement to conditionally perform statements based on an integer expression. For supporting information see The Java Tutorial: Nuts and Bolts.
- SwitchDemo2.java illustrates how it can be useful to make a case statement terminate the flow of control. For supporting information see The Java Tutorial: Nuts and Bolts.
- WhileDemo.java shows how to use a while statement to continually execute a block of code while a condition remains true. For supporting information see The Java Tutorial: Nuts and Bolts.
Date & Time
- June.java demonstrates the limits of scope by finding out which month of the year is June. For supporting information see New to Java Programming Supplement, Feb 2002.
- TimeTest.java shows you how to create a time stamp object that returns the current time. For supporting information see New to Java Programming Supplement, November 2001.
Operators
- ArithmeticDemo.java shows you how to perform mathematical operations with numbers. For supporting information see The Java Tutorial: Nuts and Bolts.
Packages
Collections
Variables
- Cast.java uses the instanceOf method to determine the type of objects in a list and shows how to cast the objects to their correct type before accessing the data. For supporting information see New to Java Programming Supplement, March 2002.
Resources
- Effective Java Code Samples provides expert tips for using the Java programming language effectively. For supporting information, see Effective Java Programming Language guide.
- Essentials of the Java Programming Language Code Samples, Part 1 give you a basic introduction to some of the more commonly used APIs such as applets, applications, servlets, file I/O, security, buildings GUIs with Swing, database access, and remote method invocation. For supporting information, see Essentials of the Java Programming Language: A Hands-On Guide, Part 1.
- Essentials of the Java Programming Language Code Samples, Part 2 give you a basic introduction to some of the more commonly used APIs such as socket communications, more building GUIs with Swing, cryptography, serialization, collections, internationalization, packages and JAr files, and object-oriented programming. For supporting information, see Essentials of the Java Programming Language: A Hands-On Guide, Part 2.