Java

Introduction
1. Java Key Words
2. Java Operators
3. Java Punctuation
4. Programmer Defined Names
5. The compiler and the Java Virtual Machine
6. Compiling and Running a Java Program
7. The programming process
8. Object-Oriented Programming


Java an Object-Oriented Programming Language.

a. Java was developed by Sun Microsystems as an object-oriented language for general-purpose business applications and for interactive, World Wide Web-based Internet applications. Some of the advantages that have made Java so popular in recent years are its security features and the fact that it is architecturally neutral, which means that you can use Java to write a program that runs on any platform (operating system). Java can be run on a wide variety of computers because it does not execute instructions on a computer directly. Instead, Java runs on a hypothetical computer known as the Java Virtual Machine (JVM).

Programming statements written in a high-level programming language are called source code. When you write a Java program, you first construct the source code using a text editor such as Notepad. The statements are saved in a file; then, the Java compiler converts the source code into a binary program of bytecode. A program called the Java interpreter then checks the bytecode and communicates with the operating system, executing the bytecode instructions line by line within the Java Virtual Machine. Because the Java program is isolated from the operating system, the Java program also is insulated from the particular hardware on which it is run. Because of this insulation, the JVM provides security against intruders accessing your computer’s hardware through the operating system. Therefore, Java is more secure than other languages. Another advantage provided by the JVM means less work for programmers— when using other programming languages, software vendors usually have to produce multiple versions of the same product ( a Windows version, Macintosh version, UNIX version, Linux version, and so on) so all users can run the program. With Java, one program version will run on all these platforms. “Write once, run anywhere” (WORA) is a slogan developed by Sun Microsystems to describe the ability of one Java program version to work correctly on multiple platforms. Java also is simpler to use than many other object- oriented languages. Java is modeled after C++. Although neither language is easy to read or understand on first exposure, Java does eliminate some of the most difficult-to-understand features in C++, such as pointers and multiple inheritance.

Java Program Types: You can write two kinds of programs using Java. Programs that are embedded in a Web page are called Java applets. Stand-alone programs are called Java applications. Java applications can be further subdivided into console applications, which support character output to a computer screen in a DOS window, for example, and windowed applications, which create a GUI with elements such as menus, toolbars, and dialog boxes. An applet is designed to be transmitted over the Internet from a web server and then executed in a Web browser.  Web browsers run Java applets in a secure environment within your computer’s memory and do not allow them to access resources.

There are two types of programs that may be created with Java: applications and applets.  An application is a stand-along program that runs on your computer. An applet refers to a small application. 
b. An object is a software entity that contains data and procedures.
c. The data in the object is known as the object's attributes.
d. The behaviors that an object performs are known as the objects methods.
e. Encapsulation refers to the combining of data and code into a single object. 

Items that must be included in the design for any real-world applications:
a. The logical flow of the instructions
b. The mathematical procedures
c. The layout of the programming statements
d. The appearance of the screen
e. The way information is presented to the user
f. The program's user friendliness
g. Manuals, help systems, and /or other forms of written documentation.

Common Elements of Programming Language

Language Element

Description

Key Words

Word that have a special meaning in the programming language, reserved words

Operators

Symbols or words that perform operations on one or more operands (data)

Punctuation

Programming languages require the use of punctuation characters.

Programmer-Defined Names

Words or names that are defined by the programmer. Identifiers

Syntax

Rules that must be followed when writing a program.

Description: Programming Languages

1. Java Key Words

JAVA Key Words

Abstract

const

final

int

Public

throw

assert

continue

finally

interface

Return

throws

boolean

default

float

long

 short

transient

break

do

for

native

static

true

byte

double

goto

new

strictfp

try

case

else

if

null

super

void

catch

enum

implements

package

switch

volatile

char

extends

import

private

synchronized

while

class

false

instanceof

protected

this

 


  2. Java Operators

Java Relational Operators

Relational Operator

Meaning

> 

Greater than

< 

Less than

>=

Greater than or equal to

>=

Less than or equal to

==

Equal to

!=

Not equal to

 

Java Arithmetic Operators

Operator

Meaning

Type

Example

+

Addition

Binary

total=cost + tax

-

Subtraction

Binary

cost=total-tax

*

Multiplication

Binary

tax=cost * rate

/

Division

Binary

saleprice=original/2

%

Modulus

Binary

remainder=value % 3


3. Java Punctuation

Java Special Punctuation Characters

Characters

Name

Meaning

//

Double Slash

Marks the beginning of a comment

( )

Opening and closing parentheses

Used in method header also can be used to control the order of operations for math.

{ }

Opening and closing braces

Encloses a group of statements, such as the content of a class or method

" "

Quotation marks

Enclose a string of characters, such as a message that is to be printed on the screen

;

Semicolon

Marks the end of a complete programming statement

=

assignment

intTax=income * .03 - assign the result of equation to intTax

==

equality

strResult= a == b - if a and b are equal returns true and assigns it to strResult

4. Programmer Defined Names are not part of the programming language but are names made up by the programmer.  Usually the name is given to a variable.
Variable is a named storage location in the computer’s memory whose contents may change during program execution.

Example:
double grossPay declares in memory the variable grossPay which is the double data type.

Constant is a named storage location
in the computer’s memory whose contents will not change during program execution.  Example: final single fedTax =.03. The word final preceding the data type identifies the constant which must always be initialized upon declaration.

5. The compiler and the Java Virtual Machine
a. Source code is what is written by the programmer in a text editor or Intergraded Development Environment (IDE) with a .java extent.
b. The Java compiler translates Java source file into a file that contain byte code instructions which are not machine language and cannot be executed directly by the CPU. 
c. Byte code is executed by the Java Virtual Machine (JVM) reads Java byte code instructions and executes them as they are read which is called an interpreted language. Byte code can be considered as machine language by JVM.
d. Portable (portability) means that a program may be written on one type of computer and then run on a wide variety of computers.  Any computer with JVM on it can be used.

6. Compiling and Running a Java Program
a. Must have either a command line JAVA complier load on your machine or Use an Integrated Development Environment program. Sun JKD is a complier.
b. javac payroll.java runs the complier from the command prompt. This would compile the program payroll.java source code.
c. java payroll will run the program.
d. Integrated Development Environments is used for JAVA programming Eclipse is the IDE that is used at SCC.

7. The programming process
a. Clearly define what the program is to do - Purpose, Input, Process, Output.
b. Visualize the program running on the computer.
c. Use design tools to create a model of the program. - pseudocode - algorithm.
d. Check the model for logical errors.
e. Enter the code and compile it.
f. Correct any errors fund during compilation.
g. Run the program with test data for input.
h. Correct any runtime errors fund while running the program. 
i. Validate the results of the program.

8. Object-Oriented Programming - Java is oop language.
a. Procedural is a set of programming statements that together perform a specific task.  Procedures typically operate on data items that are separate from the procedures. Data items are passed from one procedure to another. When the structure of the data changes the code that operates on the data must also be changed.
b. OOP is centered on creating objects. An object is a software entity that contains data and procedures.  Data is the objects attributes and the procedures are referred to as it methods. Encapsulation refers to combining of data and code into a single object. When an objects internal data is hidden from outside code and access to the data is restricted to the objects methods. The data is protected from accidental corruption.