Saturday, February 28, 2015

JAVAFX

JAVAFX

FEBRUARY 2015. And so the past has finally reached the future to become the present.

Starting next month, this web page will write one programming blog in Knight in Programming once a week. I will also write one mathematics blog in Knight in Math web page once a week.

Since some employers also look for programmers who also know the software in the Microsoft Office suite like Word, Excel, and Access, I will also include them in the Knight in Programming blog. I will also include other programming aspects, not just the programming language itself.

For the Knight in Math blog, I will discuss all math subjects from Arithmetic to doctorate level Mathematics, essentially all of Mathematics.

JavaFX is the new paradigm for GUI programming in Java. First, there was AWT which was too much platform dependent. So the Swing package replaced AWT to make it less platform dependent. Now, since website technology have advanced, JavaFX was designed to match the advancement in website technology.

Here is a sample JavaFX application.

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.stage.*;
import javafx.scene.layout.*;

/**
 * Program Description.
 *
 * @author (John Sindayen)
 * @version (February 28, 2015)
 */
public class JavaFXGUI extends Application {
    @Override
    public void start(Stage primaryStage) {
        //Create components.
        primaryStage.setTitle("JavaFX GUI Application");
        FlowPane pane = new FlowPane();
        Scene scene = new Scene(pane, 300, 300);
        Label label = new Label("READ ME");
        TextField textField = new TextField("TYPE ME");
        Button button = new Button("CLICK ME");
     
        //Add components.
        pane.getChildren().addAll(label, textField, button);
        primaryStage.setScene(scene);
     
        //Show components.
        primaryStage.show();
    }
}

The GUI pictured here is a Swing GUI that can be coded into JavaFX.



The first picture is the main data entry form. The second picture is an error message that outputs when a data is not valid.

CYK:
What AWT package class do you use in Java to make a window?
What is the programming term for a sequence of characters?
What is the name of the character '\n'?

Java is fun!

John Sindayen

Friday, February 27, 2015

BEST PRACTICE

BEST PRACTICE

JANUARY 2015. The holidays have come and gone. We can add another day to all our Christmases past and New Years past.

It is also the beginning of another semester in college for me. The spring semester started on this month and I started taking Advanced Java. This might be the last programming course I'll take because I intend to learn more about programming languages by myself.

Here are some of the best practices in programming I've learned so far.

1. Use modular programming by dividing the problem into subproblems, and even into more subproblems, if necessary. In this way, you can see the forest from the trees and the trees from the forest.

2. Always write good documentation for your code, for your own sake and for the programmers who are going to look on your code down the line.

3. Always follow a consistent and good programming style. If you work for a company that follows their own style, follow that style.

Here are some best practices on good programming style.

Start your code with a heading comment like this one:
/*
 * Student: John Sindayen
 * Course: CIT 230 Advanced Java Spring 2015
 * Homework: 1
 * Date Due: 2/5/2015
 * Source file: Soldier.java
 * Version: 1
 * Date: 2/5/2015
 * Copyright (c) 2015 John Sindayen
*/

If writing a class that has javadoc comments, follow this style:
/**
 * Soldier class is a subclass that extends the Person class by adding Rank,
 * Military Unit, Monthly Salary, Marital Profile, Education Profile, and Race
 * properties.
 *
 * @author   John Sindayen
 * @version  1.0
 */
