<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-23461296</id><updated>2011-09-13T23:54:37.543-07:00</updated><title type='text'>Kendrew's Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://kendrew88.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/23461296/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://kendrew88.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Kendrew</name><uri>http://www.blogger.com/profile/01739965342370430663</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-23461296.post-8561943202313060849</id><published>2008-12-07T17:06:00.000-08:00</published><updated>2008-12-07T18:02:09.828-08:00</updated><title type='text'>Migrating from preview SDK to 1.0 of JavaFX</title><content type='html'>I'm developing a course that includes the JavaFX technology. That part was written a few months ago, based on the JavaFX preview SDK. As the JavaFX 1.0 has been released, I convert the programs from the JavaFX preview to 1.0. The following is a summary of the changes in JavaFX that I notice during the conversion.
&lt;ul&gt;&lt;li&gt;To define constant values, use the &lt;tt&gt;def&lt;/tt&gt; keyword (instead of the &lt;tt&gt;readonly&lt;/tt&gt; keyword in the preview). E.g.,&lt;pre&gt;def PI = 3.14;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;To write an application (with Swing frames), use the &lt;tt&gt;javafx.stage.Stage&lt;/tt&gt; and the &lt;tt&gt;javafx.scene.Scene&lt;/tt&gt; classes as follows. There is no &lt;tt&gt;javafx.ext.swing.SwingFrame&lt;/tt&gt; class or &lt;tt&gt;javafx.application&lt;/tt&gt; package.&lt;pre&gt;Stage {
  scene: Scene {
    content: ...
  }
}&lt;/pre&gt;Programs written in this way can also be executed as applets without modification.&lt;/li&gt;&lt;li&gt;Swing components in the &lt;tt&gt;javafx.ext.swing&lt;/tt&gt; package are prefixed by &lt;tt&gt;Swing&lt;/tt&gt;. For example, the Swing label is &lt;tt&gt;javafx.ext.swing.SwingLabel&lt;/tt&gt; (instead of &lt;tt&gt;javafx.ext.swing.Label&lt;/tt&gt; in the preview).&lt;/li&gt;&lt;li&gt;To layout GUI components, use the classes in the &lt;tt&gt;javafx.scene.layout&lt;/tt&gt; package, such as the &lt;tt&gt;VBox&lt;/tt&gt; and &lt;tt&gt;HBox&lt;/tt&gt; classes. There is no panel class in the &lt;tt&gt;javafx.ext.swing&lt;/tt&gt; package (such as &lt;tt&gt;FlowPanel&lt;/tt&gt; in the preview).
&lt;/li&gt;&lt;li&gt;The preferred size of a Swing component in &lt;tt&gt;javafx.ext.swing&lt;/tt&gt; package cannot be modified when the it is created. (It could be in the preview.)
&lt;/li&gt;&lt;li&gt;In class definition, attributes (instance variables) are declared using the &lt;tt&gt;var&lt;/tt&gt; keyword (instead of &lt;tt&gt;attribute&lt;/tt&gt; in the preview). E.g.,&lt;pre&gt;class Person {
  var name: String;
}&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;To declare a function that overrides a superclass's function, use the &lt;tt&gt;override&lt;/tt&gt; keyword (no need in the preview):&lt;pre&gt;class Person {
  override function toString() : String { "..." }
}&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;There is no menu support. (The &lt;tt&gt;Menu&lt;/tt&gt; and &lt;tt&gt;MenuItem&lt;/tt&gt; classes in the &lt;tt&gt;javafx.ext.swing&lt;/tt&gt; package exist in the preview but not in 1.0.)&lt;/li&gt;&lt;li&gt;The shape classes, such as &lt;tt&gt;Rectangle&lt;/tt&gt; and &lt;tt&gt;Circle&lt;/tt&gt;, are in the &lt;tt&gt;javafx.scene.shape&lt;/tt&gt; package (instead of the &lt;tt&gt;javafx.scene.geometry&lt;/tt&gt; package).&lt;/li&gt;&lt;li&gt;To start, or play, a &lt;tt&gt;Timeline&lt;/tt&gt;, call the &lt;tt&gt;Timeline&lt;/tt&gt;'s &lt;tt&gt;play()&lt;/tt&gt; method (instead of the &lt;tt&gt;start()&lt;/tt&gt; method in the preview.)&lt;/li&gt;&lt;li&gt;Shapes, in the &lt;tt&gt;javafx.scene.shape&lt;/tt&gt; package, are not transparent by default. Set a shape's &lt;tt&gt;color&lt;/tt&gt; attribute to &lt;tt&gt;Color.TRANSPARENT&lt;/tt&gt; to make it transparent.
&lt;/li&gt;&lt;li&gt;The &lt;tt&gt;+&lt;/tt&gt; operator cannot be applied to strings, e.g., &lt;tt&gt;10 + " cents"&lt;/tt&gt; is not valid. Use string interpolation instead. E.g.,&lt;pre&gt;int n = 10;
var s = "{n} cents";&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;There are built-in functions &lt;tt&gt;print()&lt;/tt&gt; and &lt;tt&gt;println()&lt;/tt&gt;. There is no need to use &lt;tt&gt;java.lang.System.out.println()&lt;/tt&gt; and &lt;tt&gt;java.lang.System.out.print()&lt;/tt&gt; now.&lt;/li&gt;&lt;li&gt;There is a built-in function &lt;tt&gt;FX.exit()&lt;/tt&gt;. There is no need to use &lt;tt&gt;java.lang.System.exit()&lt;/tt&gt; now.&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/23461296-8561943202313060849?l=kendrew88.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kendrew88.blogspot.com/feeds/8561943202313060849/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=23461296&amp;postID=8561943202313060849' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/23461296/posts/default/8561943202313060849'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/23461296/posts/default/8561943202313060849'/><link rel='alternate' type='text/html' href='http://kendrew88.blogspot.com/2008/12/migrating-from-preview-sdk-to-10-of.html' title='Migrating from preview SDK to 1.0 of JavaFX'/><author><name>Kendrew</name><uri>http://www.blogger.com/profile/01739965342370430663</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-23461296.post-7365942596141091718</id><published>2008-02-04T00:24:00.000-08:00</published><updated>2008-02-15T06:49:09.704-08:00</updated><title type='text'>Classes and objects</title><content type='html'>&lt;p&gt;
In every first lesson of object-oriented programming, the concepts of classes and objects are introduced. Typically,

