CMSI 2120: Welcome to Week 01

WELCOME!!

Today, the first day of the semester, will be a pretty typical 'first day of class'. We'll cover the course syllabus, then take a brief tour of the course website so you'll know where to find your project, reading, and homework assignment information.

If time remains, the rest of the class [or the second class meeting for the two-a-week section] we will begin to look at some of the fundamental concepts of database systems and the associated theory.


The Grand Tour

First things first:

A little welcome message…

First we need to cover the basics, since fundamentals are critical to success in anything!

Helpful Links and Programming Information

Textbook links

Note that in the Lafore book, there are some sections that are done using Java Applets. These are not used any longer, and in fact, most browsers prohibit them entirely for security reasons. You can safely ignore anything in the book that says do this in the blahblahblah applet, but don't just ignore the whole thing – there are concepts that are involved that you will need, and the book [which is a bit dated, that's why it's free for you to USE] implemented examples that way. It does NOT mean there is nothing contained in those examples that is important to know.

And don't worry, I'll tell you what sections to skip in the reading assignments.

Tools you will use during the semester

Initial roll call and other sundries

And now for the dreaded pariah of all classes, the tell-the-professor-all-about-me excercise, which is guaranteed to have you all shifting uneasily in your seats! So, tell me a little about yourself, including:

Assignment Submissions

Homework assignments for this class will be done in pairs. For each assignment, you and your partner will turn in ONE copy of the assignment. Assignments are mixed, with exercises consisting of both programming projects and short answer questions. As many of you may have heard, I'm a big believer in fostering critical thinking skills, so there will be questions that are intended to make you think about what you are doing in various respects like morals, ethics, and decomposition of problem statements.

All homework will be submitted in GitHub. Please get an account if you don't already have one, and make a repository for this class. NOTE: because the assignments will be done in pairs, you will need a single account for your pair. If you WANT to make two accounts you are welcome to do so, but please be sure that I know which account will be the one that you are using for the submissions.

You can call your repo whatever you like, but it would be helpful to have the phrase "CMSI281" in the name somehow. Under the repository, please generate the following FOLDER structure:

  1. Classwork
    1. Classwork01
    2. Classwork02
    3. Classwork03
    4. Classwork04
    5. Classwork05
    6. Classwork06
    7. [etc...]
  2. Homework
    1. Homework01
    2. Homework02
    3. Homework03
    4. Homework04
    5. Homework05

I will be using this folder structure to perform the evaluations of your work. I use the GitHub desktop on my Windows machine to duplicate your repo locally for doing those evaluations, and I have several scripts that I set up to facilitate compiling and running your programs and projects. Any deviations from the above structure means my scripts will not work with your submissions, so you will NOT get credit. IF YOU NEED HELP GETTING THIS SET UP, PLEASE ASK ME OR ONE OF YOUR CLASSMATES to assist you.

Additionally, CODE THAT DOES NOT COMPILE WILL NOT BE EVALUATED. PERIOD. The time for submitting code with compile errors is past with the passing of CMSI 185/186. In those cases, I had a nominal policy of correcting compile errors if there were only one or two obvious ones. I will NOT be doing that in this class, so make sure it compiles before you turn it in.

REMEMBER: I use the command line for compiling and running. If you are using an IDE like NetBeans or Eclipse, be sure your program can be successfully compiled from the command line, and that it runs that way as well. It's an extra step for some of you, yes, but this reflects the real world of software development – just because it works for you in Eclipse doesn't mean that the USERS who run your code will be running it from Eclipse, if they even HAVE Eclipse. Most of your users will think Eclipse is that thing that happens in the sky.

Java vs. JavaScript vs. Python

OK, let's state the obvious up front: JAVA IS NOT JAVASCRIPT. If you had me for CMSI 185 or CMSI 186 [or anything else] you should realize this already. Professor Forney has a little saying on his website: Java is to JavaScript as Car is to Carpet. …or something like that.

What's Your Interpretation?

The point is, despite the similarity in the names, they are two very different animals. JavaScript is an interpreted language, which means that the computer [actually the JavaScript interpreter that is RUNNING on the computer] interprets each line of JavaScript code, one-at-a-time, turning it into the executable code [bit patterns] that the machine can actually execute. The same thing goes for Python ~ interprested language, meaning there is an engine of some sort that actually runs your code.

On the other hand, Java is a compiled language, which means you have to run a software tool called a compiler on your source code to translate it BEFORE you can run it.

Actually, it's even a bit more complicated than that, because the Java compiler translates the source code into what is known as byte code, which is not really runnable on the hardware processor of your computer either. Instead, there is a program called the Java Virtual Machine, or JVM, which is sort of like a layer on top of the operating system of your computer that will run the Java byte code. It is the JVM that interprets the byte code into what the computer CPU/GPU can actually execute. Most of the time, you don't care about this, and your USERS certainly won't give a fig. But it IS an important distinction…

We'll see this again in a week or so.

So, We Need a Type-righter……

Apart from being compiled vs. interpreted, Java is a statically-typed language, while JavaScript and Python are dynamically-typed languages. This means that in JavaScript or in Python, you can define a variable horse that has the string Trigger in it, then three lines later you can set the value of horse to be 37, and the JavaScript or the Python interpreter will happily handle that for you. However, with Java, you must define horse to have a specific data type, like String, and it will forever after [in THAT program] be of the String data type – you can never put a number in it, because it will be an error.

Something that the languages have in common, although they implement things differently, is the idea of OBJECTS. An object is essentially a user-defined, complex data type. We'll see more of THAT later, too.

