Download Computer Systems - Metcalfe County Schools

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Java: Chapter 1 Computer Systems
Computer Programming II
Aug. 2013
Why Java?
• A good question before we even begin looking at
the Java language.
The answer is that Java enables users to develop and deploy
applications on the Internet for servers, desktop computers,
and small hand-held devices. The future of computing is
being profoundly influenced by the Internet, and Java
promises to remain a big part of that future..

Java is a general purpose programming language.

Java is the Internet programming language.
What About Java?
• James Gosling and Sun Microsystems created and
distributed Java
• Java was released on May 20, 1995 as a free
program and has grown into one of the most
popular programming languages in the world.
• Java can be downloaded along with the
program(JCreator) we will use to work with Java
from free. Instructions can be found on my school
web page with links to the download sites.
Java a Problem Solver????
• The purpose of writing a program is to solve a
problem
• The general steps in problem solving are:
–
–
–
–
–
–
Understand the problem
Dissect the problem into manageable pieces
Design a solution
Consider alternatives to the solution and refine it
Implement the solution
Test the solution and fix any problems that exist
– Example You walk out to your car insert the key into
the ignition and nothing happens…Solve this problem
using the above steps.
Problem Solving
• Many projects fail because the
developer/repair person didn't really
understand the problem to be solved.
Java Program Structure
• As a class lets create your first java program which in
located on page 27 and is called the Lincoln program.
• To create the program open Jcreator(Start, Run,
Jcreator)
• Go to the file menu, select new,then project and click
on the Basic Java Application and click next.
• Name your program Lincoln and verify that the
location the program is saving is within your student
folder. Click on the … to browse and verify the path or
change locations.
• Now click the Finish button, you will end up clicking
the finish button twice.
Java Program Structure
• Using the program from page 27 in the Java
textbook enter the data shown in the book into
your java program. (Pay close attention to the
spelling, the case of the letters and where you are
typing the text).
• After finishing typing you are ready to see your
program work. To do this hit the F5 key or go to
the Run menu and select Run Project.
• Your output should appear at the bottom of the
screen. Or if an error has occurred the error code
will appear and point to potential problems.
Lets Create another program
• To practice our java programming skills lets use
the Lincoln program as a model and create a
program that displays that following…
• Name
• Address
• DOB
• Phone Number
• The program should be named Personal
Java vs. Visual Basic
• Create a program in visual basic that
displays the same output as the Lincoln
program that was just created in Java.
Remember in VB you will use labels and a
command button to make your program
work correctly.
Java vs. Visual Basic
• What are some of the similarities between
Java and Visual Basic?
• What are some of the differences between
Java and Visual Basic?
Main Parts of a Java Program
//
comments about the class
public class MyProgram
{
class header
class body
}
Comments can be placed almost anywhere,
comments are short descriptive statements
About your program or lines of code.
11
Main Parts of a Java Program
//
comments about the class
public class MyProgram
{
//
comments about the method
public static void main (String[] args)
{
method body
method header
}
}
Main Method
12
Comments
• Comments should be included to explain the purpose
of the program and describe processing steps
• They do not affect how a program works
• Java comments can take three forms:
// this comment runs to the end of the line
/*
this comment runs to the terminating
symbol, even across line breaks
/** this is a javadoc comment
*/
*/
13
Assignment
• Using the Lincoln program on page 27 as an
example design a program(You decide the name of
the program) that produces your favorite quote as
output and also tells who made the quote.
• Inside of your program insert comments that will
identify the following sections within your program
1) Main Method 3) Class Header 4)Class Body 5)
Method Header 6)Method Body
• Turn the printout of your code in for a 50 point
grade. Make sure your name is included.
Identifiers
• Identifiers are the words a programmer uses in a
program and can change from program to program
and programmer to programmer.
• Java is case sensitive(uppercase and lowercase
make words different) - Total, total, and
TOTAL are 3 different identifiers. In Visual Basic
they would all be the same identifier.
15
Identifiers
• Often we use special identifiers called
reserved words that already have a
predefined meaning in the language
• A reserved word cannot be used in any
other way
Reserved Words
• The Java reserved words(as found on page 31 of
the text):
abstract
boolean
break
byte
case
catch
char
class
const
continue
default
do
double
else
extends
false
final
finally
float
for
goto
if
implements
import
instanceof
int
interface
long
native
new
null
package
private
protected
public
return
short
static
strictfp
super
switch
synchronized
this
throw
throws
transient
true
try
void
volatile
while
17
White Space
• Spaces, blank lines, and tabs are called white
space
• White space is used to separate words and
symbols in a program
• Extra white space is ignored
• A valid Java program can be formatted in many
ways
• Programs should be formatted to enhance
readability, using consistent indentation
• See Lincoln2.java (page 33)
• See Lincoln3.java (page 34)
18
Basic Program Development
Edit and
save program
errors
errors
Compile program
Execute program and
evaluate results
Representing Color
• A black and white picture can be stored using one
bit per pixel (0 = white and 1 = black)
• A colored picture requires more information; there
are several techniques for representing colors
• For example, every color can be represented as a
mixture of the three additive primary colors Red,
Green, and Blue
• In Java, each color is represented by three
numbers between 0 and 255 that collectively are
called an RGB value
Coordinate Systems
• Each pixel can be identified using a twodimensional coordinate system
• When referring to a pixel in a Java program, we
use a coordinate system with the origin in the topleft corner to help place objects within the
computer screen area.
112
(0, 0)
X
40
(112, 40)
Y
End of the Chapter Challenge
Programs – 250 Points
• Complete the following programs found in the
Java Textbook on page 52-53.
• Programming Project 1.1 and 1.2, make sure
project 1.1 is working correctly before introducing
any errors. Write down the error message or why
the program worked.(50 points)
• Programming Projects 1.3,1.4, 1.5 and 1.6(50
points each)