&lt;ul&gt;
&lt;li&gt;an object represents an entity in real life that has states and behaviours, and&lt;/li&gt;
&lt;li&gt;a class is a blueprint/template/design of a certain type of similar objects.
&lt;/li&gt;
&lt;/ul&gt;

While these explanations are good and precise, some, if not many, new learners still cannot get the idea and their difference after reading them and the related examples. As majority of learners have procedural programming background, here I try to illustrate the concepts of classes and objects with comparison to functions in procedural programming.
&lt;/p&gt;

&lt;p&gt;
When writing a function, we are defining what will happen when the function is used (invoked). For example, let's define a function &lt;code&gt;sum&lt;/code&gt;:

&lt;div class="code"
&gt;int sum(int a, int b) {
  int r;
  r = a + b;
  return r;
}
&lt;/div&gt;
&lt;/p&gt;

&lt;p&gt;
This definition does nothing more than allowing the system to look up the method's execution when it is used elsewhere. When this function is invoked

&lt;div class="code"&gt;int x = sum(100, 200);&lt;/div&gt;

the system uses the definition of &lt;code&gt;sum &lt;/code&gt;and executes the code in the definition.
&lt;/p&gt;

&lt;p&gt;
In a similar way, a class is the definition of an object. It defines what will happen when the object is used. While using a function is mostly obvious - invoking it, using an object can be more complex - creating it, accessing its data fields, invoking its methods. Here I write a class &lt;code&gt;Circle&lt;/code&gt; (as definition of &lt;code&gt;Circle&lt;/code&gt; objects):

