Expressions An expression is a statement that can convey a value. Some of the most common expressions are mathematical, such as in the following source code example int x = 3; int y = x; Statements Statements are roughly equivalent to sentences in natural languages. The following types of expressions can be made into a statement by terminating the expression with a semicolon (;). // assignment statement ● aValue = 8933.234; Comments The java comments are statements that are not executed by the compiler and interpreter. The comments can be used to provide information or explanation about the variable, method, class or any statement. It can also be used to hide program code for specific time. Comments Continue… There are 3 types of comments in java.
Single Line Comment
Multi Line Comment Documentation Comment Comments Continue… Single line comment: Single line comment begins with // and ends at the end of the line. Multi line comment Multi line comment begins with /* and ends with */ that spans multiple lines. Document comment Documentation style comments begin with /** and terminate with */ and that spans multiple lines. (Note that documentation comment starts with /** whereas multi line comment start with /* ) Javadoc program uses this documentation comments to generate HTML pages of API documentation from Java source code files. Data types and literals Data types A variable's data type indicates what sort of value the variable represents, such as whether it is an integer, a floating-point number, or a character. Data types Continue.. There are two data types available in Java: Primitive Data Types Reference/Object Data Types Primitive Data Types: There are eight primitive data types supported by Java. Primitive data types are predefined by the language and named by a keyword. The following primitive data type are: -byte, short, char,int, long, Boolean,float,double Reference Data Types: Reference variables are created using defined constructors of the classes. ● They are used to access objects. ● These variables are declared to be of a specific type that cannot be changed. For example, Employee, Puppy etc. ● Class objects and various types of array Java Literals: Any constant value which can be assigned to the variable is called as literal/constant. // Here 100 is a constant/literal. int x = 100; Operators An operator is a symbol that represents a specific action. 1. Arithmetic There are five operators used to accomplish basic arithmetic in Java. These are shown in Table Relational operator: Are used to compare two or more objects Example > greater than, < less than >= greater than or equal <= less than or equal == equal Compound assignmnet Operator: Join arithment operator and assignmanet operator: example *=, -=, +=, /=, %= Logical operator: Return true or false based on the sate of the variables && and, || or NOT conditional OR, exclusive OR Variable variable Is a name location that store a changed value syntax: datatype variableName; Example Int x; Initialize Used to assign either value or expression to the variable Example variableName = value; variableName = Expression; Int x = 2; Int x = a + b; Constant is a variable whose value cannot change once it has been assigned. Note To define a variable as a constant, we just need to add the keyword “final” in front of the variable declaration. Syntax final float pi = 3.14; Identifiers Identifiers are the names of variables, methods, classes, packages and interfaces. Rules for identifiers: They must begin with a letter of the alphabet, an underscore, or ( _ ), or a dollar sign ($). Example $x or _x Identifiers Continue... identifier may also contain letters and the digits 0 to 9 Example x0123 Identifiers Continue... No spaces or special characters are allowed. Example String x _123 They are case-sensitive Example int x and int X are case-sensitive Identifiers Continue... Note You cannot use a java keyword (reserved word) for an identifier Common Java keywords include abstract, assert, boolean, break, byte, case, catch, char, class, const, continue, default, do, for, while, switch, this and int. End………………….