Examples:

   # Python code, dynamically typed
   myString = "This is a string in the Python Language."
   primeNumber = 23                       # this is a 'number' data type in JavaScript
   myAmount = 234.56                      # this is ALSO a 'number' data type
   myString = 23                          # this is NOT an error!! [Dynamic typing]
            

Start up your Python interpreter and enter the above code to see what happens!

   // JavaScript code, dynamically typed
   var myString = "This is also a string in the JavaScript Language.";
   var primeNumber = 23;                  // this is a 'number' data type in JavaScript
   var myAmount = 234.56;                 // this is ALSO a 'number' data type
   myString = 23;                         // this is NOT an error!! [Dynamic typing]
            

Enter the above JavaScript code in the Script Runner to see what happens there.

   // Java code, statically typed
   class Tester {
      String myString = "This is also a string in the Java Language.";
      int primeNumber = 23;                  // this is a 'primitive' data type, an 'integer'
      double myAmount = 234.56;              // this is a 'primitive' data type, a double-precision number
      myString = 23;                         // this is an ERROR!!  [Static typing]
   }
            

Try typing the Java code into a file, then compile it [or check your editor marks] to see the error. You can also try typing it into the Java Tio.run page to see what happens there.

Beginning Java

So, since we are going to *USE* Java…

So that all the sections of this class can get the same introduction to the Java Language [as well as to Data Structures in general], Dr. Toal, our LMU resident programming language 'mystic chef and guru' has put together several REALLY GOOD web pages to introduce the Java language. We'll be using them for the first few weeks of this course to augment our learning experience! Here is the first one, called Getting Started with Java!

OK, so what *IS* a data type, anywho?

The definition, in the context of the Java language, is a classification of some program entity which has specific properties and responds to, or incorporates, specific operations and/or behaviors. There are two basic types of data in Java [for want of a better descriptive word], the primitive data types, and the user-defined data type.

OK then, what is a CLASS? [Encapsulation]

So, within that context, a CLASS is a user-defined data type, which can be used as a sort of template to make objects of that class. It is a named collection of things that can hold data, and things that can operate on that data.

There is really a LOT more to it than this, but for brevity's sake I'm reducing it to the bare bones; you should probably read the sections in the textbook and in the Java In a Nutshell book, a copy of which can be found in my GitHub repo.

The fact that classes define data and the behaviors that can operate on that data leads to the idea of encapsulation, also known as data hiding. The basic idea is that the programmer defines the data in the class, and then also defines the operations for that data, which allows her to have complete control over how that data is accessed. If everything is private to the class, only the methods within that class may access the data directly; any other object will have to call some method [a gettor or settor] to access the data.

Here is an example:

  /**
   * A simple Java Class file example
   * @author Professor Johnson
   * @version 1.0.0
   */
   public class Sample {
      private String myString = "This is a string in the Java Language.";
      private int primeNumber = 23;          // 'primitive' data type, an 'integer'
      public  double myAmount = 234.56;      // 'primitive' data type, a double-precision number

     /**
      * Constructor
      * @param value String to set in the myString field
      */
      public Sample( String value) {
         myString = new String( value );
      }

     /**
      * Method to reset the "myAmount" field value
      * @param newAmount double precision value to set the field to
      * @return the integer value that is the reset amount
      public double resetAmount( double newAmount ) {
         myAmount = newAmount;
         return myAmount;
      }
     /**
      * Method to determine if a number is prime
      * @param value an integer which is potentially a prime number
      * @return boolean value, true if the value passed is prime, false if not
      public boolean isPrime( int value ) {
         boolean result = false;
         // some code that determines prime-ity
         return result;
      }
   }
            

In-class Assignment #1

This assignment is to make sure you have your environment working, so you are ready for the rest of the semester. It is perfectly OK to ask your classmates for assistance if you get stuck and I am busy helping someone else.

You will need to do the following to produce your first program for this session:

  1. Install the Java Development Kit on your computer if you haven't already done so
  2. Install a text editor or IDE on your computer if you haven't already done so
  3. Create a bookmark in your favorite browser to the Java API pages if you haven't already done so; the link for Java 15 is here
  4. Create a file called SayHello.java in a directory of your choosing by whatever method you are comfortable with
  5. Edit the file and create a program that will simply print Hello, World! to the console using System.out.println().
  6. Compile and run your program to make sure everything works.
  7. Add to your program to prompt the user to input their name from the console using the Scanner class. Don't forget you will need to import from java.util.Scanner at the top of your source file. You can then use the following two lines in your file to create a scanner object and read the user's input:
       Scanner myInput = new Scanner( System.in );
       String inputName = myInput.nextLine();
                        
  8. Add more lines to your program to prompt the user to enter a name; you can use the System.out.println() method to display the text; this should come BEFORE you use the Scanner object to read the user input from the keyboard
  9. Add more lines to your program to change the Hello, World! message to say Hello, followed by the name that the user has input. For example, if the user enters Bozo, your program should output Hello, Bozo! Don't forget to add the exclamation point at the end!
  10. Compile and run your program to make sure everything works.
  11. Test your program with several different inputs, like dog, $237.19, and just pressing Enter without entering anything. See if you can break your program!
  12. Go to GitHub and set up your repo and submission structure if you haven't already done so.
  13. Upload and commit your completed SayHello.java file to your repo
  14. Pat yourself on the back for a job well done! [Just don't hurt yourself…]

NOW FOR PART TWO!!!

Homework Assignment #1

I know this isn't due for a while, but i wanted to give you a heads-up on the homework assignments that you will be doing this semester. They are all available from the syllabus page, but just to make sure …

Week One Wrap-up

That's probably enough for the first week. Be sure to check out the links to the related materials that are listed on the class links page. Also, don't forget the project page!



I hear, and I forget.
I see, and I remember.
I do, and I understand.
Ancient Chinese Proverb