<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Latest topics for the forum "How To Articles"]]></title>
		<link>http://forums.hotjoe.com/forums/show/27.page</link>
		<description><![CDATA[The newest discussed topics in the forum "How To Articles"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>University Assignment</title>
				<description><![CDATA[ Hello, basically i have a bit of a problem. Im a full time student in University at the moment<br /> and on thursday i am due to present my project for Object Orientated Programming in Java<br /> <br /> I know nothing......<br /> Any help! any help at all! would be greatly appreciated.<br /> I know im not going to pass, but just enough to get at least like 10%?<br /> <br /> here is the documents<br /> Thank you in advance<br /> <br /> <a class="snap_shots" href="http://joshdt001.webs.com/help/help1.docx" target="_blank" rel="nofollow">http://joshdt001.webs.com/help/help1.docx</a><br /> <a class="snap_shots" href="http://joshdt001.webs.com/help/Menu.java" target="_blank" rel="nofollow">http://joshdt001.webs.com/help/Menu.java</a><br /> <a class="snap_shots" href="http://joshdt001.webs.com/help/WHOLE.java" target="_blank" rel="nofollow">http://joshdt001.webs.com/help/WHOLE.java</a><br /> <br /> <br /> <br />  ]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/835/3039.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/835/3039.page</link>
				<pubDate><![CDATA[Tue, 14 Dec 2010 11:49:43]]> GMT</pubDate>
				<author><![CDATA[ JoshDT]]></author>
			</item>
			<item>
				<title>iPhone Programming Course via Online Video, Worksheets and Respective Academic Sessions</title>
				<description><![CDATA[ EDUmobile ORG has launched their online iPhone Programming Course via a simply structured online video, PDF, worksheet & 1-on-1 help modules.<br /> <br /> The cost for the whole iPhone module is US $200paid as onetime full installment, or you can pay back over three installments. BUT, for a very particular time, they are offering this package at a 25% discount. That is, you receive everything for $150, should you enter promo code EDU while registering for the course of study.<br /> <br /> Please click here -(link deleted - spam) to get to know more about iphone tutorial in detail.<br /> <br /> <br /> ]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/647/2437.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/647/2437.page</link>
				<pubDate><![CDATA[Tue, 24 Nov 2009 04:07:10]]> GMT</pubDate>
				<author><![CDATA[ AlexCore]]></author>
			</item>
			<item>
				<title>project  on chladni plates</title>
				<description><![CDATA[ Hello<br /> I am currently starting work on a java based version of a chladni vibraring plate project.Is there  anyone you know <br /> of who could help with the code. :? <br /> <br /> Thanking you my web address is <br /> <a class="snap_shots" href="mailto:markkelly895@gmail.com">markkelly895@gmail.com</a> :) ]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/611/2335.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/611/2335.page</link>
				<pubDate><![CDATA[Thu, 20 Aug 2009 06:59:14]]> GMT</pubDate>
				<author><![CDATA[ mark]]></author>
			</item>
			<item>
				<title>Server based image scaling</title>
				<description><![CDATA[ When creating a website with many images getting the images to be correctly sized can be a total pain.  You can use many tools to resize images but sometimes it is useful to have the server size the image.  Passing a full sized image and letting the browser resize it is a total waste of bandwidth (assuming you're [b]reducing[/b] the size).<br /> <br /> I researched a few ways of doing this and decided to create a servlet to do it for me.  The servlet code below implements this for you.  Note that it also acts indirectly as a file server that reads from a configured directory.  This can allow you to prevent hotlinking or require some other check to serve an image.<br /> <br /> [code]<br /> package com.xigole.util.images;<br /> <br /> import java.awt.Graphics2D;<br /> import java.awt.RenderingHints;<br /> import java.awt.image.BufferedImage;<br /> import java.io.File;<br /> import java.io.IOException;<br /> <br /> import javax.imageio.ImageIO;<br /> import javax.servlet.ServletConfig;<br /> import javax.servlet.ServletException;<br /> import javax.servlet.http.HttpServlet;<br /> import javax.servlet.http.HttpServletRequest;<br /> import javax.servlet.http.HttpServletResponse;<br /> <br /> import org.apache.commons.logging.Log;<br /> import org.apache.commons.logging.LogFactory;<br /> <br /> /**<br />  * The ImageResizerServlet is a simple servlet to, well, resize images.<br />  * It takes advantage of Java 1.5+ constructs to dynamically resize an image in<br />  * any format supported by Java.  The response is then converted to an jpeg<br />  * dynamically.<br />  *<br />  */<br /> public class ImageResizerServlet extends HttpServlet<br /> {<br />     /**<br />      * This member is required for serializable classes.<br />      */<br />     private static final long serialVersionUID = 1;<br />     <br />     /**<br />      * The name of the directory to use for images.  This can be overridden<br />      * in the servlet config.<br />      */<br />     private static String imageDir = "catalog_images";<br /> <br />     /**<br />      * The maximum age, in seconds, that a browser should cache any images generated.<br />      * This defaults to 1 hour and can be overridden in the servlet config.<br />      */<br />     private static String maxAge = "3600";<br /> <br />     /**<br />      * The logger used for debugging and error messages.<br />      */<br />     private static Log      log = LogFactory.getLog( ImageResizerServlet.class );<br />     <br />     <br />     /**<br />      * Reads any init-param items from the web.xml for this servlet.<br />      * <br />      * Currently supported parameters:<br />      * <ul><br />      * <li>imageDir - specifies the name of the directory in which to get images.</li><br />      * <li>maxAge - value to pass to the browser indicating the max time to cache the image.</li><br />      * </ul><br />      *   <br />      */<br />     public void init( ServletConfig config ) throws ServletException<br />     {<br />         super.init( config );<br />         <br />         String configImageDir = config.getInitParameter("imageDir");<br />         <br />         if( configImageDir != null )<br />             imageDir = configImageDir;<br />         <br />         log.debug( "using \"" + imageDir + "\" as the directory for images" );<br /> <br />         String configMaxAge = config.getInitParameter("maxAge");<br />         <br />         if( configMaxAge != null )<br />             maxAge = configMaxAge;<br />         <br />         log.debug( "using \"" + maxAge + "\" as the cache timeout value" );<br />     }<br /> <br />     /**<br />      * doGet does all the work.  It reads the request, reads the image, scales it,<br />      * and sends it back.<br />      * <br />      * Request parameters:<br />      *     image - the name of the image.  This is required.<br />      *     scale - the requested scale.  This is specified in percentage so 100 will<br />      *             retuls in no scaling.  This is an optional parameter and if it<br />      *             doesn't exist then the image will be sent back unchanged and at 100%.<br />      *<br />      */<br />     public final void doGet( HttpServletRequest request, HttpServletResponse response )<br />         throws ServletException, IOException<br />     {  <br />         for( java.util.Enumeration e = request.getHeaderNames(); e.hasMoreElements(); )<br />         {<br />             String  nextHeaderName = (String)e.nextElement();<br />             log.debug( "request header name: " + nextHeaderName + " - value: " + request.getHeader( nextHeaderName ) );<br />         }<br /> <br />         String image = request.getParameter( "image" );<br />         <br />         if( image == null )<br />         {<br />             response.sendError( HttpServletResponse.SC_BAD_REQUEST, "Missing image parameter" );<br />             return;<br />         }<br />         <br />         String scaleString = request.getParameter( "scale" );<br />         <br />         if( scaleString == null )<br />             scaleString = "100.0";<br /> <br />         try<br />         {<br />             String fileName = getServletContext().getRealPath( "/" ) +<br />                               File.separator +<br />                               imageDir +<br />                               File.separator +<br />                               image;<br /> <br />             log.debug( "attempting to serve image \"" + fileName + "\" at scale \"" + scaleString + "\"" );<br /> <br />             File imageFile = new File( fileName );<br />             <br />             if( !imageFile.exists())<br />             {<br />                 response.sendError(HttpServletResponse.SC_NOT_FOUND,<br />                                    "File " + image + " not found" );<br />                 return;<br />             }<br />             <br />             BufferedImage sourceImage = ImageIO.read( imageFile );<br /> <br />             float scale = Float.parseFloat( scaleString ) / 100;<br />             int targetWidth = (int)(sourceImage.getWidth() * scale);<br />             int targetHeight = (int)(sourceImage.getHeight() * scale);<br /> <br />             BufferedImage scaledImage = new BufferedImage( targetWidth,<br />                                                            targetHeight,<br />                                                            BufferedImage.TYPE_INT_RGB );<br />             Graphics2D g2d = scaledImage.createGraphics();<br />             g2d.setRenderingHint( RenderingHints.KEY_INTERPOLATION,<br />                                   RenderingHints.VALUE_INTERPOLATION_BILINEAR );<br /> <br />             g2d.drawImage( sourceImage, 0, 0, targetWidth, targetHeight, null );<br />             <br />             //<br />             // the output is always written as a jpeg<br />             //<br />             response.setContentType("image/jpeg");<br /> <br />             //<br />             // allow for caching<br />             //<br />             response.setHeader( "Cache-Control", "max-age=" + maxAge );<br /> <br />             ImageIO.write( scaledImage, "jpeg", response.getOutputStream() );<br />         }<br />         catch(Exception e)<br />         {<br />             log.error("Got exception resizing image", e);<br />             response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage() );<br />         }<br />     }<br /> }<br /> <br /> [/code]<br /> <br /> And in your web.xml you'll need something like:<br /> <br /> [code]<br /> 	 &lt;servlet&gt;<br /> 		&lt;servlet-name&gt;imageScaler&lt;/servlet-name&gt;<br /> 		&lt;servlet-class&gt;com.xigole.util.images.ImageResizerServlet&lt;/servlet-class&gt;<br /> 		&lt;init-param&gt;<br /> 			&lt;param-name&gt;imageDir&lt;/param-name&gt;<br /> 			&lt;param-value&gt;catalog_images&lt;/param-value&gt;<br /> 		&lt;/init-param&gt;<br /> 		&lt;init-param&gt;<br /> 			&lt;param-name&gt;maxAge&lt;/param-name&gt;<br /> 			&lt;param-value&gt;3600&lt;/param-value&gt;<br /> 		&lt;/init-param&gt;<br /> 	 &lt;/servlet&gt;<br /> <br /> 	&lt;servlet-mapping&gt;<br /> 		&lt;servlet-name&gt;imageScaler&lt;/servlet-name&gt;<br /> 		&lt;url-pattern&gt;/imageScaler&lt;/url-pattern&gt;<br /> 	&lt;/servlet-mapping&gt;<br /> [/code]<br /> ]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/547/2077.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/547/2077.page</link>
				<pubDate><![CDATA[Mon, 26 Jan 2009 10:48:54]]> GMT</pubDate>
				<author><![CDATA[ stdunbar]]></author>
			</item>
			<item>
				<title>A simple duration method</title>
				<description><![CDATA[ I have often been frustrated that the Java standard library does not do a good job with time durations.  Sure, there are plenty of classes and methods to deal with time and date but nothing that is meant to use a when you have a delta between two timestamps.<br /> <br /> So I wrote a very simple method to simply print how long of a duration a number of milliseconds is.  It only goes to hours so if your duration is longer than that there will be many hours.  Additionally, this requires Java 5 and above.<br /> <br /> [code]<br /> import java.io.ByteArrayOutputStream;<br /> import java.io.PrintWriter;<br /> <br /> <br /> public class Duration<br /> {<br />     public static void main( String[] argv )<br />     {<br />         Duration duration = new Duration();<br /> <br />         System.out.println( "duration is " + duration.printDuration( 3601001, true ) );<br />     }<br /> <br />     private String printDuration( long milliseconds, boolean longFormat )<br />     {<br />         long hours = milliseconds / ((long)(1000 * 60 * 60));<br />         long minutes = (milliseconds % (1000 * 60 * 60)) / ((long)(1000 * 60 ));<br />         long seconds = (milliseconds % (1000 * 60 * 60) % (1000 * 60)) / (long)1000;<br />         long millisecondsRemainder = milliseconds % (long)1000;<br /> <br />         ByteArrayOutputStream baos = new ByteArrayOutputStream();<br /> <br />         PrintWriter writer = new PrintWriter( baos );<br /> <br />         if( longFormat )<br />              writer.printf( "%1$d hour%2$s %3$d minute%4$s %5$d second%6$s and %7$d millisecond%8$s",<br />                             hours, (hours == 1 ? "" : "s" ),<br />                             minutes, (minutes == 1 ? "" : "s"),<br />                             seconds, (seconds == 1 ? "" : "s"),<br />                             millisecondsRemainder, (millisecondsRemainder == 1 ? "" : "s" ) );<br />         else<br />             writer.printf( "%1$02d:%2$02d:%3$02d.%4$03d", hours, minutes, seconds, millisecondsRemainder );<br /> <br />         writer.close();<br /> <br />         return( baos.toString() );<br />     }<br /> }<br /> [/code]]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/493/1902.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/493/1902.page</link>
				<pubDate><![CDATA[Fri, 22 Aug 2008 10:02:51]]> GMT</pubDate>
				<author><![CDATA[ stdunbar]]></author>
			</item>
			<item>
				<title>Using a self signed certificate with SSL</title>
				<description><![CDATA[ One problem people have with Java and SSL is that the certificate manager will reject any self signed certificates.  This is common when you are doing development or are using an internal certificate that you don't want to pay money for from a commercial certificate authority.<br /> <br /> One way to handle this is to simply accept any certificate, regardless of what it has in it.  Below is a simple program to do just that - it reads a URL and, regardless of what the certificate says, prints out the contents of the URL.  Note that this is a bit dangerous to use in a production environment so be careful.<br /> <br /> I'll also attach a zip file with a build.xml so that you can build the program with ant.<br /> <br /> [code]<br /> package com.xigole.util.ssl;<br /> <br /> import java.io.IOException;<br /> import java.io.InputStream;<br /> import java.net.MalformedURLException;<br /> import java.net.URL;<br /> import java.net.URLConnection;<br /> <br /> import javax.net.ssl.HttpsURLConnection;<br /> import javax.net.ssl.SSLContext;<br /> import javax.net.ssl.TrustManager;<br /> import javax.net.ssl.X509TrustManager;<br /> <br /> public class SelfSignedCertTest {<br /> 	public static void main(String[] argv) {<br /> 		if (argv.length != 1) {<br /> 			System.err.println("usage: SelfSignedCertTest hostname");<br /> 			System.exit(1);<br /> 		}<br /> <br /> 		TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {<br /> 			public java.security.cert.X509Certificate[] getAcceptedIssuers() {<br /> 				return null;<br /> 			}<br /> <br /> 			public void checkClientTrusted(<br /> 					java.security.cert.X509Certificate[] certs, String authType) {<br /> 			}<br /> <br /> 			public void checkServerTrusted(<br /> 					java.security.cert.X509Certificate[] certs, String authType) {<br /> 				System.out.println("authType is " + authType);<br /> 				System.out.println("cert issuers");<br /> 				for (int i = 0; i &lt; certs.length; i++) {<br /> 					System.out.println("\t" + certs[i].getIssuerX500Principal().getName());<br /> 					System.out.println("\t" + certs[i].getIssuerDN().getName());<br /> 		  	   }<br /> 			}<br /> 		} };<br /> <br /> 		try {<br /> 			SSLContext sc = SSLContext.getInstance("SSL");<br /> 			sc.init(null, trustAllCerts, new java.security.SecureRandom());<br /> 			HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());<br /> 		} catch (Exception e) {<br /> 			e.printStackTrace();<br /> 			System.exit(1);<br /> 		}<br /> <br /> 		URL url = null;<br /> 		try {<br /> 			url = new URL("https", argv[0], 443, "/");<br /> 		} catch (MalformedURLException mue) {<br /> 			mue.printStackTrace();<br /> 			System.exit(1);<br /> 		}<br /> <br /> 		try {<br /> 			URLConnection connection = url.openConnection();<br /> <br /> 			InputStream is = connection.getInputStream();<br /> 			byte[] buffer = new byte[1024];<br /> 			int bytesRead = 0;<br /> <br /> 			while ((bytesRead = is.read(buffer)) != -1)<br /> 				System.out.println(new String(buffer, 0, bytesRead));<br /> 		} catch (IOException ioe) {<br /> 			ioe.printStackTrace();<br /> 			System.exit(1);<br /> 		}<br /> 	}<br /> }<br /> [/code]<br /> <br /> Note that this is almost the exact same code I posted in [url=http://forums.devshed.com/java-help-9/login-and-download-file-over-https-360178.html]a Devshed thread[/url] but the attachment has a complete build environment too.<br /> <br /> ]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/290/1235.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/290/1235.page</link>
				<pubDate><![CDATA[Thu, 15 Jun 2006 11:47:01]]> GMT</pubDate>
				<author><![CDATA[ stdunbar]]></author>
			</item>
			<item>
				<title>Database enabled GUI Forms</title>
				<description><![CDATA[ I am on the hunt for a tutorial or tool that will show me how I can easily write database desktop applications in Java.  Is there a standard way for building database forms in java?  Is there a good IDE that allows you to drop database enabled Swing components onto a canvas, and will handle updates and searches for you without the developer having to write all that code themselves?  I can't be the first person to want to do this, but so far, all my - numerous - searches on the web have drawn a blank.  I suspect I need to go down the javabeans (or enterprise beans) route.]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/141/507.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/141/507.page</link>
				<pubDate><![CDATA[Sun, 5 Feb 2006 12:31:12]]> GMT</pubDate>
				<author><![CDATA[ charlesdeb]]></author>
			</item>
			<item>
				<title>(How to Use) The Scanner Class</title>
				<description><![CDATA[ [b][u][url=http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html]The Scanner Class[/url][/u][/b]<br /> The Scanner class is a class used for "scanning" primitive types and<br /> Strings. It can be used to get input from an InputStream, to parse through<br /> a String of text or to read from a file.<br /> <br /> [b]Parsing Through a String[/b]<br /> The constructor that we will be using from the Scanner class is:<br /> [code]<br /> Constructor               Description<br /> --------------------------------------------------------------------------------<br /> Scanner(String source)    Constructs a new Scanner that produces<br />                           values scanned from the specified String.<br /> --------------------------------------------------------------------------------<br /> [/code]<br /> The methods that we will be using from the Scanner class are:<br /> [code]<br /> Method       Description<br /> --------------------------------------------------------------------------------<br /> nextInt()    Scans the next token of the input as an int.<br /> <br /> hasNextInt() Returns true if the next token in this scanner's input can be<br />              interpreted as an int value in the default radix using the<br />              nextInt() method.<br /> --------------------------------------------------------------------------------<br /> [/code]<br /> We will now write a basic program to demonstrate how to use the Scanner<br /> class to parse through a String for even numbers.<br /> [code]<br /> import java.util.Scanner;<br /> <br /> public class ParseString<br /> {    <br />     public static void main(String[] args)<br />     {<br />         private static Scanner scanner = new Scanner("1 2 3 4 5 6 7 8 9 10");<br /> <br />         while (scanner.hasNextInt()) {<br />             int num = scanner.nextInt();<br />             <br />             if (num % 2 == 0)<br />                 System.out.println(num);<br />         }<br />     }<br /> }<br /> [/code]<br /> Output from this program:<br /> [code]<br /> 2<br /> 4<br /> 6<br /> 8<br /> 10[/code]<br /> <br /> [b]Setting the Delimiter[/b]<br /> When you create an instance of the Scanner class, the default<br /> delimiter is whitespace. The Scanner class provides methods<br /> to set the delimiter.<br /> [code]<br /> Method                         Description<br /> --------------------------------------------------------------------------------<br /> useDelimiter(Pattern pattern)  Sets this scanner's delimiting pattern<br />                                to the specified pattern.<br /> <br /> useDelimiter(String pattern)   Sets this scanner's delimiting pattern<br />                                to a pattern constructed from the<br />                                specified String.<br /> --------------------------------------------------------------------------------<br /> [/code]<br /> We will now write a program that demonstrates how to set the delimiter<br /> of the Scanner class using the useDelimiter(String) method.<br /> [code]<br /> import java.util.Scanner;<br /> <br /> public class ParseString<br /> {    <br />     public static void main(String[] args)<br />     {<br />         Scanner scanner =  new Scanner("1, 2, 3, 4, 5, 6, 7, 8, 9, 10").useDelimiter(", ");<br /> <br />         while (scanner.hasNextInt()) {<br />             int num = scanner.nextInt();<br />             <br />             if (num % 2 == 0)<br />                 System.out.println(num);<br />         }<br />     }<br /> }<br /> [/code]<br /> Output from this program:<br /> [code]<br /> 2<br /> 4<br /> 6<br /> 8<br /> 10[/code]<br /> <br /> [b]Reading User Input[/b]<br /> The constructor that we will be using from the Scanner class is:<br /> [code]<br /> Constructor                    Description<br /> --------------------------------------------------------------------------------<br /> Scanner(InputStream source)    Constructs a new Scanner that <br />                                produces values scanned from the<br />                                specified input stream.<br /> --------------------------------------------------------------------------------<br /> [/code]<br /> The methods that we will be using from the Scanner class are:<br /> [code]<br /> Method            Description<br /> --------------------------------------------------------------------------------<br /> next()            Finds and returns the next complete token from<br />                   this scanner.<br /> <br /> nextDouble()      Scans the next token of the input as a double.<br /> <br /> nextInt()         Scans the next token of the input as an int.<br /> <br /> nextLine()        Advances this scanner past the current line and<br />                   returns the input that was skipped.<br /> --------------------------------------------------------------------------------<br /> [/code]<br /> We will now write a basic program to demonstrate how to read from<br /> System.in using the Scanner class.<br /> [code]<br /> /* import the Scanner class */<br /> import java.util.Scanner;<br /> <br /> /** demonstrate how to read from System.in */<br /> class ReadConsole {<br />    public static void main(String[] args) {<br />         Scanner scanner = new Scanner(System.in);<br /> <br />         System.out.print("Enter your full name: ");<br />         String name = scanner.nextLine();<br />         <br />         System.out.print("Enter your Zodiac sign: ");<br />         String zodiac = scanner.next();<br />         <br />         System.out.print("Enter your weight (kg): ");<br />         double weight = scanner.nextDouble();<br />         <br />         System.out.print("Enter your lucky number: ");<br />         int luckyNum = scanner.nextInt();<br />         <br />         System.out.println("Hello, " + name + ".");<br />         System.out.println("Your lucky number is  " + luckyNum + ".");<br />         System.out.println("You weigh " + weight + " kg.");<br />         System.out.println("Your Zodiac sign is " + zodiac + ".");<br />     }<br /> }<br /> [/code]<br /> Output from this program:<br /> [code]<br /> Enter your full name: destin<br /> Enter your Zodiac sign: Cancer<br /> Enter your weight (kg): 70.45<br /> Enter your lucky number: 7<br /> <br /> Hello, destin.<br /> Your lucky number is 7.<br /> You weigh 70.45 kg.<br /> Your Zodiac sign is Cancer.<br /> [/code]<br /> <br /> [b]Reading From a File[/b]<br /> The constructor that we will be using from the Scanner class is:<br /> [code]<br /> Constructor            Description<br /> --------------------------------------------------------------------------------<br /> Scanner(File source)   Constructs a new Scanner that <br />                        produces values scanned from the<br />                        specified input stream.<br /> --------------------------------------------------------------------------------<br /> [/code]<br /> The methods that we will be using from the Scanner class are:<br /> [code]<br /> Method                Description<br /> --------------------------------------------------------------------------------<br /> nextLine()            Advances this scanner past the current line and<br />                       returns the input that was skipped.<br /> <br /> hasNextLine()         Returns true if there is another line in the<br />                       input of this scanner.<br /> --------------------------------------------------------------------------------<br /> [/code]<br /> We will now write a basic program to demonstrate how to read from a File<br /> using the Scanner class.<br /> [code]<br /> import java.util.Scanner;<br /> import java.io.*;<br /> <br /> class HelpFile<br /> {   <br />     public static void main(String[] args) throws IOException<br />     {<br />         Scanner scanner = new Scanner(new File("test.txt"));<br />         <br />         while (scanner.hasNextLine())<br />             System.out.println(scanner.nextLine());<br />     }<br /> }<br /> [/code]<br /> test.txt:<br /> [code]<br /> line1<br /> line2<br /> line3<br /> line4<br /> line5[/code]<br /> <br /> Output from this program:<br /> [code]<br /> line1<br /> line2<br /> line3<br /> line4<br /> line5[/code]]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/128/437.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/128/437.page</link>
				<pubDate><![CDATA[Sun, 22 Jan 2006 13:32:45]]> GMT</pubDate>
				<author><![CDATA[ destin]]></author>
			</item>
			<item>
				<title>Your first Java Server Faces application - a slight variation on hello world for JSF</title>
				<description><![CDATA[ This article is a simple "Hello World" type of application using [url=http://java.sun.com/j2ee/javaserverfaces/]Java Server Faces[/url] or JSF.  This is a fairly new Java Enterprise Edition technology that aims to standardize and simplify HTML form parsing and web flow mechanisms.  In that respect it has some strong conceptual similarities with [url=http://struts.apache.org/]Struts[/url].  However, in my mind JSF takes Struts further into a true MVC model.  As Craig McClanahan, the original creator of Struts was part of the [url=http://www.jcp.org/en/jsr/detail?id=127]Java Server Faces JSR[/url] he has helped include some of the great ideas of Struts into JSF.<br /> <br /> So, onto the code!<br /> <br /> On the presentation side JSF is basically a few [url=http://www-128.ibm.com/developerworks/java/library/j-jsptags.html]JSP tag libraries[/url] that help with presentation and web flow.  Our sample application is going to allow someone to input their name and have JSF say hello to them (yeah, it'll be a real exciting application :) ).  So lets start with the page where users are asked for their name:<br /> <br /> [code]<br /> &lt;%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %&gt;<br /> &lt;%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %&gt;<br /> &lt;f:loadBundle basename="messages" var="msg"/&gt;<br /> <br /> &lt;html&gt;<br />     &lt;head&gt;<br />         &lt;title&gt;Welcome to JSF!  Please enter your name&lt;/title&gt;<br />     &lt;/head&gt;<br /> <br />     &lt;body&gt;<br />         &lt;f:view&gt;<br />             &lt;h1&gt;<br />                 &lt;h:outputText value="#{msg.helloMessage}"/&gt;<br />             &lt;/h1&gt;<br /> <br />             <p><br />                 &lt;h:messages style="color:darkred"/&gt;<br />             </p><br /> <br />             &lt;h:form id="helloForm"&gt;<br />                 &lt;h:outputText value="#{msg.promptText}"/&gt;<br /> <br />                 &lt;h:inputText value="#{personBean.personName}" required="true"&gt;<br />                     &lt;f:validateLength minimum="2" maximum="10"/&gt;<br />                 &lt;/h:inputText&gt;<br /> <br />                 &lt;h:commandButton action="greeting" value="#{msg.buttonText}" /&gt;<br />             &lt;/h:form&gt;<br />         &lt;/f:view&gt;<br />     &lt;/body&gt;<br /> &lt;/html&gt;<br /> [/code]<br /> <br /> This is the initial JSP that will be presented to a user.  It asks for a user name and contains a submit button.  One of the cool things is that this example includes some simple validation.  No extra code needs to be written to have the page validate that the input name has to be between 2 and 10 characters.<br /> <br /> The first two lines of the file simply define the JSF tag libraries.  The prefix is not required to be as shown but these are the ones commonly used so I'll stick with that.<br /> <br /> Next the line:<br /> [code]&lt;f:loadBundle basename="messages" var="msg"/&gt;[/code] loads a message bundle for our JSP.  JSF, like Struts and well written JSP's strongly encourages you to use resource bundles for all the text and this example uses that.<br /> <br /> After some normal HTML preamble you can see the first time we use the JSF tag lib with the h:outputText tag.  This tag does exactly what it says - it outputs text.  The syntax "#{ ... }" is modeled on the [url=http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPIntro7.html]JSP expression language[/url].  It looks almost the same but for JSF it has the "#" instead of the "$".<br /> <br /> Next, since ultimately this page is posted back to itself in a failure case we include any error messages that have occured during processing.  This is very similar to the Struts &lt;html:errors&gt; tag.<br /> <br /> The form is defined next.  None of this is too difficult to figure out what is going on.  As I mentioned one of the cool things is that we're building validation into this form.  As you can see:<br /> [code] <br /> &lt;h:inputText value="#{personBean.personName}" required="true"&gt;<br />     &lt;f:validateLength minimum="2" maximum="10"/&gt;<br /> &lt;/h:inputText&gt;<br /> [/code]<br /> we tell JSF that the input text is required and that it must be between 2 and 10 characters.  This is all done with just the declaration - no extra code must be written.<br /> <br /> Lastly we have a commandButton (a button to submit the form) that has the action of "greeting".  Again, like Struts this is an externalized reference to where we want the page to go next.]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/95/299.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/95/299.page</link>
				<pubDate><![CDATA[Fri, 23 Dec 2005 11:07:23]]> GMT</pubDate>
				<author><![CDATA[ stdunbar]]></author>
			</item>
			<item>
				<title>Building a simple socket based HTTP server</title>
				<description><![CDATA[ I'd like to create an article on building a very simple HTTP server.  There are other tutorials out there but I'll try my shot at it too.  It seems that sockets are a common discussion topic.  As part of this the first post will be about the requirements that I'm going to try to satisfy.<br /> <br /> The first and most important thing is that the purpose of this is to provide a framework for learning.  It is not to produce a production quality web server like Apache or Tomcat.  While the code will be high quality I may take shortcuts or leave some features out in the interest of time or clarity.  I will try to point out where I feel that a shortcut or non-enterprise design has been used.  A side effect of this requirement is we will not use anything except for the classes available in 1.4 J2SE.  There are many excellent libraries available for networking.  But this is meant to be a learning program.  By doing it "by hand" one time I find that you learn significantly more than jumping straight to a thrid party library.<br /> <br /> Which leads to the second requirement.  I'm going to limit the initial scope to only handle the HTTP GET command.  This is the most commonly used HTTP command.  However, this means that the first version of the software will not be able to handle form processing.  As time permits I will also include the HTTP POST command.<br /> <br /> The server should comply with [url=http://www.w3.org/Protocols/rfc2616/rfc2616.html]RFC 2616[/url] in the GET area where possible.  Where it isn't possible it should work well with any HTTP client.  While the majority of the HTTP clients are browsers the server should work equally well with programs such as [url=http://www.gnu.org/software/wget/wget.html]wget[/url] where there is much more limited user interaction.<br /> <br /> Lastly, the code will be developed in a Java [b]1.4[/b] environment.  While Java 1.5/5.0 is the current release the intention is to allow the most number of people to benefit from this.  1.5 is still in limited use outside of schools.  From what I can see a significant number of people are still using 1.4.  Where something might be easier in 1.5 we will try to point that out.<br /> <br /> If you'd like to see other requirements please feel free to post it in this thread.  We can discuss what else may be useful and add it to the requirements as time permits.<br /> ]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/62/144.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/62/144.page</link>
				<pubDate><![CDATA[Fri, 2 Dec 2005 11:39:01]]> GMT</pubDate>
				<author><![CDATA[ stdunbar]]></author>
			</item>
	</channel>
</rss>
