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

Friday, January 30, 2015

JAVA INHERITANCE

Java Inheritance

October 2014. About this time, I already bought an Asus computer from Fry’s because I was going to need it to study for the MCSA Configuring Windows 8.1 Exam 687. I bought it for less than a public junior college semester course.

As you might know already, unless you don’t read technical web pages, Windows 8.1 is going to be off the market soon and so will its derivate Windows 9. Microsoft is churning out Windows 10 instead.

Windows 8 could not compete with its predecessor Windows 7's likeability. Among the flaws of Windows 8 I have encountered is that the tile environment is separated from the desktop environment. For example, if you log in to a WiFi in the desktop environment, you need to log in again in the tile environment. However, it seems that this flaw might have been corrected by a Windows 8 update.

Currently, I am taking an Advanced Java class and we are studying Java inheritance. Java allows only single inheritance, but you can simulate multiple inheritance using interfaces.

Here’s a Java program that shows constructor chaining in an inheritance.

public class Bird extends Pterodactyl {
  public String toString() {
    return "I am a bird.";
  }
  public static void main(String[] args) {
    Bird bird = new Bird();
    System.out.println(bird.toString());
  }
}

class LivingThings {
  public LivingThings() {
    System.out.print("I am a living thing. ");
  }
}

class Animals extends LivingThings {
  public Animals() {
    System.out.print("I am an animal. ");
  }
}

class Dinosaurs extends Animals {
  public Dinosaurs() {
    System.out.print("I am a dinosaur. ");
  }
}

class Pterodactyl extends Dinosaurs {
  public Pterodactyl() {
    System.out.print("I am a pterodactyl. ");
  }
}

Here is the console run and output of the above program.
> run Bird
I am a living thing. I am an animal. I am a dinosaur. I am a pterodactyl. I am a bird.
>

CYK:
What keyword is use to create instances in Java?
What keyword is use to call the superclass constructor or superclass method?
What’s the new paradigm that is replacing the swing package GUI capability?

Look up in the sky! It's a bird! ...

John Sindayen

Reference:
http://java67.blogspot.com/2012/12/how-constructor-chaining-works-in-java.html

Tuesday, January 27, 2015

BRANCH & LOOP

BRANCH & LOOP

September 2014. I’ve been looking at the job requirements for programmers at this time.

A lot of the jobs required applicants to know a lot of computer languages. For example, one job requires knowing C#, Visual Basic, HTML, CSS, and SQL also. Another job would require knowing C or C++, Java, JavaScript, PHP, HTML, and SQL.

So I decided to learn at least ten computer languages, both programming and web scripting languages, along with RDBMS languages. I decided to have knowledge of these languages: Java, C, C++, C#, VB.Net, Python, JavaScript, PHP, HTML, CSS, and SQL.

In the meantime, here’s a program of the list of the syntaxes or examples of the entire programming world’s selection and loop statements. If somebody invents a new one, he or she will be instamatically famous.

class Instamatic {
  public static void main(String[] args) {
    boolean boolean_expression = true;
    String variable;
    String expression1 = "constant1";
    String expression2 = "constant2";
    String[] array = new String[100];

    if (boolean_expression) {
      //Statements
    }

    if (boolean_expression) {
      //Statements
    }
    else {
      //Statements
    }
   
    variable = boolean_expression ? expression1 : expression2;
   
    if (boolean_expression) {
      //Statements
    }
    else if (boolean_expression) {
      //Statements
    }
    else {
      //Statements
    }
   
    switch (variable) {
      case "constant1":
        //Statements
        break;
      case "constant2":
        //Statements
        break;
      default:
        //Statements
        break;
    }
   
    //Statements
    while (boolean_expression) {
      //Statements
    }
   
    //Statements
    do {
      //Statements
    } while (boolean_expression);
   
    for (int i = 0; i < 100; i++) {
      //Statements
    }
   
    for (String element : array) {
      //Statements
    }

  }
}

CYK:
How do you encapsulate a data field?
What kind of token follows the case keyword in C and C++?
What Java data type uses 4 bytes but has no precision?

Loop before you leap!

John Sindayen

References:
https://msdn.microsoft.com/en-us/library/aa292164(v=vs.71).aspx
http://www.dba-oracle.com/t_grid_rac_rdbms_language.htm
http://www.engineersblogsite.com/what-is-node-branch-and-loop-in-a-circuit.html
http://en.wikipedia.org/wiki/Significant_figures

Saturday, January 24, 2015

VARIABLE TYPE

VARIABLE TYPE FOR DATA TYPE

August 2014. About this time, a student needed some tutoring in C. I have not taken a C programming class before and I did not want to take one since C is a subset of C++. I would rather learn C by myself than pay a $300 semester course for C.

I looked at the student’s C program that was not working and tried to debug it. Since I have taken Advanced C++ already, it was not hard to decipher C’s heavy use of pointers or to debug his program. Without pointers C could not do any input and output operations at all.

The concept of variable data type started with C. This is why C is the most successful programming language ever in existence. It’s success is exemplified by all the other languages that adapted its style, particularly C++, Java, Visual Basic, and C#, and by all the popular operating systems of today that uses it, specifically Windows, Mac OS, Linux, and Unix.

Strictly speaking, JavaScript, PHP and Python does not have variable data types as defined in C, C++, C#, Java, SQL and Visual Basic programming languages. HTML and CSS has no variable data type, by definition of variable.

This is the list of primitive data types used by variables in many languages. These data types are particular to Java. All, except byte and boolean, are derived from C and C++.

This program is written in Python, for simplicity.

#Python program that prints the primitive type and their ranges.
print(" boolean range:  true to false                                          ")
print(" char range   :  all original Unicode characters including ASCII        ")
print(" byte range   :  -128 to 127                                            ")
print(" short range  :  -32768 to 32767 or +/- 32K                             ")
print(" int range    :  -2147483648 to 2147483647 or +/- 2 billion             ")
print(" long range   :  -9223372036854775808l to 9223372036854775807L          ")
print("                 or +/- 9 billion billion dollars                       ")
print(" float range  :  1.40129846432481707e-45f to 3.40282346638528860e+38F   ")
print(" double range :  4.94065645841246544e-324d to 1.79769313486231570e+308D ")

C and C++ also has signed and unsigned data types.
C# and VB also has Decimal data type and VB has Single data type.

CYK:
What Java primitive data type is not in C++?
What primitive data type cannot be cast to another data type in Java?
What does a local variable do to a global variable of the same name?

Happy data typing!

John Sindayen

References:
https://msdn.microsoft.com/en-us/library/47zceaw7.aspx
http://zetcode.com/lang/python/datatypes/
http://www.w3schools.com/js/js_datatypes.asp
http://php.net/manual/en/language.types.php
http://zetcode.com/lang/csharp/datatypes/
http://www.tutorialspoint.com/plsql/plsql_data_types.htm
http://www.tizag.com/sqlTutorial/sqlcreate.php
http://stackoverflow.com/questions/7247202/how-to-use-variable-in-css
http://www.w3.org/TR/html4/types.html
http://www.cplusplus.com/doc/tutorial/variables/