DOC PREVIEW
TRINITY CSCI 1321 - Java Basics

This preview shows page 1-2-3 out of 10 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 101Java Basics1/22/20082Opening Discussion■Let's look at solutions to the interclass problem.■What did we talk about last class?■Do you have any questions about the reading?What is the project that will be developed in the text?What are the main component to the game framework?3Code■We want to continue our bank example that we worked on last time in two ways.■First I want to have our bank make an account and try doing some things with it.■Second we want to add customer information. Instead of adding that straight to the account, we should create a Customer class and have the account reference it.■Let's put in proper documentation comments on the code as well.4More on Objects■There is no operator overloading in Java. You write and call normal methods instead.■Doing = or == with object references assigns or compares references. Think of them as pointers without the *.■Use a copy constructor to copy and equals() for value comparison.■No -> or * (deref) operator because things are implicitly dereferenced.5Garbage Collection■Java has automatic garbage collection. There is no delete operator (no free).■When you are done using an object and you have no more reachable references to it, the system can determine this and free up the memory for it.■As a result, you can allocate objects much more freely because you don’t have to worry about freeing them.6Arrays■Arrays in Java are actually objects. An array type is denoted by placing [] after the normal type. When you do a new you are allocating the array object. If the items in it are objects you still have to allocate the individual objects.■This is really nice for inclusion polymorphism.■You use them like you would in C/C++, though they do have a length member that you can access to find out how many elements are in an array.7Strings■Like arrays, strings are a class in Java, called String. Literal strings in Java are objects of that class too.■This class is in the java.lang package. Note that java.lang is the one package that is implicitly imported so you don’t have to use the import statement to refer to the classes in it directly.8Exceptions■Java tries to prevent sloppy error handling by providing exceptions instead of requiring programmers to check return codes.■try blocks surround code that might throw exceptions.■catch blocks follow a try block and specify what type it is waiting for.■finally catches everything and always happens.■If an exception type can be thrown but isn’t caught, it must be in the throws clause of that method. Not true for RuntimeExceptions.9Immutable Objects■In your reading you have inevitably come across the term immutable. What does this mean?■What are the advantages and pitfalls of immutability?■How can you write code that takes advantage of immutability?■The entire paradigm of functional languages is based on the idea that data is immutable.10Minute Essay■Do you have any significant questions about Java at this point? What do you see as the most significant differences between Java and C right now?■Interclass Problem – Write a class that represents rational numbers and do some code to test it


View Full Document

TRINITY CSCI 1321 - Java Basics

Documents in this Course
Recursion

Recursion

11 pages

Iterators

Iterators

10 pages

Actors

Actors

9 pages

Recursion

Recursion

15 pages

Recursion

Recursion

10 pages

Threads

Threads

7 pages

Trees

Trees

11 pages

Load more
Download Java Basics
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Java Basics and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Java Basics 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?