Frequently Asked Questions
This document contains answers to some frequency (and infrequently) asked questions.
When will the textbook be published? The first four chapters are published as an Introduction to Programming in Java: An Interdisciplinary Approach by Addison Wesley. If you're a faculty member considering adoption, please fill out the form from the booksite homepage.
Why Java? Why not C or C++ or C# or Python or Ruby or Matlab? The program that we are writing are very similar to their counterparts in several other languages, so our choice of language is not crucial. We use Java because it is widely available, widely used, embraces a full set of modern abstractions, and has a variety of automatic checks for mistakes in programs, so it works well for students learning to program. There is no perfect language and you certainly will find yourself programming in other languages in the future.
Do I need previous programming experience? No, this textbook starts from the beginning. If you have prior programming experience, you can move through Chapter 1 at a more rapid pace, but you are likely to find the examples worthy of careful study.
Do I need any special math or science background? No, we assume only a basic high school background. Our approachreinforces and takes advantage of students' preparation in high-school math and science as they learn programming.
Are there solutions to all of the exercises? No, we've linked to the ones we have written. Feel free to contribute to the community and submit a solution to one of the exercises.
I'm an instructor. Can I use your material for my class? If you adopt the book, you are free to use and adapt any of the material for your needs. Otherwise, please email the authors to request permission.
How can I contact the authors? Email Kevin Wayne.
Which textbook do you recommend for CS 2 course? We highly recommend the companion textbook Algorithms, 4th Edition.
What version of Java are you using? Java 1.5 (aka Java 5.0) or newer. We use some Java 1.5 features (formatted output, generics, autoboxing). that are not available in earlier versions.
Who designed Java? James Gosling. Here is an interview, where he discusses some of the thoughts that went into including and not including certain features of Java.
Is there an official specification of the Java language? Yes, but it's quite technical. Here is the Java Language and Virtual Machine Specifications.
Where can I find documentation for the Java libraries? Here is documentation for all Java 1.5 classes. As you become a more proficient Java programmer, this will become an essential reference.
Can you recommend a good intermediate-level book on Java? Check out Oracle's online Java Tutorial for an introduction to advanced Java features not covered in our textbook. Joshua Bloch's Effective Java is a "must-read" for any intermediate to advanced Java programmer.
I've programmed in C before. Can you offer any help on transitioning? Here's a comparison table.
Is there a good integrated development environment for novices? We recommend Dr. Java. More sophisticated IDEs, such as Eclipse, are overkill for an intro course, but are widely used by professional programmers.
Should I use a debugger? Reasonable people disagree on this one. Our preference is not to use a debugger when first learning to program.
My program runs out of memory, but my system should have more than enough. What's going on? The java heap is the area of RAM reserved for use by the Java virtual machine. You can specifically ask for more (assuming your system has enough) with the following command:
% java -Xmx300m -Xms300m PrimeSieve N
In this case, we are asking for 300MB of memory. The -Xmx sets the maximum heap size, the -Xms flag sets the initial heap size.
My program runs gives me the error message StackOverflowError. What could be wrong? Typically, this is because you have a recursive function that goes into an infinite loop. It could also be caused by a deeply nested recursive function like Sum.java. You can ask for more stack space with
% java -Xss10m Sum N
However, on Windows XP this does not appear to work, and is a documented bug. If you have a work-a-round, we'd be happy to hear about it.
Can I compile by .java file directly into machine language instead of Java bytecode? Yes, if you have gcj type one of the following at the command prompt
% gcj --main=HelloWorld HelloWorld.java % gcj --main=HelloWorld HelloWorld.class
This will create an executable named a.out or HelloWorld.exe depending on your operating system. You can then run the program by typing a.out or HelloWorld instead of java HelloWorld.
How do I set the classpath? The classpath is an environment variable which javac and java use to find the location of any needed .class files. This would enable you to put StdDraw.class, StdIn.class, and other commonly used libraries and they would always be available. By default, the classpath is the current working directory. If your classpath has already been set, you may need to change it to make it include the current working directory. Here's a wealth of classpath info. It can be rather confusing.
How do I play an MP3 file in Java? Here are some instructions on playing an MP3 file in Java.
When I compile with javac it says that one of the methods I use is deprecated. What does that mean? A deprecated method is method that was supported in older versions of Java, but is now obsolete. You should use the suggested replacement method instead, since the deprecated method may not be supported in future versions of Java.
Does the Java compiler always know to recompile dependent files as needed? Usually, but not always. Be careful with final static constants for primitive types and Strings.
How does Java compare in terms of speed to C or C++? To Perl or Python? The answer depends greatly on the type of application you're running. As a rule of thumb, Java's performance is good, C and C++ are blazingly fast, and Perl/Python are slow. This article claims that Java is comparable to C for scientific applications involving number crunching. No benchmark is perfect, but The Computer Language Shootout Benchmarks is a good starting point.
Are there are common pitfalls that I should be aware of? Here's a worthwhile list of common Java gotchas.
Does Java have pointers? Java doesn't have raw pointers like C or C++, but it has references which are almost as powerful, but much safer. Here's a good summary of the differences. The Java Virtual Machine itself can implement references with pointers (for raw speed) or with handles (for more flexible memory management).
Can I write AJAX applications like Google Maps and Gmail in Java? Yes, check out the Google Web Toolkit.
How can I use Java to control another application and pass it native system input events (e.g., take control of the mouse and keyboard), e.g., for automatic testing or demos? Use Java's Robot class. Richard G. Baldwin has a good tutorial ( part 1, part 2, and part 3).
Is it possible to crash the Java Virtual Machine? Yes. Program Bug.java consistently crashes the JVM on a variety of operating systems.
The program links contain syntax-highlighted versions of the code. How was this accomplished? We use GNU source-highlight to automatically produce the syntax-highlighted versions.
How did you create the equations? We used Latex and this TeX to PNG converter.
How did you create the screen output drawings in the textbook? We used our standard drawing library described in the textbook.
I want to be able to publish reference solutions
on the Web, but don't want my students to be able to
decompile them. What can I do?
Java bytecode obfuscator.