Introduction to Java
• Learn about expressions and types int , double , boolean , and String.
• Learn about declarations of variables and assignments to them.
• Learn the basics of object-oriented programming.
• Learn how to use classes from the Java API.
• Learn the importance of good style.
The first section of this chapter deals with the evaluation of expressions in Java.
Here is an example of an expression: 3+5 . Java expressions differ slightly in
some respects from the math expressions you have seen. We hope that you will
immediately get on your computer, practice writing expressions, and see how the
computer evaluates them. Practicing on the computer with each topic will give
you a fluency in Java programming that is otherwise hard to come by. Appendix
I outlines how you can do this on your own computer.
The second section introduce the concept of a variable , which can be viewed
simply as a box into which a value can be stored, and how variables are used in
The major part of this chapter is an introduction to object-oriented program-
ming in Java, which will give you an understanding of the class as a fundamen-
tal mechanism for organizing and structuring programs. Interestingly enough, the
concept of classes was not even taught twenty years ago; today, we do not know
what we would do without it.
You will soon see that good programming style is important. Consistently
using a simple style that lets you see the structure of your program gives you a
chance to write correct programs. Not following a good style almost always leads
to chaos in your program and a consequent waste of time trying to write it, under-
stand it, and get it correct.