FIT9017: Week 11

With Week 11 being the last week for new topics to be introduced, Judy presented a lecture on Inheritance. I had read and worked through some inheritance tutorials previously but did not really grasp it with good clarity. Judy’s lecture did clarify a great deal.

Key advantages to inheritance:

  • Avoid code duplication
  • Re-use
  • Easier maintenance
  • Easier extendability

source: week 11 lecture notes

(more…)

FIT9017: Week 10

Week 10’s lecture by Judy started with an example of why code format convention are important if software is to be supported, extended, corrected, maintained, ported, adapted and re-used.

The focus then turned to 2 code important concepts of code quality:

  • Cohesion – Each component must contained related and well defined task, high cohesion is good.
  • Coupling – Each component must rely on as little data from other components as possible, low coupling is good.
    • Explicit Coupling – public Room northExit; (public fields should be changed to private and accessor/mutator methods added
    • Implicit Coupling – Call get/display methods instead of have 2 hard coded copies of information used in more than one class.
    • Not included was an explanation of normal coupling where a constuctor/mutator needs parameters.

Finally we covered some java commands from prompts for compiling and running:

  • compile:  javac class1.java
  • run: java class1
  • run jar: java -jar somthing.jar

We submitted our class diagrams and test strategies for Assignment 2 in the tutorial. I am lacking some understanding of the requirements for the test plan and how to present it so I will have to review this… there is not much info in the text book or lecture slides.

FIT9017: Week 9

Program, Design testing a program. We had some overlap this week with the Systems Analysis and Design subject as we looked at some program design methodologies.

New topics covered were:

  • CRC (class, responsibilities collaborators)
  • Testing strategy evolved from testing classes in isolation to testing use cases and scenarios

The tutorial was focused on giving us an idea of how to design our classes for assignment 2. I think the plans that we discussed were to simplistic however and there should be more classes than we covered in the program. The text book seems to have no section on this topic and I have found the index to be terrible… D:<

I will cut this post short as I need to finish the class diagrams for stage 1 of assignment 2 due tomorrow. Finding it a bit difficult as cohesion and coupling seem to work against each other in some instances.

FIT9017: Week 8

Judy returned to present lecture 8 this week, focussing on Encapsulation and Scope. The coverage of each aspect was quite introductory so I am just going to list through the points covered very breifly.

A graphic illustration of the encapsulation of Objects
  • Public Interface – public method and constructors are the objects/class’s interface
  • Encapsulation enables information hiding, a key point of object oriented development and code re-use
  • Local Variables – Scope limited to within a method
  • Field – attribute of an object, shoudl be private
  • Final – cannot be changed

Pearl of the Week:

  • Static vs Final – a good explination here

Short post this week, recently got Visual Studio 2010 so will look at trying out some C# in the next couple of weeks assuming I don’t get to addicted to SC2.

FIT9017: Week 7

This weeks lecture was once again presented by Michael Smith which was once again quite entertaining. The lecture was quite light with consideration given to the submission of the assignment at the start of the lecture. I was quite happy with the assignment, getting most of it done early and being able to consult with Michael on the solutions I had prepared. With some feedback from Michael I was then able to make some improvements and test them before the submission. This seems like it will be the necessary path for all assignments in this course as my failure to consult with the lecturer prior to handing in the Systems and Analysis Assignment 1a resulted in a mediocre mark for a very simple assignment.I suspect we will get the marks back in the first week of May.

In any case, the title of this weeks lecture was ‘Documentation, Identity, Equality and more Collections’. Covering the Java API and its presentation in Javadoc first off. As I learned the Javadoc notation when I first studied Java none of the ensuing slides where new.

Next came the equality  of Strings. Again this was one of the first important points mentioned in all Java text books. Basically using the arithmetic operator ‘==’ on two strings (or any objects for that matter) does not evaluate the content of the objects. Thus, if one wants to compare the state of two string objects string1.equals(string2) must be utilized. We spent some time discussing why this is the case, concluding that it the memory location that is compared when using the ‘==’ and that further ‘under the hood’ analysis was beyong the scope of this subject… o_o

We then looked at the immutable nature of Strings, which also applies to ArrayLists and other Collection objects that utilize Arrays.

Interfaces Implementations
Hash table Resizable array Tree Linked list Hash table + Linked list
Set HashSet TreeSet LinkedHashSet
List ArrayList LinkedList
Queue
Map HashMap TreeMap LinkedHashMap

Next came the most interesting part of the lecture.. HashMaps and HashSets (which also leads to other interfaces and implementations of Collections). I don’t have time right now to review all about collections but Michael gave me a great link: http://java.sun.com/docs/books/tutorial/collections/index.html which I will read thoroughly as from my limited experience strong knowledge on this topic is very valuable.

FIT9017: Week 6

A bit of a late entry for last weeks classes. The lecture was once again presented by Michael Smith and this week we ran through a number of Java (and programming) basics.

  • Library Classes – Java API, API documentation is generally the first google results when you search a method/data type + ‘JAVA’
  • Collections – Arrays and ArrayLists is a types of collection
  • Dynamic Arrays – called ‘ArrayList ‘ in Java (there may be other collections in Java? but ArrayList the only one I know of). Much better than arrays in that the size is dynamic and objects can be stored and all iteration and sorting is pretty much already optimized. Java’s for-each loop – for(Elementtype element : collection) – for (String note : noteBook)
  • Loops – Some types of loops in Java
    • for(i = 0; i < isbn.Length(); i++) {}
    • while (scanner.hasNext()) {}
    • do {} while (inChar != ‘X’);
    • for (String note : noteBook) {}

(more…)

FIT9017: Week 5

This weeks lecture was presented by Michael Smith and targeted an introduction to testing and debugging. Initially was discussed when testing should begin in the Software Development process, the Design phase. As soon as the solution has been designed then tests for that solution can and should also be designed. During the implementation phase testing should be conducted as soon as compilation is complete. Documentation was also recognized early in the lecture as a key aspect of testing and debugging.

Pearl Of The Week: Types of errors in Programs:

  • Syntax Errors -> Mistakes in spelling or unclosed parenthesis etc. Compiler will find these errors, preventing completion of compilation until they are amended.
  • Execution/Run Time Errors -> Null Pointer Exceptions, Attempting to access arrays outside of bounds. Occurrence of these errors in Java will result in relevant exceptions thrown.
  • Logic Errors -> Project has been compiled and runs without error but behavior is not as expected.

We then explored some examples of how important testing and debugging is by reviewing some examples where the process was not done correctly.

(more…)

FIT9017: Week 4

Week 4’s lecture by Judy got slightly deeper into the concept, design and implementation of objects. Again, I am finding that these lectures are moving very slowly and feel that prospective students should be given a chance (if they want) to demonstrate that they are not complete novices. However, this from an administrative point of view would probably be impossible and running through an introductory class will ensure that all the basic concepts (and more importantly, conventions) are clearly understood. So the only thing to do is get good marks and have a point to argue from for next semester.

The lecture started of defining the terms Abstraction and Modularization referencing their relevance to programming with a simple clock program. I felt this was valuable but could have been so much more valuable if we had gone a few steps further and show the practical applications for modularization and decoupling by making the clock program work and re-using the modules in different examples. In this example, Class Diagrams and Object Diagrams where covered (straight out of bluej).

Next came Primitive Types vs Object Types, specifically the differences in memory allocation (objects reference). I guess this will be a more interesting point when programming in C and the Garbage collector does not destroy unreferenced variables. Formal Parameters, Actual Arguments, Internal and External method calls followed, these were all consistent with what I have seen previously  and now feel very intuitive. The only point where I felt uncomfortable was where methods contained local variables with the same name as their Formal Parameters, necessitating the need for this.variable = variable notation. Seems much easier to me to avoid double naming.

The really key topic covered in the lecture and in the tutorials was the coding conventions: 70.40.214.44/Java_coding_standards.pdf

I need to update my existing habits to meet these standards (definitely a good thing).. means alot more indenting.

I will start reading through the text book more for this subject and continuing my own Java development. This should suffice until next semester or the 3rd when I hope we have the chance to do some challenging implementations.

Pearl of the Week: My first attempt at using Java Objects and a MySQL DB, hope to learn how wrong it is in the near future.[cc lang=”java”]
/**
Constructs a Book with bookID.
@param ID the Book ID number
*/
public Book(int ID)
throws SQLException, IOException, ClassNotFoundException
{
SimpleDataSource.init();
Connection conn = SimpleDataSource.getConnection();
try
{
java.sql.PreparedStatement
stat = conn.prepareStatement(“SELECT * FROM books WHERE book_ID = ?”);
stat.setInt(1, ID);
ResultSet rs = stat.executeQuery();
rs.next();
title = rs.getString(“title”);
author = rs.getString(“author”);
total = rs.getInt(“total_pages”);
current = rs.getInt(“current_page”);
path = rs.getString(“path”);
date = rs.getString(“date”);
genre = rs.getString(“genre”);
notes = rs.getString(“notes”);
}
finally
{
conn.close();
}
}
[/cc]

Haha there already a few bit there that are breaking format conventions already…. D:

Note, for some reason the code box is automatically removing indentation. The code box was made using a WordPress plugin: http://kpumuk.info/projects/wordpress-plugins/codecolorer/

FIT9017: Week 3

Judy Sheard’s third week lecture continued on the introduction to Java and programming as a whole. Although all of the concepts covered were very basic some of the terminology needs to be learned, particularly for when in the work place and the need to communicate arises. So, a summary of the terms covered and their contextual definitions:

  • Selection – if construct, 3 components: condition,consequent, alternative. if(keyword) (condition){consequent}else{alt}
  • relational operator –  ==, !=, <, >, <=, =>  result of these operators is a boolean TRUE/FALSE
  • boolean expression –  using one of the above operators.
  • compound statement – multiple lines in consequent block.
  • nested if – if within and if construct.
  • logical operators – !, && , || NOT, AND, OR can be used in conjunction with boolean expressions.
  • switch statement – can be used to neaten cascading if statements (compiles as cascading ifs however) ideal for day of the week statements etc. Can only be used with int and char expression evaluations.
  • shorthand arithmetic operators – a += 1; a -=1; a *=2; a /=3; a %=5; //reassign a with the result of the operators. a++; ++a; b–; –b; // if ++, — is after the variable then the arithmetic will be applied after the entire statement.
  • local variables –  variables within methods which exist only as long as the method is being executed.
  • base input –  using scanner method to read from keyboard

Precedence rule for evaluating expressions (JAVA):

  1. Parenthesis
  2. Unary Operators (++, –, !)
  3. Binary Arithmetic Operators (*, /, %, +, -)
  4. Relational Operators (<, >, <=, =>, ==, !=)
  5. Logical Operators ( &&, ||)
  6. Shorthand arithmetic ( =, +=, -=, *=, /=, %=) // these ones are evaluated right to left.

When in doubt of any of the above its much easier just to use parenthesis…

Pearl of the week: (I was always under the impression that a leap year is simple every 4th year, this is not the case however)

Algorithm for leap years:

Hope all banking systems have this correctly coded otherwise the 2100 bug might turn out to be more exciting than y2k.

The tut again was simply a revision of the lecture with the chance to ask question and get explanations. We are getting the assignment outline this week, Judy has said it is not really challenging…

FIT9017: Week 2

Today Judy Sheard continued the introduction to the Java language whilst maintaining a conceptual anchor. Having worked through several Java text books prior to starting the course I was already familiar with most of the terms and concepts but a little revision never hurts. The topics covered in the lecture:

  • Classes
  • Fields
  • Assignment
  • Expressions
  • Constructors
  • Methods
  • Parameters
  • Accessor/Mutator methods
  • Data types
  • Display Information
  • Visibility Modifiers

The tutorial included some revision of the material presented in the lecture and some references to the text book which no one brought. This was a bit annoying, why they could not list the questions instead of referencing seems irrational. Similarly the decision not to make available the lecture notes prior to the lecture so students can preview it is really odd…

Anyhow, as the lecture and tut were quite basic I had some time to work on my own project in which I identified a bug. A JTable which retrieves selected data from a MySQL table and then replaces it has a bug in the update function whereby a single array variable is dropped from the end of the first row. The bug must be either in the code pulling the values from the JTable into an Array variable or the code creating an SQL update Query from the Java array:

JTable -> Array variable code:
[cc lang=”java” line_numbers=”TRUE” width=”90%”]private void updateQuoteButtonMouseReleased(java.awt.event.MouseEvent evt) {
for (int a=0;a < qData.arrayRet().length;a++) { for (int b=0;b < 3;b++) { String cString = (String) quoteTable.getValueAt(a,b); qData.setArrayVal(a,b,cString); } } try { qData.updateBookDB(); this.qPop(Integer.parseInt(enterIDField.getText())); } catch (SQLException ex) { Logger.getLogger(BookPanel.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(BookPanel.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(BookPanel.class.getName()).log(Level.SEVERE, null, ex); } } [/cc] Array variable -> SQL UPDATE query code: [cc lang="java" line_numbers="TRUE" width="90%"]public void updateBookDB() throws SQLException, IOException, ClassNotFoundException { if (qArray.length == 0) { SimpleDataSource.init(); Connection conn = SimpleDataSource.getConnection(); try { java.sql.PreparedStatement stat2 = conn.prepareStatement ("DELETE FROM quotes WHERE book_ID = ?"); stat2.setInt(1, bookID); stat2.execute(); } finally { conn.close(); } } else { String SQLCmd = "INSERT INTO quotes values "; for (int a=0;a < (qArray.length - 1);a++) { SQLCmd = SQLCmd + "(" + bookID + ", 1, " + qArray[a][0] + ", '" + qArray[a][1] + "', '" + qArray[a][2] + "'),"; } SQLCmd = SQLCmd + "(" + bookID + ", 1, " + qArray[qArray.length - 1][0] + ", '" + qArray[qArray.length - 1][1] + "', '" + qArray[qArray.length - 1][2] + "');"; SimpleDataSource.init(); Connection conn = SimpleDataSource.getConnection(); try { java.sql.PreparedStatement stat2 = conn.prepareStatement ("DELETE FROM quotes WHERE book_ID = ?"); stat2.setInt(1, bookID); java.sql.PreparedStatement stat3 = conn.prepareStatement(SQLCmd); stat2.execute(); stat3.execute(); } finally { conn.close(); } } [/cc] After having a look at the code in notepad and being unable to find the bug. I will look for the error tomorrow night and see how long it takes me to find and fix. I won't open another of my own projects in BlueJ after it automatically renamed my Package declarations making errors throughout my source code.