CS110- Lecture 2 Feb 2, 2005 Announcements

advertisement
CS110- Lecture 2
Feb 2, 2005

Announcements
•
•
•
•
No labs next week.
OWL ids are posted on course website and
default password is CS110.
Submit Prelab 1 and Lab report 1 along
with your Prelab 2.
Questions
6/30/2016
CS110-Spring 2005, Lecture 2
1
Agenda



OWL demo
Java programming
language
A Java program



Comments
Identifiers and
Reserved words
White Space

Program Development





Designing Programs


6/30/2016
Programming languages
Editors, Compilers and
Interpreters
Syntax and Semantics
Errors
Object Oriented
Programming
Problem solving
CS110-Spring 2005, Lecture 2
2
Java programming language


Program?
Programming language




Defines a set of rules
Java was developed in early 90’s
Undergone various changes.
Some parts have been deprecated.
6/30/2016
CS110-Spring 2005, Lecture 2
3
Java programming language

Java 2 platform is organized into:



J2SE: Provides a complete environment for
applications development on desktops and servers.
J2EE: Provides environment for developing,
deploying, integrating, and managing Web servicesenabled applications
J2ME: Provides an application environment for
applications running on consumer devices, such as
mobile phones, pagers, and TV set-top boxes, as
well as a broad range of embedded devices.
6/30/2016
CS110-Spring 2005, Lecture 2
4
Java programming language



Platform independent
Programs could be executed on the web (more
later)
Object oriented programming language




World around us is made up of objects (people,
automobiles, trees etc.)
Each object perform certain actions (methods) and
each action has some effect on other objects.
OOP views a program as similarly consisting of
objects.
Objects of the same kind are said to be in the same
class.
6/30/2016
CS110-Spring 2005, Lecture 2
5
Java programming language


Standard Class Library: Java is
accompanied by library of extra software
that we can use when developing
programs.
The J2SE application programming
interface (API) defines the prescribed
manner by which an application can use
the functionality available in the class
libraries.
6/30/2016
CS110-Spring 2005, Lecture 2
6
A Java Program

Lets write our first program




Name: Welcome.java
Consist of only one method (group of
programming statements). The name of the
method is main.
Program calls another method - println
All java applications have a main method.
6/30/2016
CS110-Spring 2005, Lecture 2
7
A Java Program: Comments




Don’t affect the output of program.
Language features that programmers use to
communicate thoughts.
Java files always start with comments.
Not a rule in the Java language, but a rule for us.

// text up to end of line is a comment
 /** special javadoc comment – more later
*/
 /* old style comment– rare */
6/30/2016
CS110-Spring 2005, Lecture 2
8
A Java Program: Identifiers
and Reserved Words

Identifiers – various words used when
writing programs



Words that we chose when writing a
program.
Words that another programmer chose.
Words that are reserved for special
purposes in the language (reserved words).
6/30/2016
CS110-Spring 2005, Lecture 2
9
A Java Program: Identifiers
and Reserved Words





An identifier that we make up for use in a
program can be composed of any
combinations of letters, digits, _ and $.
Cannot begin with digit.
Can be of any length.
Can use both lowercase and uppercase letters
Java is case sensitive (total, Total, TOTAL are
different).
6/30/2016
CS110-Spring 2005, Lecture 2
10
A Java Program: Identifiers
and Reserved Words


Using consistent case format for each
kind of identifier makes them easy to
understand (Coding conventions).
For e.g.: We use uppercase for the first
letter of each Word for class names.
6/30/2016
CS110-Spring 2005, Lecture 2
11
A Java Program: White Space




All java programs use white space to
separate the words and symbols.
White space consists of blanks, tabs
and newline characters.
It is used only to separate words.
You must adhere to particular
guidelines when you write your
programs.
6/30/2016
CS110-Spring 2005, Lecture 2
12
Program Development

Running a program involves certain
activities.



Write program in a particular language.
Translate into a form that computer can
understand.
Remove errors that may occur at various
stages.
6/30/2016
CS110-Spring 2005, Lecture 2
13
Program Development –
Programming Language levels




Machine Language
Low level
languages
Assembly Language
High Level Languages (designed for
people to use)
Fourth Generation Languages (e.g.: SQL)
6/30/2016
CS110-Spring 2005, Lecture 2
14
Program Development – Editors,
Compilers and Interpreters


Editor: Software tool used to type in
program and save it in a file.
Compiler:
Program in high
level language
(source code)
Compiler
Program in low
level language
(object code)
Translation process occurs once for
a program.
6/30/2016
CS110-Spring 2005, Lecture 2
15
Program Development – Editors,
Compilers and Interpreters



Interpreter: Interweaves the translation
and execution activities. A small part of
the source code is translated and
executed.
Advantage: No need for a separate
compilation phase.
Disadvantage: Slow because translation
process occurs during each execution.
6/30/2016
CS110-Spring 2005, Lecture 2
16
Java Byte Code

The process generally used to translate
and execute java program combines the
use of a compiler and interpreter.
Java program
Java compiler
Java bytecode
6/30/2016
Bytecode
interpreter
CS110-Spring 2005, Lecture 2
Machine
language
17
Java Byte Code



Bytecode is not the machine language for any
particular computer.
Bytecode is the machine language for a
hypothetical computer that is something like
the average of all the computers. This
hypothetical computer is called JVM.
Does it sound like bytecode just add an extra
step?
6/30/2016
CS110-Spring 2005, Lecture 2
18
Java Byte Code


Bytecode makes java architecture
neutral.
After you compile your program into
bytecode you can use that bytecode on
any computer. You do not need to
recompile it and you can send bytecode
over internet.
6/30/2016
CS110-Spring 2005, Lecture 2
19
Program Development –
Syntax and Semantics


The syntax rules of a language dictate
exactly how the vocabulary elements of
the language can be combined to form
statement.
The semantics of a statement in a
programming language defines what
will happen when that statement is
executed.
6/30/2016
CS110-Spring 2005, Lecture 2
20
Program Development –
Errors



Compile time error- compliers make sure that
you are using correct syntax. Any error
identified by the compiler is called a compile
time error.
Run time error- Occurs during program
execution.
Logical error-Program compiles and executes
without complaint but produces incorrect
results.
6/30/2016
CS110-Spring 2005, Lecture 2
21
Designing programs: Problem
solving





Understanding the problem
Designing a solution
Considering alternatives and refining
the solution
Implementing the solution
Testing the solution and fixing problems
6/30/2016
CS110-Spring 2005, Lecture 2
22
Object oriented programming



The (software) world consists of objects
Each object is an instance of a class
An object has



fields that describe what it looks like (its state)
methods that describe how it behaves
One object sends a message to another
asking it to use one of its methods to do
some work
6/30/2016
CS110-Spring 2005, Lecture 2
23
Download