Category: Basic Java

Jan 02

DropBall.java Uses a while loop to determine how long it takes a ball to fall from the top of the Washington Monument to the ground

DropBall.java Uses a while loop to determine how long it takes a ball to fall from the top of the Washington Monument to the ground ************************************************************ /** Simulating dropping a ball from the top of the Washington * Monument. The program outputs the height of the ball each * second until the ball hits the …

Continue reading

Jan 02

Basic Hello World application

******************* HelloWorld.java Basic Hello World application. ******************* */ public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world."); } } /* Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017

Jan 02

Application that reports all command-line arguments

****************** ShowArgs.java Application that reports all command-line arguments. ****************** */ public class ShowArgs { public static void main(String[] args) { for(int i=0; i

Jan 02

HelloWWW.java Basic Hello World (Wide Web) Applet

********************* import java.applet.Applet; import java.awt.*; ********************* public class HelloWWW extends Applet { private int fontSize = 40; public void init() { setBackground(Color.black); setForeground(Color.white); setFont(new Font("SansSerif", Font.BOLD, fontSize)); } public void paint(Graphics g) { g.drawString("Hello, World Wide Web.", 5, fontSize+5); } } <

Jan 02

StringTest.java Demonstrates various methods of the String class.

NULL

Jan 02

DropBall.java Uses a while loop to determine how long it takes a ball to fall from the top of the Washington Monument to the ground.

NULL

Jan 02

Exec.java Provides static methods for running external processes from applications.

NULL

Jan 02

ExecTest.java illustrates use of the Exec class.

NULL

Jan 02

Factorial.java Computes an exact factorial, n!, using a BigInteger

NULL

Jan 02

URLTest.java Demonstrates try/catch blocks.

NULL

Jan 02

Illustrates the use of arrays

NULL

Jan 02

Tests the class type of an object using the isInstance method (preferred over instanceof operator).

NULL

Jan 02

TreeTest.java Builds a binary tree and prints the contents of the nodes. Uses the following classes:

NULL

Jan 02

ModificationTest.java Demonstrates changing fields of an object. Inherits from ReferenceTest.java.

NULL

Jan 02

NegativeLengthException.java Illustrates defining and throwing your own exceptions.

NULL

Jan 02

NumFormat.java Formats real numbers with DecimalFormat.

NULL

Skip to toolbar