28

Three permissible styles of comments line comments e.g. //comments on a line by themselves block comments e.g. /*comments on one line or can

Embed Size (px)

Citation preview

Page 1: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can
Page 2: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

Three permissible styles of comments line comments

e.g. //comments on a line by themselves block comments

e.g. /*comments on one line or can be extended across as many lines as needed */

Javadoc comments e.g./**javadoc comments generate

documentation with a program named javadoc*/

Page 3: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

The java source code has to be saved with an extension .java

The filename and the classname must be the same

Case sensitive

Page 4: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

Requirements when defining a classname: A classname must begin with a letter of

the alphabet, an underscore or a dollar sign.

A classname can contain only letter, digits, underscore or dollar signs.

A classname cannot be a Java programming language reserved keyword

Page 5: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

Classname should be nouns in mixed case. Variable names declared usually begin

with a lowercase first letter and should be in mixed case

Constant variables declared usually are all uppercase with the words separated by underscore.

Method name(procedures) declared should be verbs in mixed case with the first letter in lower case.

Page 6: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

Whitespace used to organize your program code to make reading easier.

The code between a pair of curly brackets ‘{‘ and ‘}’ within any class or method is known as a block.

All statements in Java programming ends with a semicolon( ; ).

A statement is a single line of code.

Page 7: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

names that are given to a variable, class or a method

case sensitiveRequirements in declaring an identifier:

can used letters, digits, dollar signs and underscores

must begin with a letter, an underscore or a dollar sign

no maximum length of characters must not use of reserved words

Page 8: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

Identifiers Valid Examples Invalid Examples

e.g. student name

studentName, student_name

student Name,Student-name

e.g. class code classCode,class_code

#code, class

e.g. fee payment

$payment,payFee

Pay Fee, pay-fee

Page 9: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

The basic building blocks of the language

abstract do implement private throw

boolean double import protected throws

break else instanceOf public transient

byte extends int return true

case false interface short try

catch final long static void

char finally native super volatile

class float new switch white

continue for null synchronized this

default if package

Page 10: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

Two types of identifiers in JAVA Programming:

Constants- data or values stored that do not change during the execution of the program

Variables- data or values stored that can be changed during the execution of the program

Page 11: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

static final type identifier=value;

The type in the declaration refers to the data type(which will be seen later in this chapter).

The identifier refers to the name of the constant being defined.

Page 12: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

Type ExamplesShortLongInt

234226357284L13324

Char String

‘a’“Hello World”

Boolean True or false

Page 13: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

A data type that identifies the type of data that the variable will store

An identifier that is the variable’s name

An optional assigned value, if we want a variable to contain an initial value

A semicolon to end the declaration

Page 14: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

type identifier;The type refers to the data type, and

identifier is the name of the variable being defined.

type identifier1, identifier2;To define more than one variable with the

same data type, the names will be separated by a comma.

Page 15: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

We can assign a value to a variable at the time of declaration or at any point later on after the variable is being declared.syntax:

type identifier=value;or

type identifier;identifier=value;

Page 16: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

Primitive boolean byte char double float int long short

Reference array class

Page 17: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

Logical Boolean – can hold only true or false

e.g. boolean answer=true;

IntegerType Minimum Range Maximum Range Size

Byte -128 127 8 bits

Short -32,768 32,767 16 bits

Int -2,147,483,648 2,147,483,648 32bits

Long -9,223,372.036,854,775,808

9,223,372.036,854,775,808

64 bits

Page 18: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

Floating Point

Character char

e.g. char num = ‘8’;

Type Minimum Range

Maximum Range

Size

Float -1.7e-308 1.7e+308 32bits

Double 3.4e-038 3.4+038 64 bits

Page 19: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

Array A list of variables which all have the

same data types and same nameSyntax:

type array_name[];or

type [] array_name;

Page 20: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

Class String

Variable name refers to the location in memory rather than to a particular value.

e.g. String myWord=“Java is my favorite subject”;

Page 21: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

Used to define the shape and function of Java code

Separator Function

{ } To separate blocks of code

; To delimit the end of a line of code

, To separate a list of values or variables

[ ] To define and reference arrays

( ) To indicate precedence in an expression

. To separate a class from a subclass

Page 22: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

Symbols used with data or variables to create mathematical or logical expressions Types:

Arithmetic operator Relational or comparison operator Logical operator Assignment operator Increment/decrement operator

Page 23: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

Arithmetic operator

Operator Description

+ Addition

- Subtraction

* Multiplication

/ Division

% Modulus

Page 24: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

Relational or comparison operator Allows us to compare two items

Operator Description

< Less than

> Greater than

== equal to

<= less than or equal

>= greater than or equal

!= not equal to

Page 25: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

Logical operator Used to combine compound conditions

Operator Description

|| OR

&& AND

! NOT

Page 26: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

Assignment operator Represented by the equals sign (=)

Initialization- assignment made when we declare a variable

Assignment-assignment made later

Page 27: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

Increment or decrement operator

Page 28: Three permissible styles of comments  line comments  e.g. //comments on a line by themselves  block comments  e.g. /*comments on one line or can

Used to store any characters that includes non-printing characters

Operator Description

\b Backspace

\t Tab

\n New line

\f Form feed

\r Carriage return

\” Double quotation mark

\’ Single quotation mark

\\ backslach