33
POS406 Emilio Yanine

POS406 Emilio Yanine. Welcome Syllabus Course overview: POS406 Vs. PRG420 Attendance Policy Review OLN forums (Flexnet): email Vs Forum Participation

Embed Size (px)

Citation preview

POS406

Emilio Yanine

Welcome Syllabus

Course overview: POS406 Vs. PRG420 Attendance Policy Review OLN forums (Flexnet): email Vs Forum Participation expectations Grading Breaks/Hours Laptops for class activities Web site

Books Java Programming: Comprehensive Concepts and Techniques

The Java SDK and Textpad Team formation

Team charter Review Team Project

Programming Languages

Why do we need to program? What problems are suitable for a

programmatic solution? What problems are not suitable to a

programmatic solution

History of Programming Languages First Generation (Machine Language)

Late 1940’s (after WWII)

Second Generation (Assembly) Early 1950’s

Third Generation (High level/structured) Late 1950’s Ex: FORTRAN (1957), COBOL (1959)

Fourth Generation (Object Oriented) Mid 1980’s Ex: C++ (1985), Java (1995), VBasic (1992)

1GL Characteristics

100% machine dependent (not portable) Very tedious to program Very difficult to debug Complete control of hardware

(fast/efficient)

1GL Hello Program

00401010 55 8B EC 83 EC 40 53 00401017 56 57 8D 7D C0 B9 10 0040101E 00 00 00 B8 CC CC CC 00401025 CC F3 AB 68 1C 00 42 0040102C 00 E8 2E 00 00 00 83 00401033 C4 04 33 C0 5F 5E 5B 0040103A 83 C4 40 3B EC E8 9C 00401041 00 00 00 8B E5 5D C3 00401048 CC CC CC CC CC CC CC

2GL Characteristics Easier to read

Uses instructions mnemonics Very fast (compared to high level lang’s.)

High performance drivers still written in assembly

Unsuitable for large programs No structure or advanced constructs

Machine/CPU dependent

2GL “Hello” Program1: // test.cpp : Defines the entry point

for the console application.2: //3:4: #include "stdafx.h"5:6: int main(int argc, char* argv[])7: {00401010 push ebp00401011 mov ebp,esp00401013 sub esp,40h00401016 push ebx00401017 push esi00401018 push edi00401019 lea edi,[ebp-40h]0040101C mov ecx,10h00401021 mov eax,0CCCCCCCCh00401026 rep stos dword ptr [edi]

8: printf("Hello World!\n");00401028 push offset string "Hello World!\n" (0042001c)0040102D call printf (00401060)00401032 add esp,49: return 0;00401035 xor eax,eax10: }00401037 pop edi00401038 pop esi00401039 pop ebx0040103A add esp,40h0040103D cmp ebp,esp0040103F call __chkesp (004010e0)00401044 mov esp,ebp00401046 pop ebp00401047 ret

3GL Characteristics

