Thursday, September 4, 2008

Java fundamentals

I covered a few things about Java and recommend two sources about Java for C++ programmers:

I mentioned that my most common error coming to Java from C++ is in declaring variables:

TrafficLight tLight;

In both languages, this declares a variable named tLight. In C++, the variable is of type TrafficLight and the instance is initialized by a constructor. In Java, the variable is of type reference to TrafficLight and is initialized to null. To create an actual object, use

TrafficLight tLight = new TraffcLight();

Some other points I made:

  • One public class is defined in a file. The class Foo must be defined in file foo.java.
  • Classes are organized into packages. All the classes in a package must be in a directory that has the name of the package.
  • A Java source file is compiled using javac, the Java compiler. The output of the compiler is a class file—e.g., Foo.class.
  • A Java program is run using the Java Virtual Machine (JVM) via the java command. The class method having the signature public static void main(String args[]); is invoked as the starting point of a program.
  • A Java program is usually a collection of packages and classes that are stored together in a Java archive (.jar) file. [In fact, Netbeans stores the classes for each project in a separate .jar file.]

We went to the lab and I tried, anyway, to introduce you to regular expressions. We had trouble using the NetBeans edtor, but it worked in vim. Regular-Expressions.info seems chock full of info about regular expressions.

Tuesday, September 2, 2008

Getting started

We went over the course syllabus today and I talked about what compilers are and our plans for the semester. The first part of the plan is a Java spike—you need to learn some Java. I have assigned a set of programs that should help you learn enough Java for us to get started on coding a compiler. You may work in a team of two or three for these projects as long as all the team members are present for the coding and debugging. You will get no benefit from letting others do the coding for you because you will be responsible for implementing your own Bantam Java compiler in Java.

Homework

Read the introduction to the Bantam Java Compiler Project Lab Manual, pages 1–7.

Project

Implement the following programs in Java using NetBeans,which is installed on the computers in Olin 227 Lab. Each program should be implemented as a separate NetBeans project. For grading, submit an archive of the project folder. Submit the projects as you complete them. All projects are due no later than Monday, September 15.

Sunday, August 24, 2008

Welcome!

Welcome to COSC 481! This will a busy, but very interesting semester. Implementing a compiler draws on many areas of computer science, including data structures, theory of computation, computer architecture, algorithms, and operating systems. After implementing a compiler successfully, "very few aspets of computer programming seem like magic." [see Marc L. Corliss and E Christopher Lewis, Bantam Java Compiler Project Lab Manual, Extended Version 1.2.]

I am looking forward to a successful and fun semester.

Homework

Homework assignments will be called out like this.

Project

Project assignments will be called out like this.