Programming Languages

titteringcluckSoftware and s/w Development

Nov 10, 2012 (4 years and 7 months ago)

224 views

Programming Languages


Mrs. Butera


What is a Program?

A program is a set of instructions a computer
follows in order to perform a task. A
programming language is a special language
used to write computer programs.



What is an algorithm?

The set of well
-
defined steps that
are given the computer to perform
a task or solve a problem.

Gross Pay Algorithm


Display: “How many hours did you work?”


Allow user to input hours worked


store the number
in memory


Display: “How much do you get paid per hour?”


Allow user to input pay per hour and store the
number in memory


Calculate Gross pay = Hours_Worked x
Pay_Per_Hour


Display the Gross Pay

Machine Language


Computers only process instructions that are
written in “Machine Language”



Machine Language


Binary numbers = 0's and 1's


Example: 101101000001010101

Programming Languages

Easier than machine language!!!!!



Use words instead of numbers


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


Invented to ease task of programming


Words get translated into machine language
by compliers or interpreters


Programming Lanugages


BASIC


FORTRAN


COBOL


Pascal


C


C++


Java



JavaScript


Perl


Python


Ruby


Visual Basic

History of Java


Developed by Sun Microsystems in 1991


Goal
: Develop a language that could be
processed by all the devices it controlled


not dependent upon the processor each
with its own machine language

Used in:


Stand
-
alone applications


Applets for the Internet and devices

Security

Can Java applets corrupt your computer?


NO!


Web browsers run Java applets in a secure
environment within your computer's memory
and do not allow them to access any of your
computer's resources

What is a Program Made of?

Language Elements



common to all
languages:


Key Words



(reserved words)


have
special meaning in the language.


Operators



symbols or words that perform
operations on one or more operand. An
operand is usually an item of data, such as
a number

What is a Program Made of?
continued:

Language

Elements



common to all
languages:


Punctuation



characters that serve specific
purposes, such as marking the beginning
or ending of a statement


Programmer
-
Defined Names


unlike key
words, these names are assigned by the
programmer to identify storage location sin
memory and parts of the program.

What is a Program Made of?
continued:

Language Elements


common to all
languages:


Syntax



rules that must be followed when
writing a program. Syntax dictates how key
words and operators may be used, and
where punctuation symbols must appear.

Program Sample

class HelloWorldApp {


public static void main(String[] args) {


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


}

}


Key Words/Reserved Words


Every programming language has reserved
words that cannot be used as variable
names


Look up the reserved words online or in
your textbook


When you compile your program, an error
will be returned if you use a reserved word
incorrectly

Key Words/Reserved Words

public class

Payroll

{


public
static

void

main(String[] args)


{



Int

hours = 40;



double

grossPay, payRate = 25.0;



grossPay = hours * payRate;


System.out.println(“Your gross pay is $” + grossPay);


}

}

Programmer
-
Defined Names

Variable are the names of memory locations that may hold data.

public class Payroll

{


public static void main(String[] args)


{



Int
hours

= 40;



double
grossPay
,
payRate

= 25.0;



grossPay

=

hours

*
payRate
;


System.out.println(“Your gross pay is $” +
grossPay
);


}

}

Operators

public class Payroll

{


public static void main(String[] args)


{



Int hours
=

40;



double grossPay, payRate

=

25.0;



grossPay
=

hours
*

payRate;


System.out.println(“Your gross pay is $” + grossPay);


}

}

Punctuation

Marks the end of a complete sentence/statement.

public class Payroll

{


public static void main(String[] args)


{



Int hours = 40
;



double grossPay, payRate = 25.0
;



grossPay = hours * payRate
;


System.out.println(“Your gross pay is $” + grossPay)
;


}

}

Lines and Statements

Programs are made up of lines and statements.

Lines

A line is just a single line as it appears in the body of a program.

public class Payroll

{


public static void main(String[] args)


{



Int hours = 40
;



double grossPay, payRate = 25.0
;



grossPay = hours * payRate
;


System.out.println(“Your gross pay is $” + grossPay)
;


}

}

Statements

A statement is a complete instruction that causes the computer to
perform some action.

public class Payroll

{


public static void main(String[] args)


{



Int hours = 40
;



double grossPay, payRate = 25.0
;



grossPay = hours * payRate
;


System.out.println(“Your gross pay is $” + grossPay)
;


}

}

Variables

A variable is a named storage location in the computer's memory.

public class Payroll

{


public static void main(String[] args)


{



Int
hours

= 40
;



double
grossPay, payRate

= 25.0
;



grossPay

=
hours

*
payRate
;


System.out.println(“Your gross pay is $” +
grossPay
)
;


}

}

The Compiler and the Java
Virtual Machine (JVM)


Source Code = the program is typed in a text
editor. Source file example:
test.java


javac test.java



compiles

the program
-
(converts
source code to byte code


3b 00 8h 01 84 ff ......)


syntax errors may be returned


java test

-

executes

the program

The Compiler and the Java
Virtual Machine (JVM)

Intergrated Development
Environments (IDE)

Software package
including:


Text Editor


Compiler


Debugger


Other utilities

Examples:



NetBeans


Eclipse


Komodo


WinDev

The Programming Process


1.
Clearly define what the program is to do
(requirements).

2.
Visualize the program running on the
computer.

3.
Use design tools to create a model of the
program.

4.
Check the model for logical errors.

5.

Enter the code and compile it.

The Programming Process

continued:


6. Correct any errors found during
compilation. Repeat steps 5 & 6 as many.
times as necessary.

7. Run the program with test data for input.

8. Correct any runtime errors found while
running the program. Repeat steps 5 & 6
as many times as necessary.

9. Validate the results of the program.