Categories
Foundations of Programming

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:

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);
}
}

Array variable -> SQL UPDATE query code:

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();
}
}

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.

Categories
Computer Technologies and O/S

FIT9018: Week 2

Andy Cheng today presented an Introduction to Operating Systems,  focusing on Unix and Unix like operating systems. This lecture was a bit short due to a time and room change. We also had to finish the previous weeks lecture with some further analysis into the steps a computer takes to process instructions. The operating system is best defined graphically (source: http://en.wikipedia.org/wiki/Operating_system <- also has a good amount of relevant details in the article):

Some key abilities of an O/S are:

  • Controls Hardware
  • Provides environment for other programs to run/compile
  • Controls CPU, memory and secondary memory allocation
  • Divides software into utilities and application depending on complexity

Modern operating systems can be defined as Multi-User and Multi-tasking (although this interrupts give the illusion of multitasking, the processor can only process one programs instruction at any given time.)

Running somewhat parallel to the abilities are, The Major Functions of an O/S:

  • Process Management(program/s in execution) -> creates and destroys processes, controls progress¬† of processes, acts on exceptions/interrupts (enables multitasking), allocating hardware to processes, providing inter process communication.
  • File Management -> controls transfer of data to and from secondary storage devices, controlling file access, provide sharing, keep track of space and locations of files.
  • Memory Management -> Primary memory (RAM), closely related to process management and assists in the illusion of multitasking. Modern O/S memory management should be non-contiguous logical objects to be disjointed and to enable virtual memory (incorporating secondary memory).

The rest of the lecture was a history of Unix and the evolution of O/S, a more detailed version of which can be found at: http://en.wikipedia.org/wiki/History_of_operating_systems

The tut comprised simply of installing ubuntu onto a flash disk from which we will be completing tasks from in the future. However the tut did contain the Pearl of the week:

When installing Ubuntu onto a flash disk you must go into advanced installation options at the review stage and change the boot sector installation to the Flash disk drive (it is not altered when choosing the Flash disk as the installation directory). Without this Ubuntu will not boot from a flash disk!