Chapter 1: Introduction to Computers and Java
Learning Objectives
After completion of this chapter, you should be able to
Explain why it is helpful to study computer programming
Learning how to program is more than just writing code. It is really about computational thinking. Computational thinking is hard to define, but at its core is
careful reasoning about methods of doing things. Another name for methods is algorithms.
Many consider computational thinking as a fundamental skill on par with reading, writing, and arithmetic.
Describe the early failures, successes and characteristics of the Java Programming Language
Java was designed by Sun Microsystems in the early 1990s develop a new technology for programming next generation smart appliances, which Sun expected to be a major new opportunity.
Java's Early Failures
- This smart appliance project failed because no one wanted to use Java to implement it.
- Java was redesigned to work with cable TV. This project also failed because the cable companies decided to choose a competing system.
Java's Success
- When the World Wide Web became popular in 1994, Sun began redesigning Java to work with the Web.
- In 1996 they released Java for the Web and it was an instant hit. The rest is history ...
- Java 1.0 - 212 classes in 8 packages, released May 1996
- Java 1.1 - 503 classes in 23 packages, released Feb. 1997
- Java 1.2 (Also known as Java 2) - 1,520 classes in 59 packages, Swing graphical API, released Dec 1998
- Java 1.3 - released May 2000
- Java 1.4 - released February 2002
- Java 5.0 - 3562 classes in 166 packages, released September 2004.
- Java 6.0 - Java SE 6 released December 2006
- Oracle purchases Sun Microsystems, 2009
- Java 7.0 - released July 2011
Java Characteristics
Java was successful, both because of Sun's persistence marketing, but also because there was a need for a language with its characteristics.
- Supports the Object-Oriented
(OO) programming methodology
- Platform Independence - allow the same program to be executed on multiple operating systems
- Built-in support for using computer networks
- Secure - it should execute code from remote sources safely
- Easy to learn and use by borrowing the good parts of older Object Oriented languages like C++
- Automatic Garbage Collection
- Supports International character sets through Unicode
- Free and disseminated over the Internet
Explain the difference between Java applications, Java applets, and JavaServer web pages
Java is used by programmers to write several types of applications
- Java Applets - runs in a browser
- JavaServer Pages - runs on a Web server
- Java Applications - runs on a desktop computer
Explain the steps involved in creating computer programs
We can view programs as a complete set of instructions (known as an algorithm) to accomplish some task.
The level of detail of the instructions depends ... (on a lot of things)
Know the difference between machine language, assembly language, and high-level programming languages.
There are four programming language levels
- Machine language (uses binary representation)
- Assembly language (CS 311 at Central)
- High-level languages
- COBOL, FORTRAN, Pascal, and C (procedural paradigm)
- Smalltalk, C++ and Java (object-oriented paradigm)
- LISP and Scheme (functional paradigm)
- Fourth-generation languages (database Structured Query Language SQL, Visual Basic controls)
Explain how abstraction relates to programming
The level of abstraction increases with each programming language level.
High-level programming languages allow programmers to write instructions at a high level of abstraction with less low-level detail.
Object-oriented (OO) languages allow programmers to add new abstractions to the programming language. This is similar to creating new words to stand for complicated concepts in English.
In Java, these new high-level abstractions are referred to as classes. When we use these high-level abstractions (classes) in programs, we call them objects.
Read and understand simple Java Programs
The Java Developers Kit (JDK) is a collection of free software available from Sun containing the Java compiler (javac.exe) and Java Virtual Machine (java.exe).
jGRASP is a programming editor and environment that allows you to type in your source code program, compile it using the Java compiler, and run it using the Java Virtual Machine.
jGRASP's toolbars and menus provide a convenient way to access the Java JDK. While, we could access the Java JDK through commands entered at a DOS prompt, combining editing, compiling, debugging, and execution into one integrated development environment (IDE) simplifies the process.
Recognize the elements common to all programming languages
Most programming languages share a set of common elements
- Key words
- Symbols, Operators, Punctuation
- Programmer-defined identifiers
Understand the elements in a simple Hello World Program
// My first program
public class HelloWorld
{
public static void main
(String[ ] args
)
{
String message
= "Hello World" ;
System.
out.
println( message
) ;
}
}
Understand the fundamental concepts of object-oriented programming
A programming language specifies the words, symbols and rules that we can use to write a program (the syntax).
Java Programs are object-oriented programs and
- consist of one or more classes (objects)
- Classes contain one or more methods
- Methods contain one or more program statements
- Statements consist of reserved words, symbols, values, variables
Read and understand an object-oriented sample Java class
public class Car
{
private double gallonsLeft
;
public void drive
( )
{
System.
out.
println ("Here I go ... HONK HONK ... You moron!");
gallonsLeft
= 0.0;
}
public void fillErUp
( )
{
gallonsLeft
= 24.5;
}
}
Explain the role of the Java compiler and Java Virtual Machine
The Java compiler translates Java source code into a special representation called bytecode. Java bytecode is not the same as machine language designed to run on a particular CPU, but a general low-level language designed to run on the Java Virtual Machine.
Another software tool, called the Java Virtual Machine, takes the Java bytecode and executes it on the particular computer.
Therefore, both the Java compiler and bytecode are not tied to any particular CPU or machine. We call this being architecturally-neutral. In theory, write-once and run everywhere: Platform independence
Prepare for Lab 1
Link to Lab 1