Easier to program large projectsAdded code structure added (functions, loops,

conditional statements and branching. Cornerstone is the procedure (function)

Known as “procedural” languagesData is secondary and separate from code

Portable code independent of cpu (only partially true)

3GL “Hello” Program (C lang.)

#include "stdafx.h"

int main()

{

printf("Hello World!\n");

return 0;

}

4GL Characteristics

More intuitive approach to programming Idea is to model problems using “Objects”

Code and data “encapsulated” into Objects Supports advanced OOP constructs

Classes, inheritance, aggregation, etc.

“Hello” Program in Java

public class Hello {

public static void main(String args[])

{

System.out.println("Hello World!\n");

} //end main

} //end class Hello

Java History

Derived from C++ Developed at Sun Microsystems in 1991

Initially called project “Green” Market target was smart appliances such

microwaves, refrigerators. When the WWW popularity exploded in

1993, Java’s potential was quickly realized

Why Java

SecurityJava runtime engine monitors instructions as

they are interpreted an executed Truly platform independent

Universal API Simpler syntax

No PointersNo Multiple Inheritance

Program Development Environments

(Software Development Tools)

Compilers/IDE

Modern software development environments are highly integrated tools that provide the essential functions necessary to develop programs. These include: Text editor to type programs commands Compiler to convert to machine language Linker to link in libraries and other modules Debugger to help catch semantic (logic) errors

Compile & Link

Run(Test)

Edit

Program Build Cycle

Text Editor Compiler Linker Debugger

MyFile.c

(C code)

MyFile.obj

(intermediate binary)

Built in libraries and other program modules

MyFile.exe

(Executable prog.)

Text Editor Java Compiler

MyFile.java

(java code)

MyFile.class

(Executable program)Run Application

Java Interpreter(Virtual Machine)

Java Program Build Cycle

Trilogy of Programming(Putting it Together)

Prog. Framework: Java, C, Pascal, Cobol, Fortran, etc,

Environment: Windows, DOS, Unix, etc.

Tools: Java SDK, MSVC++, Borland C++

Subject Matter Knowledge

POS 406

Java Basics

Variables

A variable is an item of data named by an identifier

The variable's name must be a legal identifier --an unlimited series of Unicode characters that begins with a letter. type name

Java supports primitive and reference data types…..

Primitive Data Types

contains a single value of the appropriate size and format for its type Byte Short Integer Long Float Double Char Boolean

Reference Data Types

The value of a reference type variable, in contrast to that of a primitive type, is a reference to (an address of) the value or set of values represented by the variable (references an object).

A reference is called a pointer, or a memory address in other languages

Reference variables use the operator “new” to create (instantiate) the objects that they point to: JButton calcButton; // variable declaration calcButton = new JButton("Calculate"); //object creation JButton calcButton = new JButton("Calculate"); //combined statement

The Java programming language does not support the explicit use of addresses (pointers) like other languages do. You use the variable's name instead – or the object’s name.

Final Variables

You can declare a variable in any scope to be ‘final’. The value of a final variable cannot change after it has been initialized. Such variables are similar to constants in other programming languages. final int aFinalVar = 0;

Summary of VariablesKeyword Description Size/Format

(integers)byte Byte-length integer 8-bit two's complementshort Short integer 16-bit two's complementint Integer 32-bit two's complementlong Long integer 64-bit two's complement

(real numbers)float

Single-precision floating point 32-bit IEEE 754

doubleDouble-precision floating point 64-bit IEEE 754

(other types)char A single character 16-bit Unicode characterboolean

A boolean value (true or false) true or false

Binary Operators

Arithmetic: *, /, %, +, - Relational: >, <, >=, <=, ==, != Logical: &&, ||

Arithmetic Operators

Operator Use Description

+op1 + op2

Adds op1 and op2

-op1 - op2 Subtracts op2 from op1

* op1 * op2

Multiplies op1 by op2

/ op1 / op2

Divides op1 by op2

% op1 % op2

Computes the remainder of dividing op1 by op2

Increment/Decrement

Operator Use Description

++ op++ Increments op by 1; evaluates to the value of op before it was incremented

++ ++op Increments op by 1; evaluates to the value of op after it was incremented

-- op-- Decrements op by 1; evaluates to the value of op before it was decremented

-- --op Decrements op by 1; evaluates to the value of op after it was decremented

Relational Operators

Operator Use Returns true if

> op1 > op2 op1 is greater than op2

>= op1 >= op2 op1 is greater than or equal to op2

< op1 < op2 op1 is less than op2

<= op1 <= op2 op1 is less than or equal to op2

== op1 == op2 op1 and op2 are equal

!= op1 != op2 op1 and op2 are not equal

Logical Ops and Binary Truth Tables

X

T

T

F

F

Y

T

F

T

F

AND(&&)

T

F

F

F

XOR

F

T

T

F C

OR(||)

T

T

T

F

Operator Precedence Table Operator Description Associativity

()[]

Parentheses (grouping)Brackets (array subscript)

left-to-right

++  --!  ~&

Unary preincrement/predecrementUnary logical negation/bitwise complementAddress

right-to-left

*  /  % Multiplication/division/modulus left-to-right

+  - Addition/subtraction left-to-right

<  <=>  >=

Relational less than/less than or equal toRelational greater than/greater than or equal to

left-to-right

==  != Relational is equal to/is not equal to left-to-right

&& Logical AND left-to-right

|| Logical OR left-to-right

?: Ternary conditional right-to-left

=+=  -=*=  /=%=  &=

AssignmentAddition/subtraction assignment

Multiplication/division assignmentModulus/bitwise AND assignment

right-to-left

, Comma (separate expressions) left-to-right

Control Flow Statements

Statement Type Keyword

looping while, do-while , for

decision making if-else, switch-case

exception handling try-catch-finally, throw

branching break, continue, label:, return