Computer Science 268: Introduction to Computer Programming (Java)
Study Guide
Unit 2
Read Chapter 2 of the textbook: Programming in the Small I: Names and Things
This chapter provides essential information on Java, introducing the building blocks of Java programs. This includes how to represent numbers and characters in Java and how to store values in a Java program. The chapter also discusses how information is represented in Java, introducing concepts such as objects, classes and subroutines. Furthermore, the chapter discusses ways to get information into and out of programs, and concludes with a discussion of Java programming environments.
Section 2.1 The Basic Java Application
This section discusses the overall look and construction of the Java application. Most Java programs are composed of the same building blocks formatted in the same way from program to program. Read this section and be sure to try the simple program examples.
Section 2.2 Variables and the Primitive Types
This section introduces variables, data types, literals (constant data values) and strings (groups of characters). The section ends with a discussion on how to best use variables in a program, and it concludes with an example you should try for yourself.
Read and review this section carefully.
- 2.2.1 Variables
- 2.2.2 Types
- 2.2.3 Literals
- 2.2.4 Strings and String Literals
- 2.2.5 Variables in Programs
Section 2.3 Strings, Classes, Objects, and Subroutines
This section begins with a discussion of some of the built-in functions you can call from within your own programs and includes an example you should try. The section then introduces classes and objects, and it discusses operations you can perform on strings. The section concludes with a discussion of the enumerated type (enum). Again, try the examples in this section.
Read and review this section carefully.
- 2.3.1 Built-in Subroutines and Functions
- 2.3.2 Classes and Objects
- 2.3.3 Operations on Strings
- 2.3.4 Introduction to Enums
Section 2.4 Text Input and Output
This section begins by discussing and demonstrating a classic Java print statement (System.out.println) and how it can be used to display output from your program. Subsections 2.4.2 through 2.4.5 discuss the textbook author’s own input–output (I/O) class called TextIO. Read these subsections to get a sense of what the author is trying to accomplish; however, you will not be asked to use the class in your programs. The final part of this section discusses a more conventional Java input mechanism, Scanner. We will be using Scanner in programs for this course. Therefore, try the example in this section.
Read and review subsections 2.4.1 and 2.4.6 carefully.
- 2.4.1 Basic Output and Formatted Output
- 2.4.2 A First Text Input Example
- 2.4.3 Basic TextIO Input Functions
- 2.4.4 Introduction to File I/O
- 2.4.5 Other TextIO Features
- 2.4.6 Using Scanner for Input
Section 2.5 Details of Expressions
This section discusses expressions, which are the basic building blocks of Java code, Java methods (subroutines), Java classes and objects and, ultimately, Java programs. The section discusses various operators that act on constants or variables to create expressions. Operators can be unary (acting on one thing) or binary (acting on two things). Operators can work with numbers or logic conditions. Assignment operators are used to assign the results of expressions to variables. Ultimately, there are rules that govern how operators are used, as well as which operations take precedence over (i.e., come before) other operations.
Read and review this section carefully.
- 2.5.1 Arithmetic Operators
- 2.5.2 Increment and Decrement
- 2.5.3 Relational Operators
- 2.5.4 Boolean Operators
- 2.5.5 Conditional Operator
- 2.5.6 Assignment Operators and Type Conversion
- 2.5.7 Precedence Rules
Section 2.6 Programming Environments
This last section of the chapter discusses programming environments. Subsection 2.6.1 discusses the essential Java environment, the Java Development Kit (JDK). All other Java environments employ the JDK to read and compile code. Some environments include the JDK, while others require you to download and install the JDK yourself. In this course, you will primarily use a standard Java SDK for exploring the Java concepts covered in this course. The environment you choose to use will depend on the computer operating system you have. The SDK can be installed and used on Windows, Unix, OSX (Macintosh) and Linux. All operating systems offer a form of “command shell” that can be used for compiling and executing Java programs. We will not be using or covering Eclipse, NetBeans or BlueJ in this course, but you may choose to use NetBeans rather than the command line environment for your course study and assignments.
For now you can skip subsections 2.6.3 through 2.6.8. However, when you are ready to start Assignment 4 you may wish to read the subsections on Eclipse and other programming environments.
Subsection 2.6.7 discusses packages and Java. We will use packages in Assignment 4.
Read and review subsections 2.6.1, 2.6.2 and 2.6.7 carefully.
- 2.6.1 Getting JDK and JavaFX
- 2.6.2 Command Line Environment
- 2.6.3 JavaFX on the Command Line
- 2.6.4 Eclipse IDE
- 2.6.5 Using JavaFX in Eclipse
- 2.6.6 BlueJ
- 2.6.7 The Problem of Packages
- 2.6.8 About jshell
It is a good practice to attempt the programming exercises in the textbook, to put the topics you have learned into concrete Java code. This, in turn, allows you to reflect on the material you have read. Skip any exercises relating to topics in Chapter 2 that are not covered in the course.
Resist the temptation to download the programming exercises from the textbook and simply run them. The greatest benefit in learning to program in a new language occurs when you type all the example code yourself.
Typing the code, even for simple examples, engages your brain in the process of writing code, compiling code, running code, and diagnosing and resolving problems that may arise. It is the latter skill—problem solving—that can become the most powerful tool in learning to program.
It is a good practice to review the chapter quizzes in the textbook, as the questions allow you to reflect on the material you have read.