Category: FromSitesTree.com

UrlTest.java Demonstrates the ease in which the various components of an URL can be determined (host, port, protocol, etc.). #Programming Code Examples #Java/J2EE/J2ME #Network Programming

UrlTest.java Demonstrates the ease in which the various components of an URL can be determined (host, port, protocol, etc.). import java.net.*; /** Read a URL from the command line, then print * the various components. * * Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * . * © 2001 …

Continue reading

NetworkClientTest.java Makes a simple connection to the host and port specified on the command line. Uses the following classes: #Programming Code Examples #Java/J2EE/J2ME #Network Programming

NetworkClientTest.java Makes a simple connection to the host and port specified on the command line. Uses the following classes: /** Make simple connection to host and port specified. * * Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * . * © 2001 Marty Hall and Larry Brown; * may …

Continue reading

TokTest.java Illustrates parsing a string with a StringTokenizer. #Programming Code Examples #Java/J2EE/J2ME #Network Programming

TokTest.java Illustrates parsing a string with a StringTokenizer. import java.util.StringTokenizer; /** Prints the tokens resulting from treating the first * command-line argument as the string to be tokenized * and the second as the delimiter set. * * Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * . * © …

Continue reading

SplitTest.java Illustrates parsing a string with a String.split #Programming Code Examples #Java/J2EE/J2ME #Network Programming

SplitTest.java Illustrates parsing a string with a String.split /** Prints the tokens resulting from treating the first * command-line argument as the string to be tokenized * and the second as the delimiter set. Uses * String.split instead of StringTokenizer. */ public class SplitTest { public static void main(String[] args) { if (args.length == 2) …

Continue reading

Example demonstrating the use of packages #Programming Code Examples #Java/J2EE/J2ME #Object Oriented Programming

&&&&&&&&&&&&&&&&&&& Example demonstrating the use of packages. * Class1.java defined in package1. * Class2.java defined in package2. * Class3.java defined in package2.package3. * Class1.java defined in package4. * PackageExample.java Driver for package example &&&&&&&&&&&&&&&&&&&&& ~~~~~~~~~~~~~~~~~~~~~ Class1.java defined in package1. ~~~~~~~~~~~~~~~~~~~~~ package package1; ***************** public class Class1 { public static void printInfo() { System.out.println("This is Class1 …

Continue reading

Statics.java Demonstrates static and non-static methods. #Programming Code Examples #Java/J2EE/J2ME #Object Oriented Programming

*/ public class Statics { public static void main(String[] args) { staticMethod(); Statics s1 = new Statics(); s1.regularMethod(); } public static void staticMethod() { System.out.println("This is a static method."); } public void regularMethod() { System.out.println("This is a regular method."); } } Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10396 Categories:Programming …

Continue reading

A Ship class illustrating object-oriented programming concepts #Programming Code Examples #Java/J2EE/J2ME #Object Oriented Programming

************************ Ship.java A Ship class illustrating object-oriented programming concepts. Incorporates Javadoc comments. See ShipTest.java for a test. ************************ /** Ship example to demonstrate OOP in Java. * * @author * Larry Brown * @version 2.0 */ public class Ship { // Instance variables private double x=0.0, y=0.0, speed=1.0, direction=0.0; private String name; // Constructors /** …

Continue reading

Speedboat.java Illustrates inheritance from Ship class #Programming Code Examples #Java/J2EE/J2ME #Object Oriented Programming

***************************** Speedboat.java Illustrates inheritance from Ship class. See SpeedboatTest.java for a test. ***************************** /** A fast Ship. Red and going 20 knots by default. * *********************** public class Speedboat extends Ship { private String color = "red"; /** Builds a red Speedboat going N at 20 knots. */ public Speedboat(String name) { super(name); setSpeed(20); } …

Continue reading

Code examples for interfaces #Programming Code Examples #Java/J2EE/J2ME #Object Oriented Programming

**************************** Code examples for interfaces: * Class1.java implements Interface1.java * Abstract Class2.java implements Interface1.java and Interface2.java * Class3.java extends abstract class Class2.java * Interface3.java extends Interface1.java and Interface2.java *************************** ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Class1.java ~~~~~~~~~~~~~~~~~~~~~~~~~~~ // This class is not abstract, so it must provide // implementations of method1 and method2. public class Class1 extends SomeClass implements Interface1 …

Continue reading

Example illustrating inheritance and abstract classes #Programming Code Examples #Java/J2EE/J2ME #Object Oriented Programming

*********************************** # Example illustrating inheritance and abstract classes. * Shape.java The parent class (abstract) for all closed, open, curved, and straight-edged shapes. * Curve.java An (abstract) curved Shape (open or closed). * StraightEdgedShape.java A Shape with straight edges (open or closed). * Measurable.java Interface defining classes with measurable areas. * Circle.java A circle that extends …

Continue reading