Java Review - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Java Review

Description:

Java bytecode is not the machine ... http://java.sun.com/j2se/javadoc ... http://java.sun.com/j2se/1.5/docs/tooldocs/windows/javadoc.html. Java Style Specifics ... – PowerPoint PPT presentation

Number of Views:13
Avg rating:3.0/5.0
Slides: 19
Provided by: thomas49
Learn more at: http://www.mscs.mu.edu
Category:
Tags: com | java | review

less

Transcript and Presenter's Notes

Title: Java Review


1
Java Review
  • Outline
  • Java Primitives, Program Structure
  • Operators, Control Flow, Loops
  • Classes and Objects

Most of these slides are based on Intro to OOP
with Java text book by C. Thomas Wu
2
Java Translation
  • The Java compiler translates Java source code
    into a special representation called bytecode in
    the .class file
  • Java bytecode is not the machine language for any
    specific CPU
  • Another software tool, called an interpreter (in
    our case the Java Virtual Machine), executes the
    bytecode
  • Java is considered to be architecture-neutral
  • The Java compiler is not tied to any particular
    machine

3
Program Structure
// comments about the class
public class MyProgram

// comments about the method
public static void main (String args)

method header
method body
4
Arithmetic Operators
Intro to OOP with Java, C. Thomas Wu
5
Operator Precedence Rules
6
Syntax for the if Statement
if ( ltboolean expressiongt ) ltthen blockgt else
ltelse blockgt
Can be visualized as a flowchart
Indentation is important!
7
Comparing Objects
With primitive data types, we have only one way
to compare them, but with objects (reference data
type), we have two ways to compare them. We can
test whether two variables point to the same
object (use ), or We can test whether two
distinct objects have the same contents.
Sol They are not equal Discussion of some
string methods
8
Syntax for the switch Statement
switch ( ltarithmetic expressiongt ) ltcase label
1gt ltcase body 1gt ltcase label ngt ltcase
body ngt
9
Syntax for the while Statement
while ( ltboolean expressiongt ) ltstatementgt
10
Example Testing Input Data
String inputStr int age inputStr
JOptionPane.showInputDialog(null, "Your Age
(between 0 and 130)") age
Integer.parseInt(inputStr) while (age lt 0
age gt 130) JOptionPane.showMessageDialog(null,
"An invalid age was entered. Please try
again.") inputStr JOptionPane.showInputDialog
(null, "Your Age (between 0 and
130)") age Integer.parseInt(inputStr)
11
Syntax for the do-while Statement
do ltstatementgt while ( ltboolean expressiongt )
12
Syntax for the for Statement
for ( ltinitializationgt ltboolean expressiongt
ltincrementgt ) ltstatementgt
13
Defining a Class
Let us take a look at Bicycle.java, and
BicycleRegistration.java
14
Creating a Package
  • The following steps illustrate the process of
    creating a package name company that includes the
    Employee class.
  • 1. Include the statement
  • package company
  • as the first statement of the source file for
    the Employee class.
  • 2. The class declaration must include the
    visibility modifier public as
  • public class Employee
  • ...
  • 3. Create a folder named company, the same name
    as the package name. In Java, the package must
    have a one-to-one correspondence with the folder.
  • 4. Place the modified Employee class into the
    company folder and compile it.
  • 5. Modify the CLASSPATH environment variable to
    include the folder that contains the company
    folder.
  • 6. Include the statement import company. in the
    driver class EmployeePayRaise

15
Arrays of Primitive Data Types
  • What is an Array? Why do we need them?
  • Array Declaration
  • ltdata typegt ltvariablegt //variation 1
  • ltdata typegt ltvariablegt //variation 2
  • Array Creation
  • ltvariablegt new ltdata typegt ltsizegt
  • Example

16
Array Processing
17
Javadoc and Java Style
  • General information on javadoc is located at
  • http//java.sun.com/j2se/javadoc
  • Detailed reference on how to use javadoc on
    Windows is located at
  • http//java.sun.com/j2se/1.5/docs/tooldocs/windows
    /javadoc.html
  • Java Style Specifics
  • http//geosoft.no/development/javastyle.html

18
Javadoc (contd)
Write a Comment
User Comments (0)
About PowerShow.com