public class Soldier extends Person {

When initializing values for instance fields, use the default values for that type, as in the following:
        rank = null;
        militaryUnit = null;
        monthlySalary = 0.0;

As far as indentation is concerned, indent four spaces to begin a block, whether it is explicit or not, like this:
    public Soldier(String fn, String ln, int a, String g)
    {
        super(fn, ln, a, g);

Indent eight spaces if it is a continuation of a line, like this one:
        if (rk.equals("PVT") || rk.equals("CPL") || rk.equals("SGT")
                || rk.equals("2LT") || rk.equals("1LT") || rk.equals("CPT")

CYK:
What kind of class is an abstract method define in?
What key word is needed to use an interface in Java?
What is the proper term for a function that is a member of a class?

Follow your dreams!

John Sindayen

Saturday, February 14, 2015

JAVADOC

JAVADOC COMMENTS

December 2014. I come in full circle on this month in learning all the programming and web development languages enumerated in the subheading of this blog: C, C++, C#, CSS, HTML, Java, JavaScript, PHP, Python, SQL, and VB.NET.

Upon familiarizing myself with all these languages, I was now prepared to send in my resume and apply for a programming job. So I requested the college I was tutoring in to schedule me only for the Saturday tutoring hours, instead of weekdays, in the next semester. But I also made myself available for college tutoring during the weekdays by appointment only. By appointment tutoring has flexible hours, so I can schedule them in the morning when job interviews were unlikely to be held.

Returning back to the present day, my Advanced Java course assignment involves creating Javadoc comments for a class definition to avail user programmers to use them in their own program.

Javadoc comments are extricated by the JVM utility called javadoc.exe to generate an HTML code describing the contract you made to the user of the class definition. Supposing you have a Java file named Soldier, the following will generate your HTML from the command prompt:

javadoc Soldier.java

How do you display the HTML code? Instantiate a web browser and use the following syntax in the URL bar:

file:///directory/folder0/folder1/folder2/Soldier.html

Here is the HTML page generated by javadoc.


CYK:
What makes a comment a Javadoc comment?
What is the character code to display a Valentine heart?
What data type is used for the smallest and largest integer the computer platform can hold?

Happy Valentine's Day!

John Sindayen

Reference:
http://users.ipfw.edu/chansavj/CS160/Appendices/Appendix_F.pdf

Wednesday, February 11, 2015

DR JAVA

DR JAVA IDE

November 2014. Around this time, I have already studied Java, C, C++, VB.NET, JavaScript, Python, and HTML, and explored C# and CSS. I have yet to write a program in PHP and SQL. So I started learning about PHP and SQL on this month. I am also spending 24 hours a week tutoring programming, Windows 7, and Microsoft Office 2013.

Now going back to the future, just last week, I learned that compilers can get a system error also. And any programs the erroneous compiler has compiled are prone to bugs that can only be fixed by compiling the program again using a new compiler that has not outputted a compiler error.

I was compiling a Java program using DrJava when it outputted an error. I did not pay attention to it because I did not know any better then. The program always returned a runtime exception in the same instruction. I did not know then that it was not really an exception, until I compiled it using the command prompt instead.

The following is the output of the DrJava program run. The ellipsis are placeholders for more data I eliminated to shorten this report. The Compiler Discovery Log is empty. The report outlines the Swing package components. However, the program that I was running at the time did not use Swing components. So, there. I think the wrong spelling of "occurred" emphasizes the error condition.

1 error occured! Please submit a bug report containing the information below and an account of the actions that caused the bug (if known) to http://sourceforge.net/projects/drjava. You may wish to save all your work and restart DrJava. Thanks for your help in making DrJava better!
edu.rice.cs.util.UnexpectedException: java.util.concurrent.TimeoutException
at edu.rice.cs.drjava.model.repl.newjvm.MainJVM$StartingState.restart(MainJVM.java:827)
at edu.rice.cs.drjava.model.repl.newjvm.MainJVM.restartInterpreterJVM(MainJVM.java:160)
 . . .
at edu.rice.cs.drjava.model.DefaultGlobalModel.resetInteractions(DefaultGlobalModel.java:451)
 . . .
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
 . . .
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
 . . .
System Properties:
DrJava Version drjava-20140826-r5761
 . . .
sun.boot.library.path = C:\Program Files\Java\jre1.8.0_25\bin
 . . .
java.vm.name = Java HotSpot(TM) 64-Bit Server VM
 . . .
Used memory: about 99.08 megabytes
Free memory: about 15.42 megabytes
Total memory: about 114.50 megabytes
Total memory can expand to: about 873 megabytes
Number of processors/cores: 4
Compiler Discovery Log:

CYK:
What is the name of the Java interpreter?
What does IDE stand for?
What is the short name for 1,024 bytes?

Compiler filer, what’s your function?

John Sindayen