&lt;div class="code"
&gt;class Circle {
  int radius; // data field
  Circle(int r) { // constructor
    radius = r;
  }
  double getArea() { // method
    return radius * radius * 3.1416;
  }
}
&lt;/div&gt;
&lt;/p&gt;

&lt;p&gt;
When &lt;code&gt;Circle&lt;/code&gt; objects are used in some other code, the system will look into the class and execute the proper code in the class. For example, with

&lt;div class="code"&gt;Circle c = new Circle(10);&lt;/div&gt;

the constructor of class &lt;code&gt;Circle&lt;/code&gt; will execute and a &lt;code&gt;Circle&lt;/code&gt; object is created. With

&lt;div class="code"&gt;c.radius = 9;&lt;/div&gt;

the data field &lt;code&gt;radius&lt;/code&gt; of the newly created &lt;code&gt;Circle&lt;/code&gt; will be changed. With

&lt;div class="code"&gt;c.getRadius()&lt;/div&gt;

the code inside the method &lt;code&gt;getRadius&lt;/code&gt; of the &lt;code&gt;Circle&lt;/code&gt; will be executed.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/23461296-7365942596141091718?l=kendrew88.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kendrew88.blogspot.com/feeds/7365942596141091718/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=23461296&amp;postID=7365942596141091718' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/23461296/posts/default/7365942596141091718'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/23461296/posts/default/7365942596141091718'/><link rel='alternate' type='text/html' href='http://kendrew88.blogspot.com/2008/02/classes-and-objects-in-every-first.html' title='Classes and objects'/><author><name>Kendrew</name><uri>http://www.blogger.com/profile/01739965342370430663</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-23461296.post-114174012732593317</id><published>2006-03-07T05:50:00.000-08:00</published><updated>2008-02-18T07:18:44.446-08:00</updated><title type='text'>From zero to a running servlet in one minute</title><content type='html'>&lt;p&gt;
Many learners to programming servlets find it difficult to get started working with Tomcat - installing, configuring, deploying with the Tomcat manager or admin, reloading a modified servlet, etc. etc. Using Netbeans can greatly reduce the frustration in initial studying, as we can create a working servlet easily and quickly. Here are the steps:
&lt;/p&gt;

&lt;ol style="list-style-type:decimal; margin-left:-3em"&gt;

&lt;li&gt;Start Netbeans&lt;br /&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/7472/2407/1600/nb0.2.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/7472/2407/400/nb0.0.jpg" alt="" border="0" /&gt;&lt;/a&gt;
&lt;/li&gt;

&lt;li&gt;Create a  project by clicking the menu File -&gt; New Project...&lt;br /&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/7472/2407/1600/nb1.1.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/7472/2407/400/nb1.jpg" alt="" border="0" /&gt;&lt;/a&gt;
&lt;/li&gt;

&lt;li&gt;In the New Project dialog, select Category of Web, and Projects type Web Application, then click Next &gt;&lt;br /&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/7472/2407/1600/nb2.1.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/7472/2407/400/nb2.0.jpg" alt="" border="0" /&gt;&lt;/a&gt;
&lt;/li&gt;

&lt;li&gt;In the New Web Application dialog, enter the Project Name (e.g., WebExample1), then click Next &gt;&lt;br /&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/7472/2407/1600/nb3.0.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/7472/2407/400/nb3.jpg" alt="" border="0" /&gt;&lt;/a&gt;
&lt;/li&gt;

&lt;li&gt;In the next step, we don't use any framework, so just click Finish.&lt;br /&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/7472/2407/1600/nb4.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/7472/2407/400/nb4.jpg" alt="" border="0" /&gt;&lt;/a&gt;
&lt;/li&gt;

&lt;li&gt;Netbeans is creating the project.&lt;br /&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/7472/2407/1600/nb5.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/7472/2407/400/nb5.jpg" alt="" border="0" /&gt;&lt;/a&gt;
&lt;/li&gt;

