Tag: code

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

import java.math.BigInteger; /** Computes an exact factorial, using a BigInteger.  *  *  Taken from Core Web Programming from  *  Prentice Hall and Sun Microsystems Press,  *  .  *  © 2001 Marty Hall and Larry Brown;  *  may be freely used or adapted.  */ public class Factorial {   public static void main(String[] args) {     …

Continue reading

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

import java.io.*; /** A class that eases the pain of running external processes  *  from applications. Lets you run a program three ways:  *        *          exec: Execute the command, returning      *         immediately even if the command is still running.      *         This would be appropriate for printing a file.      …

Continue reading

Controlling Image Loading

~~~~~~~~~~~~~~~~~~~ ImageBox.java A class that incorrectly tries to load an image and draw an outline around it. The problem is that the size of the image is requested before the image is completely loaded, thus, returning a width and height of -1. ~~~~~~~~~~~~~~~~~~~ import java.applet.Applet; import java.awt.*; /** A class that incorrectly tries to load …

Continue reading

HelloWWW2.java Illustrates the ability of an applet to read parameters contained in the HTML document

HelloWWW2.java Illustrates the ability of an applet to read parameters contained in the HTML document (PARAM element containing a NAME-VALUE pair). &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& import java.applet.Applet; import java.awt.*; ************************* public class HelloWWW2 extends Applet {   public void init() {     setFont(new Font(“SansSerif”, Font.BOLD, 30));     Color background = Color.gray;     Color foreground = Color.darkGray;     String …

Continue reading

An example Travel Site

quick-search.html Front end to travel site <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”> <!– Front end to travel servlet. Taken from Core Web Programming Java 2 Edition from Prentice Hall and Sun Microsystems Press, . May be freely used or adapted. –> <HTML> <HEAD>   <TITLE>Online Travel Quick Search</TITLE>   <LINK REL=STYLESHEET         HREF=”travel-styles.css”         …

Continue reading

GetElementsByName an example: Checkbox

<html>     <head>         <script type=”text/javascript”>             function getElements()               {               var x=document.getElementsByName(“myInput[]”);               alert(x.length);               alert(x[0].value);               alert(x[1].value);               alert(x[2].value);               }         </script> </head> <body>     <input …

Continue reading

IfExample.jsp Page that uses the custom nested tags

IfExample.jsp Page that uses the custom nested tags <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”> <!– Illustration of IfTag tag. Taken from Core Web Programming Java 2 Edition from Prentice Hall and Sun Microsystems Press, . May be freely used or adapted. –> <HTML> <HEAD> <TITLE>If Tag Example</TITLE> <LINK REL=STYLESHEET       HREF=”JSP-Styles.css”       TYPE=”text/css”> </HEAD> …

Continue reading

Driver template to create and start a Thread object.

** Taken from Core Web Programming from  *  Prentice Hall and Sun Microsystems Press,   *  © 2001 Marty Hall and Larry Brown;  *  may be freely used or adapted.  */ public class DriverClass extends SomeClass {   …   public void startAThread() {     // Create a Thread object.     ThreadClass thread = new …

Continue reading

Pointers

/* The following code example is taken from the book  * “The C++ Standard Library – A Tutorial and Reference”  * by Nicolai M. Josuttis, Addison-Wesley, 1999  *  * (C) Copyright Nicolai M. Josuttis 1999.  * Permission to copy, use, modify, sell and distribute this software  * is granted provided this copyright notice appears in …

Continue reading

Valarray Example

/* The following code example is taken from the book  * “The C++ Standard Library – A Tutorial and Reference”  * by Nicolai M. Josuttis, Addison-Wesley, 1999  *  * (C) Copyright Nicolai M. Josuttis 1999.  * Permission to copy, use, modify, sell and distribute this software  * is granted provided this copyright notice appears in …

Continue reading