To Lecture Notes
IT 313 -- Jan 6, 2020
Is IT 313 the Right Course for You?
- IT 313 is a third programming course.
- The official prereqs for IT 313 are IT 211 and IT 212.
- However, if you have taken a different two quarter programming sequence in a high level language such as
Ruby, Python, C#, or C++ you are qualified to take IT 313.
- You are underqualified for IT 313 if you have only taken one high level programming course.
- You are overqualified for IT 313 if you have taken a data
structures course in Java, such as CSC 300.
- The textbook for this class, Big Java, Late Objects by Cay Horstmann, is required.
- Use the optional textbook if you are interested in the details of software design patterns:
Head First Design Patterns by Freeman and Freeman, O'Reilly, 2004.
Course Website
Announcements Lecture Notes Documents Projects Exam Info
Prof Info Syllabus
Review Quiz
- What are these datatypes?
integer floating point character string boolean
Ans: Here is a table showing the Python and Java primitive datatypes. The
numbers in parentheses are the number of bytes needed to represent that datatype
in the Java Virtual Machine.
Meaning | Python | Java |
Integer | int (unlimited) | byte
(1) short (2) int (4) long (8) |
Floating Point | float (8) | float
(4) double (8) |
Character | | char (2) |
Character String | str (4 or 8 byte
reference variable) |
String (4 or 8 byte reference variable) |
Logical | bool (1) |
boolean (1) |
An integer value is a whole number: positive, negative, or zero. For example:
834564, -5348372, or
0.
By default, Java int variables are between -2 billion and 2 billion.
A floating point value is a number with a decimal point and optional exponent. E.g.:
5.342, -6.3372, 0.0,
3.4356e11
(means 3.456 × 1011).
A character constant is a single unicode character. E.g.:
'W', '5', '$'.
We will see how to represent non-keyboard unicode characters later.
Strictly speaking, Java can only deal with 2-byte Unicode characters. Chinese has so many characters,
that 4 bytes are needed to represent all of them.
Java character constants always use single quotes.
A string constant is a sequence of zero or more characters:
"dog", "elephant",
"12345", "!@#$%^&*()",
"" (empty string).
A boolean constant is either true or
false.
- List the Python operators that you know. Most of these also work as Java operators. Ans:
Arithmetic: + - * / %
String Concatenation: +
Comparison: < > <= >= == !=
Logical: && || ^ !
Bitwise: & | ^ ~
Assignment: ++ -- += -= *=
/= %= &= |= ^=
Array Lookup: [ ]
Grouping, Function Invocation: ( )
Tertiary Conditional Operator: ?
Member Access: .
The ? operator is also called the Elvis operator, because it looks like
Elvis Presley's hair when turned sideways.
See Horstman, page 866 for an operator precedence table.
- Name some common control structures. Ans:
Python: if..else, if..elif..else, while, for.
Java: if..else, if..else if..else, switch, while, do..while, for.
- Give some plausable examples of objects in the sense of object oriented programming. Ans:
Person Student Pet BasketballPlayer Transaction CatalogItem Automobile
Working with Java
- Understand three components to effectively use Java:
- Object oriented programming (OOP),
- A modern editor such as IntelliJ,
- The application programming interfaces (API) in the Java Class Library
The HelloWorld Example
Install Java 11 and IntelliJ IDEA on your computer. See the Announcements Page for links.
Important: install version 11 on your machine to be
compatible with the version of Java in the classroom and in the labs.
Standard IO
- Standard IO means reading from the keyboard and writing to the computer screen
in a Command Prompt Window (Windows) or Terminal Window (Unix or Linux, e.g., on
a Mac).
- The keyboard and computer screen together are called the console.
- Here is a summary of the three standard IO streams:
Index | Name | Java Object |
Physical Device | IntelliJ Color in Output Window | Redirection Symbol |
0 | stdin | System.in | Keyboard |
Green |
< |
1 | stdout | System.out | Screen |
Black |
> |
2 | stderr | System.err | Screen* |
Red |
2> |
*But not redirected even if Standard Out is redirected.
Redirection
Redirect Standard Out and Standard Err:
> java Greeter1 > greeting.txt 2> prompt.txt
Steve
> type greeting.txt
Hello, Steve, how are you?
> type prompt.txt
Enter your name:
Redirect Standard Out, Standard Err, and Standard In:
> type name.txt
Steve
> java Greeter1 < name.txt > greeting.txt 2> prompt.txt
> type greeting.txt
Hello, Steve, how are you?
> type prompt.txt
Enter your name:
Redirect Standard Err to same file as Standard Out:
> java Greeter1 > greeting.txt 2>&1
Steve
> type greeting.txt
Enter your name: Hello, Steve, how are you?
2>&1 means redirect Standard Err to the file
in argument 1 (&1), which is greeting.txt
Eclipse does not directly support
IO redirection. Read from or write to files directly instead.
IntelliJ Editor
- We are using the IntelliJ Editor for this course. The Java projects that you submit must be IntelliJ projects.
- IntelliJ is considered to be a more modern editor than Eclipse.
- Here are two documents that show how to create simple IntelliJ projects:
- IntelliJ has many key-combination shortcuts that allow experienced Java programmers to write Java source code very quickly.
You don't need to learn all these shortcuts for this class. However, there are two shortcuts that you will
probably want to start using immediately:
- Control-S: Save all.
- Alt-Enter: Show intention actions and quick fixes.
- Here are other shortcuts on this IntelliJ Default Keymap
page if you are interested.
Project 1