Mihai's CS368-1 (Fall 1999):
Java for C++ Programmers

The Computer Science 368-1 course covers Java and is for students with previous C++ experience.
This page is not the main class page. The main class page used to be located at:

http://www.cs.wisc.edu/~cs368-1/SECTION1/cs368.html
Please refer to that page before asking any questions.

Below you will find questions and answers related to the on-line lessons, the homework, and the programming assignments. The questions are listed by date, with the most recent at the top. Please check the whole list of questions before contacting the TA or the professor. Thanks.

Mon Sep 20, 1999

Q:
How do I deallocate / delete objects?
A:
You don't, as Java does the deallocation for you. The Java Virtual Machine (the program you invoke with java) runs a process in parallel with your program, and this process (called Garbage Collector) checks for memory no longer in use in your program and automagically frees that memory.

For example, if you allocate a String inside a method, when the method terminates, the memory used by the String object will be freed. Similarly, when your program terminates, the List class will be deleted and so will all the Objects stored in the list.

For more details, check out the Cleaning Up Unused Objects in the Java Language Tutorial at http://java.sun.com/docs/books/tutorial/java/javaOO/garbagecollection.html.

Mon Sep 20, 1999

Q:
Do I need to catch exceptions in Program 2?
A:
No. Program 2 is a rewrite of Program 1 using linked lists. Program 1 did not have to handle exceptional cases (such as going beyond the end of the list with nextElement()), not does Program 2 have to.

Thu Sep 16, 1999

Q:
How do I convert an integer to a String?
A:
You can do it in at least two ways. Suppose s is declared as a String and i is of type int.
  1. s = new Integer( i ).toString(); // make i into an Integer object, then
                                     // use toString() on the object
             
  2. s = "" + i; // the addition forces i to be converted to a String
                // since we add an empty string ( "" ), the result
                // string contains just the integer value
             
If you know of more ways to do this, please let me know.

Thu Sep 2, 1999

Q:
I took some Computer Science classes a while ago. Now, whatever accounts I had there are expired. But in order to use the computers at CS for this course, I need to have a login... so what should I do?
A:
Your account with the CS department should have been reactivated. Try logging in to one of the machines in the CS labs.

If that does not work, or if you forgot your password, please go to the CSL office, 2350 Computer Sciences and Statistics, and have your account activated ASAP.

Copyright 1998-2005 Mihai Christodorescu. All rights reserved.
Maintained by Mihai Christodorescu (http://mihai.christodorescu.org).
Created: Mon Dec 21 21:12:13 PST 1998
Last modified: Sat Oct 1 23:06:19 CDT 2005