Before continuing further, I want to take time and clarify what the course expects you to come into the course ready to do. While most UVA students in this course will be coming from CS 2100, some people may be coming from other programming backgrounds.
This page is meant to briefly summarize what you are expected to know and be comfortable with in the Java programming language. This means both being able to read code and write code that uses the following tools and techniques.
if
, else
, and else if
switch
statements. Example:
public String getDayName(int dayIndex){
switch(day) {
case 0:
return "Sunday";
case 1:
return "Monday";
...
case 6:
return "Saturday";
default:
throw new IllegalDayException();
}
}
for
and while
loops
for(int i = 0; i < max_number; i++)
for(Student student : listOfStudents)
while(x > 0)
You should be very comfortable writing functions in Java, and understand:
You should be very comfortable with Java Classes
new
keywordstatic
keyword and what it meanspublic
and private
keywords.You should be familiar with:
interface
and implements
keywords
List
, Set
and Map
Comparable<E>
Comparator<E>
Runnable
extends
and abstract
keywordsObject
class
Object
class methods like equals(Object o)
, toString()
, and hashCode()
List<String> words = new ArrayList<>();
You should be familiar with:
IndexOutOfBoundsException
NullPointerException
IllegalArgumentException
ArithmeticException
IllegalStateException
ClassCastException
FileNotFoundException
IOException
Exception
try
-catch
-finally
blocksLook at this example Java code on Github. This code has 4 classes, which I encourage you to look at in this order:
You should be able to understand all of this code before we dive into our course material. This includes understanding what each class does and how each class interacts with each other.
You should be able to download these Java files, put them into a project in your IDE of choice, and run the Main.java program, and you should be able to understand why the output displays.
Note that, in your IDE, you’ll have to add the code to a package called “example”. This can be done by right-clicking on your source code folder (typically “src”) and going to New -> Package. Then, simply make a package called “example”, and drop the downloaded files in there. We will talk about packages, and why we have them, soon.
As we go further in the class, you’ll learn how to “clone” the Github Repository this code is in, as well as “build” it in order to run the code as is.