C01new
-
Upload
nazmi-aziz -
Category
Documents
-
view
222 -
download
0
Transcript of C01new
-
7/27/2019 C01new
1/14
Chapter 1Introduction
Java Software Solutions
Foundations of Pro ram Desi n
Copyright 2012 Pearson Education, Inc.
Seventh Edition
John Lewis
William Loftus
-
7/27/2019 C01new
2/14
Introduction
Chapter 1 focuses on: an introduction to Java
Copyright 2012 Pearson Education, Inc.
-
7/27/2019 C01new
3/14
Outline
The Java Programming Language
Copyright 2012 Pearson Education, Inc.
-
7/27/2019 C01new
4/14
Java
The Java programming language was created bySun Microsystems, Inc.
It was introduced in 1995 and it's popularity hasgrown quickly since
programm ng anguagespec es e wor s ansymbols that we can use to write a program
A programming language employs a set of rules
that dictate how the words and symbols can be puttogether to form valid program statements
Copyright 2012 Pearson Education, Inc.
-
7/27/2019 C01new
5/14
Java Program Structure
In the Java programming language: A program is made up of one or more classes
A class contains one or more methods A method contains program statements
the course
A Java application always contains a method
called main
See Lincoln.java
Copyright 2012 Pearson Education, Inc.
-
7/27/2019 C01new
6/14
//********************************************************************
// Lincoln.java Author: Lewis/Loftus
//
// Demonstrates the basic structure of a Java application.
//********************************************************************
public class Lincoln
{
//-----------------------------------------------------------------
// Prints a presidential quote.
-----------------------------------------------------------------
Copyright 2012 Pearson Education, Inc.
public static voidmain (String[] args){
System.out.println ("A quote by Abraham Lincoln:");
System.out.println ("Whatever you are, be a good one.");
}
}
-
7/27/2019 C01new
7/14
//********************************************************************
// Lincoln.java Author: Lewis/Loftus
//
// Demonstrates the basic structure of a Java application.
//********************************************************************
public class Lincoln
{
//-----------------------------------------------------------------
// Prints a presidential quote.
-----------------------------------------------------------------
OutputA quote by Abraham Lincoln:
Whatever you are, be a good one.
Copyright 2012 Pearson Education, Inc.
public static voidmain (String[] args){
System.out.println ("A quote by Abraham Lincoln:");
System.out.println ("Whatever you are, be a good one.");
}
}
-
7/27/2019 C01new
8/14
Java Program Structure
public class MyProgram
{
// comments about the class
class headerclass headerclass headerclass header
}
class bodyclass bodyclass bodyclass body
Comments can be placed almost anywhereComments can be placed almost anywhereComments can be placed almost anywhereComments can be placed almost anywhere
Copyright 2012 Pearson Education, Inc.
-
7/27/2019 C01new
9/14
Java Program Structure
public class MyProgram
{
// comments about the class
public static void main (String[] args)
// comments about the method
}
{
}
method headermethod headermethod headermethod headermethod bodymethod bodymethod bodymethod body
Copyright 2012 Pearson Education, Inc.
-
7/27/2019 C01new
10/14
Comments
Comments should be included to explain thepurpose of the program and describe processing
steps They do not affect how a program works
ava commen s can a e ree orms:
// this comment runs to the end of the line
/* this comment runs to the terminatingsymbol, even across line breaks */
/** this is a javadoc comment */
Copyright 2012 Pearson Education, Inc.
-
7/27/2019 C01new
11/14
Identifiers
Identifiersare the "words" in a program
A Java identifier can be made up of letters, digits,
the underscore character ( _ ), and the dollar sign
Identifiers cannot begin with a digit
ava s case sens ve: Total, total, anTOTAL are different identifiers
By convention, programmers use different case
styles for different types of identifiers, such as title casefor class names - Lincoln
upper casefor constants - MAXIMUM
Copyright 2012 Pearson Education, Inc.
-
7/27/2019 C01new
12/14
Identifiers
Sometimes the programmer chooses theidentifer(such as Lincoln)
Sometimes we are using another programmer'scode, so we use the identifiers that he or shechose (such as println)
Often we use special identifiers called reservedwordsthat already have a predefined meaning inthe language
A reserved word cannot be used in any other way
Copyright 2012 Pearson Education, Inc.
-
7/27/2019 C01new
13/14
Reserved Words
The Java reserved words:
abstract
assert
boolean
break
byte
else
enum
extends
false
final
interface
long
native
new
null
switch
synchronized
this
throw
throws
casecatch
char
class
const
continuedefault
do
double
finallyfloat
for
goto
if
implementsimport
instanceof
int
packageprivate
protected
public
return
shortstatic
strictfp
super
transienttrue
try
void
volatile
while
Copyright 2012 Pearson Education, Inc.
-
7/27/2019 C01new
14/14
Summary
Chapter 1 focused on: an introduction to Java
Copyright 2012 Pearson Education, Inc.