TCU CoSc 10403 Introduction to Programming (with Java) - PowerPoint PPT Presentation

About This Presentation
Title:

TCU CoSc 10403 Introduction to Programming (with Java)

Description:

Introduction to Programming (with Java) ... (which are ignored by the compiler) ... Consider another simple HelloWorld program Syntax & Semantics Syntax ... – PowerPoint PPT presentation

Number of Views:95
Avg rating:3.0/5.0
Slides: 12
Provided by: Dr232014
Learn more at: http://csfaculty.tcu.edu
Category:

less

Transcript and Presenter's Notes

Title: TCU CoSc 10403 Introduction to Programming (with Java)


1
TCU CoSc 10403 Introduction to Programming (with
Java)
  • Java Language Overview

2
Consider another simple HelloWorld program
  • import javax.swing.
  • import java.awt.
  • /
  • Another HelloWorld program in Java
  • /
  • public class HelloWorld extends JApplet
  • JLabel helloLabel new JLabel ("How ya
    doing?")
  • public void init()
  • setLayout(new FlowLayout())
  • add (helloLabel)
  • helloLabel.setForeground (Color.RED)

3
Syntax Semantics
  • Note that the preceding program contained a
    variety of different symbols ,/().
  • These are delimiters (punctuation marks) in the
    language and must appear in particular places.
  • Similarly, note that there are words such as
    (class, public, extends, import,
    Applet) - these are reserved words in the
    language and must not be misspelled or written in
    the wrong context.

4
Syntax Semantics
  • The syntax of a language defines how you can put
    symbols, reserved words, and identifiers together
    to make a valid program.
  • During compilation, all syntax rules are
    checked.
  • If a program is not syntactically correct, the
    compiler gives error messages and wont produce
    the bytecode.
  • Syntax errors must be eliminated before the
    bytecodes are produced that allows us to try to
    execute the program.
  • The semantics of a language construct is the
    meaning of the construct it defines its role in
    a program
  • A syntactically correct program does not mean it
    is logically (semantically) correct.
  • A program will always do what it is told to do -
    not what the programmer meant to tell it to do.

5
Errors
  • A program may have three different types of
    errors.
  • Compile-time errors - errors with syntax (if
    compile-time errors exist, an executable version
    of the program is not created.
  • Run-time errors program compiles starts to
    excute and then crashes (terminates abnormally)
    (Example divide by zero).
  • Logical errors program compiles and
    executes.The program runs with no errors but
    produces incorrect results.

6
Problem Solving
  • Debugging finding and fixing errors in code
  • System.out.println prints to the console window
  • use System.out.println statements to see where
    you are in the programs execution or to display
    the value of variables
  • System.out.println( a )
  • System.out.println( x x )
  • These will display in the Console window at the
    bottom of the IDE

System.out.println information appears in the
Console window.
7
Coding Style
  • White Space
  • Spaces, blank lines, and tabs are collectively
    called white space and are used to separate
    words and symbols in a program
  • Extra white space is ignored
  • A valid Java program can be formatted many
    different ways
  • Programs should be formatted to enhance
    readability, using consistent indentation
  • Poor examples

Choose some style (mine, the Authors) and
stick with it!!!
8
Better Style
  • /
    /
  • / Program Name Lab 1 /
  • / /
  • / Student Name J.Q. Public /
  • / Semester Spring, 2004 /
  • / Class Section CoSc 10403 - 15 /
  • / Instructor Dr. James Comer /
  • / /
  • / Program Overview /
  • / This program displays a string of text in
    the center /
  • / of the applet window. The text is drawn in
    blue in /
  • / bold, 16 point Helvetica /
  • / /
  • / Input /
  • / There is no input to this program. /
  • / /
  • / Output /
  • / The string of text that is hard coded in
    the program. /
  • / /
  • White space consists of blanks, tabs, and newline
    characters.
  • White space is used to separate the words and
    symbols used in Java programs.
  • A programmer can use white space to emphasize
    parts of the program and to make the program
    easier to read.
  • Except when its used to separate words, the
    computer ignores white space.

9
Documentation
  • All programs are to be documented using the
    Documentation Guidelines and the Documentation
    Standard provided on the 10403 class website.
  • Failure to do so will result in several lost
    points on your graded lab assignment.
  • Comments should include a detailed preamble set
    of comments (see the standard) and inline
    documentation (to explain the purpose of the
    program and to describe processing steps). These
    are to be positioned within the executable
    statements of your program.
  • Java comments (which are ignored by the compiler)
    can take two forms
  • // comment runs to the end of the line
  • and
  • / The purpose of this program is ..
  • ../

10
Documentation Standard
  • /

    /
  • / Program Name Lab 3

    /
  • /

    /
  • / Student Name John Q. Programmer

    /
  • / Semester Fall, 1999

    /
  • / Class Section CoSc 10403 - 15

    /
  • / Instructor Dr. Hallie Pena

    /
  • / Due Date September 23, 1999

    /
  • /

    /
  • / Program Overview

    /
  • / This applet uses a text field to accept
    user input representing a Fahrenheit temperature.
    /
  • / When the user presses the ltenter keygt,
    the temperature is converted to Celsius. the
    /
  • / result is displayed in a label and, in
    addition, in a text area that serves as an
    ongoing /
  • / log of all conversions that have been
    performed. The user can continue to perform
    /
  • / terperature conversions until the applet
    is terminated.
    /
  • /

    /
  • / Input

    /
  • / Input data must be the integer Fahrenheit
    value that is to be converted to Celsius.
    /
  • /

    /

11
Terminology for the parts of a Java program
A java
program
consists of
classes
consist of
members (instances of the class)
are
fields
methods
are
variables
objects
void
typed
consist of
declared with
classes
types
fields
statements
constructors
inner classes
are
parameters
are
invocation assignment repetition selection excepti
on
are
special typed methods
fields
Write a Comment
User Comments (0)
About PowerShow.com