Home : Course Map : Chapter 2 : Java
Chapter 2 : Java Essentials
JavaTech
Course Map
Chapter 2

Introduction
Essentials
Structure

Keywords
Primitive Types
Comments
Literals
Expressions
Operators
Statements
Casts & Mixing
Strings
Console Output 
   Demo
Exercises

    Supplements
Conditional: if-else
Repetitions
Flow Control

Java vs C/C++
JVM Instructions 1

     About JavaTech
     Codes List
     Exercises
     Feedback
     References
     Resources
     Tips
     Topic Index
     Course Guide
     What's New

If you buy one of those do-it-yourself furniture kits, the best way to start is just to dump all of those screws, nuts, planks, widgets and tools on the floor, group them into piles of similar looking things, and then go read the first page of the instructions.

Even though you don't know what all of those things do, it helps to pick them up, look them over, and group them into similar looking piles so that you become familiar with them and can recognize them in the instructions.

In this chapter we dump out all the basic pieces of Java so you can become familiar with them. However, you don't need to understand yet what every single piece does. That will become clear come as we proceed through the rest of the course and as you practice by writing lots of programs.

We begin with a listing of the basic elements and then outline the structure of a generic program.

We proceed through the individual elements of the language beginning with the Java reserved words, or keywords. We then discuss the basic data types in Java called primitives. These are used in expressions and with various operators to make up statements.

After this introduction to the basic elements, we next start to look at how to use them.

Casts & Mixing section gives rules on mixing data types in an expression and how to cast, that is "convert", from a wider data type down to a more narrow type, e.g. a long to a int.

Every program, even short ones, should include plenty of comments to allow not only other users to understand how your programs work but also to allow yourself to understand them when you come back to them at a later time. So a section on commenting code is included.

Although more details will be given on them later, to allow you to start writing programs as soon as possible, brief discussions of strings, and console I/O are given. Then a basic application demo is presented before the exercises.

This chapter includes:

  • Elements - overview of the various parts of the Java language.
  • Structure - the layout of a generic program or class.
  • Keywords & Symbols - words & symbols reserved for the Java compiler.
  • Primitive Types - the basic data types.
  • Comments - how to put comments into the Java code.
  • Expressions - elemental operations that return a value.
  • Operators - all the operations defined in Java.
  • Statements - a complete "sentence" in the code.
  • Casts & Mixing - how to deal with expressions with a mix of primitive types.
  • Strings - character strings in Java are part of the core language.
  • Print Output - a simple way to send output to the command line.
    • Demo - an applet & an application (a standalone program) to demonstrate how to send output to the console..
  • Exercises

The topics are mostly in a tutorial format but for some sections, such as the operators and primitives, additional material such as tables and specifications are provided for later reference.

As discussed in the previous chapter, for the example and exercise codes you can use the Starter programs that we provide. In these programs you can just stick code segments into the designated areas and then compile and run them. For now you don't need to understand class, objects, and other complexities to start programming. Later, the starter programs will just provide convenient templates in which to begin coding.

Note: Java syntax has much in common with C/C++. However, there are also many differences. See a comparison of Java vs C/C++.

Latest update: Oct. 15, 2004

            Tech
Arithmetic Ops
Math Class
More on Integers
FP : Overview
FP : Java  
  
Demo 1
More Mix/Cast
  Demo 2
Exercises

           Physics
Differential Eq.
Euler Method
  
Demo 1
Predictor-Corrector
  
Demo 2
Exercises

  Part I Part II Part III
Java Core 1  2  3  4  5  6  7  8  9  10  11  12 13 14 15 16 17
18 19 20
21
22 23 24
Supplements

1  2  3  4  5  6  7  8  9  10  11  12

Tech 1  2  3  4  5  6  7  8  9  10  11  12
Physics 1  2  3  4  5  6  7  8  9  10  11  12

Java is a trademark of Sun Microsystems, Inc.