Computer Science Building, Princeton University


Introduction to CS


1.  A Simple Machine

2.  Java Programming

    • Hello World

    • Primitive Types

    • Conditionals, Loops

    • Input and Output

    • Arrays

    • Functions

    • Recursion

3.  OOP

4.  Data Structures

5.  A Computing Machine

6.  Building a Computer

7.  Theory of Computation

8.  Systems

9.  Scientific Computation

10.  Perspective


 Lecture Notes

Assignments

FAQ









2. ELEMENTS OF PROGRAMMING


Our goal. Our goal in this chapter is to convince you that writing a computer program is easier than writing a piece of text such as a paragraph or an essay. Writing prose is difficult: we spend many years in school to learn how to do it. By contrast, just a few building blocks suffice to take us into a world where we can harness the computer to help us solve all sorts of fascinating problems that would be otherwise unapproachable. In this chapter, we take you through these building blocks, get you started on programming in Java, and study a variety of interesting programs. Students who learn the programs in this book will have the solid foundation necessary to prepare them to be able to effectively use computers as they pursue any academic discipline.

What you will learn. You will learn the Java programming language, but that will be much easier to do than learning a foreign language that is unfamiliar to you. Indeed, programming languages are characterized by no more than a few dozen vocabulary words and rules of grammar. Most of the material that we cover in this chapter could apply to the C or C++ languages, or any of several other modern programming languages, but we describe everything specifically in Java so that you can get started creating and running programs right away. To the extent possible, we will focus on learning to program, as opposed to learning details about Java.