Docsity

Programming Paradigms - Java Programming | COP 2250, Study notes of Javascript programming

Partial preview of the text

Download Programming Paradigms - Java Programming | COP 2250 and more Study notes Javascript programming in PDF only on Docsity!

Chapter 1Lecture 2

Topics Covered •^

Programming Paradigms

-^

Object Oriented Programming^ –

Class and Object

-^

Abstraction

-^

Three Object Oriented Principles

•^

Java Language and Programs

-^

Developing a Java Application

-^

Setup SDK

Programming Paradigms

-^

Procedural Language^ –

a programmer specifies a set of instructions to perform a specific task inthe form of procedures or functions

-^

C, Fortran etc.

-^

Program’s data shared among procedures

-^

Procedures dealt mainly with basic data types

-^

Procedures dealt mainly with basic data types

-^

Data centric

-^

Become unmanageable when logic becomes complex

-^

No reuse functionality

-^

Object Oriented Paradigm^ –

Object oriented approach organizes a program around its data (object)and a set of well defined interfaces to its data.– New tool: Classes & Objects

-^

C++, Java

OOP Advantage: Reuse

• Well-written classes can be reused in new

applications

• Shortens development time because

programmers don't need to write new code

programmers don't need to write new code

• Programs are more robust because the

class code is already tested

The Java Language

• Created by Sun Microsystems in 1995• Syntax based on C++• Object-oriented •^

Support for Internet applications

•^

Support for Internet applications

• Extensive library of prewritten classes• Portability among platforms• Built-in networking

An Introduction to Programming • Programming Basics• Program Design with Pseudocode •^

Developing a Java Application

•^

Developing a Java Application

Programming Basics

• Programming is translating a problem into

ordered steps consisting of operations acomputer can perform:^ –

Input

Input

  • Calculations– Comparisons of values– Moving data– Output

•^

The order of execution of instructions iscalled

flow of control

Four Types of Flow of Control

• Sequential Processing

  • Execute instructions in order

• Method Call

Jump to code in method, then return

Jump to code in method, then return

• Selection

  • Choose code to execute based on data value

• Looping or Iteration

  • Repeat operations for multiple data values

Sequential Processing

• The pseudocode for calculating the sum of

two numbers would look like this: read first number

read first number read second numberset total to (first number +

second number)

output total

Selection

• The pseudocode for determining if a

number is positive or negative is:^ read a number

read a number if the number is greater than

or equal to 0 write "Number is positive." else

write "Number is negative."

Looping

• The pseudocode for finding the sum of a

set of numbers is: set total to 0

set total to 0 read a numberwhile there was a number to

read,

add number to totalread the next number write total

A First Application

1

// First program in Java 2

// FirstProgram.java 3 4

public class FirstProgram 5

{ 6

public static void main( String [] args )

6

public static void main( String [] args )

7

{

8

System.out.println( "Programming is not "

9

  • " a spectator sport!" );

10

System.exit( 0 );

11

}

12 }

  • Java is case-sensitive. The class name

and the source filename must matchexactly, including capitalization.

Integrated Development Environment

-^

Download & Install Java JDK and NetBeanshttp://java.sun.com/j2se/1.5.0/download.jsp

click

  • click