&lt;li&gt;The project is created. We can just ignore the default JSP page that is automatically generated.&lt;br /&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/7472/2407/1600/nb6.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/7472/2407/400/nb6.jpg" alt="" border="0" /&gt;&lt;/a&gt;
&lt;/li&gt;

&lt;li&gt;Now, let's create a servlet.  Click the menu File -&gt; New File...&lt;br /&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/7472/2407/1600/nb7.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/7472/2407/400/nb7.jpg" alt="" border="0" /&gt;&lt;/a&gt;
&lt;/li&gt;

&lt;li&gt;In the New File dialog, select the Category of Web, and the File Type of Servlet, then click Next &gt;&lt;br /&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/7472/2407/1600/nb8.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/7472/2407/400/nb8.jpg" alt="" border="0" /&gt;&lt;/a&gt;
&lt;/li&gt;

&lt;li&gt;In the New Servlet dialog, enter the Class Name (e.g., ServletExample1), then click Next &gt;&lt;br /&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/7472/2407/1600/nb10.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/7472/2407/400/nb10.jpg" alt="" border="0" /&gt;&lt;/a&gt;
&lt;/li&gt;

&lt;li&gt;In the next step, we use all default deployment values, so just click Finish.&lt;br /&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/7472/2407/1600/nb11.1.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/7472/2407/400/nb11.1.jpg" alt="" border="0" /&gt;&lt;/a&gt;
&lt;/li&gt;

&lt;li&gt;A complete servlet is generated.&lt;br /&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/7472/2407/1600/nb12.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/7472/2407/400/nb12.0.jpg" alt="" border="0" /&gt;&lt;/a&gt;
&lt;/li&gt;

&lt;li&gt;Edit the servlet do show something. E.g., remove the line "/* TODO output your page here." and the line "*/".&lt;br /&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/7472/2407/1600/nb13.1.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/7472/2407/400/nb13.0.jpg" alt="" border="0" /&gt;&lt;/a&gt;
&lt;/li&gt;

&lt;li&gt;After editing the servlet, save it by clicking the menu File -&gt; Save.&lt;br /&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/7472/2407/1600/nb14.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/7472/2407/400/nb14.jpg" alt="" border="0" /&gt;&lt;/a&gt;
&lt;/li&gt;

&lt;li&gt;We can now run the servlet. Click the menu Run -&gt; Run File -&gt; Run "ServletExample1.java"&lt;br /&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/7472/2407/1600/nb15.0.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/7472/2407/400/nb15.0.jpg" alt="" border="0" /&gt;&lt;/a&gt;
&lt;/li&gt;

&lt;li&gt;Accept the default Execution URL by clicking OK.&lt;br /&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/7472/2407/1600/nb16.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/7472/2407/400/nb16.0.jpg" alt="" border="0" /&gt;&lt;/a&gt;
&lt;/li&gt;

&lt;li&gt;Netbeans will compile the servlet, start the Tomcat server, deploy the web app.&lt;br /&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/7472/2407/1600/nb17.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/7472/2407/400/nb17.jpg" alt="" border="0" /&gt;&lt;/a&gt;
&lt;/li&gt;

&lt;li&gt;And then open a browser to access the URL for your servlet. The servlet is executed.&lt;br /&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/7472/2407/1600/nb18.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/7472/2407/400/nb18.jpg" alt="" border="0" /&gt;&lt;/a&gt;
&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt;
In this way, we can create and run a servlet, without the installation and configuration of Tomcat. Tomcat 5.5.9 is bundled and pre-configured in Netbeans 5.0.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/23461296-114174012732593317?l=kendrew88.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kendrew88.blogspot.com/feeds/114174012732593317/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=23461296&amp;postID=114174012732593317' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/23461296/posts/default/114174012732593317'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/23461296/posts/default/114174012732593317'/><link rel='alternate' type='text/html' href='http://kendrew88.blogspot.com/2006/03/from-zero-to-running-servlet-in-one.html' title='From zero to a running servlet in one minute'/><author><name>Kendrew</name><uri>http://www.blogger.com/profile/01739965342370430663</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
