Presentation is loading. Please wait.

Presentation is loading. Please wait.

 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.

Similar presentations


Presentation on theme: " 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."— Presentation transcript:

1

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 be extended across as many lines as needed */  Javadoc comments  e.g./**javadoc comments generate documentation with a program named javadoc*/

3  The java source code has to be saved with an extension.java  The filename and the classname must be the same  Case sensitive

4  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

5  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.

6  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.

7  names that are given to a variable, class or a method  case sensitive Requirements 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

8 IdentifiersValid ExamplesInvalid Examples e.g. student namestudentName, student_name student Name, Student-name e.g. class codeclassCode, class_code #code, class e.g. fee payment$payment, payFee Pay Fee, pay-fee

9  The basic building blocks of the language abstractdoimplementprivatethrow booleandoubleimportprotectedthrows breakelseinstanceOfpublictransient byteextendsintreturntrue casefalseinterfaceshorttry catchfinallongstaticvoid charfinallynativesupervolatile classfloatnewswitchwhite continuefornullsynchronizedthis defaultifpackage

10 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

11 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.

12 TypeExamples Short Long Int 2342 26357284L 13324 Char String ‘a’ “Hello World” BooleanTrue or false

13  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

14 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.

15  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;

16  Primitive  boolean  byte  char  double  float  int  long  short  Reference  array  class

17  Logical  Boolean – can hold only true or false  e.g. boolean answer=true;  Integer TypeMinimum RangeMaximum RangeSize Byte-1281278 bits Short-32,76832,76716 bits Int-2,147,483,6482,147,483,64832bits Long-9,223,372.036,854,775,8089,223,372.036,854,775,80864 bits

18  Floating Point  Character  char  e.g. char num = ‘8’; TypeMinimum RangeMaximum RangeSize Float-1.7e-3081.7e+30832bits Double3.4e-0383.4+03864 bits

19  Array  A list of variables which all have the same data types and same name Syntax: type array_name[]; or type [] array_name;

20  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”;

21  Used to define the shape and function of Java code SeparatorFunction { }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

22  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

23  Arithmetic operator OperatorDescription +Addition -Subtraction *Multiplication /Division %Modulus

24  Relational or comparison operator  Allows us to compare two items OperatorDescription <Less than >Greater than ==equal to <=less than or equal >=greater than or equal !=not equal to

25  Logical operator  Used to combine compound conditions OperatorDescription ||OR &&AND !NOT

26  Assignment operator  Represented by the equals sign (=)  Initialization- assignment made when we declare a variable  Assignment-assignment made later

27  Pre-increment e.g. ++identifier;  Post-increment e.g. identifier++;  Pre-decrement e.g. --identifier;  Post-decrement e.g. identifier--;  Increment or decrement operator

28  Used to store any characters that includes non-printing characters OperatorDescription \bBackspace \tTab \nNew line \fForm feed \rCarriage return \”Double quotation mark \’Single quotation mark \\backslach


Download ppt " 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."

Similar presentations


Ads by Google