The following are the software tools, either required or recommended for this course.
Please read and follow the provided links:
- A. Java Links
- The latest version of the Java language is Java 8, but any version above Java 5 should be OK for Java Programming Homework.
Unfortunately, the latest version of Eclipse needs at least Java 7.
* My Java FAQs : it is tuned to what my students need!
* Java tutorials : an accessible online reference that should cover most of what we need.
* Java Supplements: downloadable supplements from Liang's book.
* Java 8 API's : it is official and comprehensive, but overwhelming and unwieldy!
- B. Eclipse Links
- Eclipse is an integrated development environment (IDE) that we will use for developing Java programs:
It has many features and can be overwhelming, so there are many tutorials available on the web.
* Video for your first eclipse project, or a downloadable supplement: both from Liang's book
* Eclipse help and Eclipse FAQs: courtesy of the Eclipse organization
* [30 Eclipse shortcuts] or [93 Eclipse shortcuts] : learn a few tricks!
Note: "control+" in Windows is "command+" in Mac !!
* My collection of Eclipse FAQs : informal collection of tips
- C. MAKE program
- Besides Java, you will learn a basic software tool to organize and test your programs.
This tool is called make (or variants such as gmake).
YOU MUST INSTALL A COPY OF "make" (or "gmake") on your computer.
(If you are in Windows, then you must install it though Cygwin.)
By default, this tool runs a program which you create, with default name Makefile. I have a simple introduction here:
* Tutorial and Notes on Make Program
In my classes, when you submit a program, I normally require you to include a README file plus a Makefile.
Here is a sample Makefile which you can modify and use (first rename it to "Makefile" before using):
* Makefile-hw1 (New!! Sep 4, 2015)
When you save this file, your browser may add the ".txt" extension to this file. Just rename it as "Makefile" without any extension. If you use an editor to edit this file some editors may also save it as "Makefile.txt". Again, rename it to plain "Makefile".
Some operating systems (Windows) may hide file extensions from your view -- I suggest you remove that feature to see all extensions.
Here are some fancier variants:
* sample Makefile based on src/bin directory structure
* fancy sample Makefile based on src/bin directory structure (new!! March 1)
Q1: How to get the make program? In the Mac world, you need to download Xcode (you will be asked to register as Apple Developer)and also download the command line tools. In the Windows world, I suggest downloading Cygwin which opens up all kinds of unix tools for your use as well.
Q2: How to pass multiple command line arguments (including string arguments) to a program from the terminal? E.g., suppose you have a target called run defined as follows:
java $(p) $(args)
So p is the name of the java program and args the command line arguments of the java program.In this example, myProg takes 2 command line arguments: the first is an int nn, the second a string pp. Now you can call this target at the terminal, and can override the default values as follows:
> make run args=111 \"./src/zoombinis\"
> make run nn=222
where you can freely override the default values of args or nn.
Q3: How to change a variable substitution depending on the specific target?
This is an important trick! But first understand what we want:
E.g., suppose you have two target called hw1 and hw2, and both share the same variable named nn. But say in target hw1 you want nn=111 but in target hw2 you want nn=222. To achieve this effect, you might try to define your targets this way:
java hw1 $(nn)
java hw2 $(nn)
I hope the intent of these two targets are clear.But they are incorrect. Reason: the assignments nn=111 and nn=333 are not allowed within a target. The solution is to ask the make program to do the variable substitution for you:
make run p=hw1 nn=111
make run p=hw2 nn=333
Interesting: your targets are recursively calling make! Of course, you should be careful that such recursive calls to make do not lead to infinite loops. Unfortunately, this solution does not allow you to override the default values of nn. To allow override of nn, you will need to do:
ifeq ($(p),hw1) nn=111 else ifeq ($(p),hw2) nn=222 endif endif
(of course this must be split across many lines). You combine this with these targets:
make hw1-helper p=hw1
java hw1 $(nn)
and similarly for hw2 and hw2-helper. Why this works is subtle!
- D. Cygwin for Windows World
- If you are in the Windows World, we strongly recommend installing cygwin, a free unix-like operating system.
Through cygwin, you can obtain make and all the standard unix tools. I provide a basic introduction here:
* Cygwin FAQs
* Cygwin Links and Introduction
It is easy to install (or uninstall), and does not require dual boot (so you can have both cygwin and Windows running at the same time).
- E. MacOS -- getting make program, etc
- Apple has a bad habit of not supporting non-Mac software. So if you have special problems on this score, we will try to help.
To get the "make" program, you used to have to register as a developer with Apple to download their IDE called Xcode. You should do that anyway, as it is free. But if you do not wish to register, since OS X 10.9 (Mavericks) you can get "make" and other useful unix tools without installing all of Xcode.
What you need to install is a section of Xcode called Command Line Tools.
For more information, see http://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x/.
What you get includes: make, GCC, clang, perl, svn, git, size, strip, strings, libtool, cpp, what, and many other useful commands that are usually found in default linux installations.
- F. Editors -- mostly gvim
- Editors are software for creating and editing text files. Technically, a text file is any file that contains only the standard ASCII characters. For example, your java program is a text file.
Most beginning computer users (if you are in the Windows world) are familiar with Microsoft's editor called Word or notepad.
But Word produces more than just "text" as it has all kinds of mark-ups, font choices (bold, italics, large size), etc.
It produces its own special file that is "text + extras". (E.g., .docx file is an example of a "text + extras" format). Such "extras" are not allowed in a Java file or a Makefile.
Many editors (like Word) are "WYSIWYG" (what-you-see-is-what-you-get). They are easy to learn, but beyond that, they must give you a load of menu choices and buttons. But all these slows you down. Real programmers seldom use such editors.
If you are new to non-WYSIWYG editors, I recommend an editor called gvim -- it belongs to vi family of editors.
Gvim is free, and is available on all platforms (on MacOS, it is called MacVim). If you want me to look at your code, you must download a copy of gvim before you see me.
Q1: How to invoke gvim/MacVim from the terminal:
In non-MacOS, it is easy: put a link from any folder in your PATH variable to the location where the gvim binary or executable is located. I like to use the path /usr/local/bin that is in most PATH. In MacOS, we mention 3 alternatives: (a) Downloaded a copy of MacVim. It is typically found in /Applications/MacVim.app/Contents/MacOS. You can call it to open any file named myFile by typing in your Terminal the following:
>> open -a MacVim myFile:
(b) Alternatively, after downloading MacVim, it may also contain a script file called mvim (I have put a copy of mvim in Piazza Resources). Copy mvim to the folder /usr/local/bin (you may need to first do a "sudo" and create this folder if it is not already there). Make mvim file executable (using the unix chmod command). This script file needs to know where your downloaded MacVim.app (or MacVim-snapshot-74/MacVim.app) is located). We recommend that you move these to /Applications. Then you must put this line into your .bash_profile file found in your home directory:
From now on, you can just invoke mvim from your terminal on any file
(c) A third suggestion is to use brew to install and automatically set up your macvim:
>> brew install macvim --with-override-system-vim
That will provide mvim, vim, vi, view, etc. in /usr/local/bin (all symlinked to the copy in the Cellar). This removes the need to create any aliases and also changes your vi, vim, etc. to all use the same Vim distribution as your MacVim.
Q2: How to customize gvim:
You need to have a file called .vimrc in your home directory. Here is a sample .vimrc file (click me) to start with.
Q3: I cannot find gvim on the web??:
Yes, most web search for gvim actually send you to a site for "vim". But the "vim" sites will have "gvim" because they are basically the same editor under the hood. The "g" in "gvim" refers to the GUI interface that is missing in "vim". Next, if you are a Mac user, then the version of "gvim" you need is called MacVim.
- G. Getting rid of unwanted .txt extensions
- This is an issue mostly on Microsoft Windows. Here is one site with this information:
There are two issues: first issue is that certain editors (such as Notepad) automatically add the .txt extension. Solution in Notepad is to put the file name in quotes, e.g., "myClass.java" will prevent Notepad from saving it as myClass.java.txt. The second issue is that Microsoft's Explorer has a habit of hiding file extensions (so you cannot see the .txt file extension).
The above link suggests that you go to the menu bar in Explorer, click ->Tools ->Folder Options, and in dialog box, click "View"to see a setting "Hide file extensions for known file types" and uncheck the box beside it to disable it. Finally click "Apply" and then "OK".
- H. Customizing your Terminal/Shell
- The terminal program is the most efficient way to interact with your computer.
If you are in Microsoft windows, I will assume that you use a Cygwin Terminal; MacOS comes with a Terminal program; on Unix-based OS, terminals is standard fare.
However, to use the terminal, you must use a special program called a shell program. There are many shell programs, variously called:
sh, csh, tcsh, ksh, bash (etc).
Most people probably has bash, and I will assume this. To customize the behavior of bash, you should create a file called .bash_profile (notice the name begins with a dot) and put it in your home directory (~). Here is a version of my .bash_profile file:
* sample .bash_profile
Use as is, or modify to suit your needs.
- Z. Pick Up Files