Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.

Similar presentations


Presentation on theme: "Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java."— Presentation transcript:

1 Java Basics

2 Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java is case sensitive language In the Java programming language, a keyword is one of 50 reserved words that have a predefined meaning in the language; because of this, programmers cannot use keywords as names for variables, methods, classes, or as any other identifier. 2.Identifiers Names given to variables, class, package, methods. Generally starts with letter followed by letters or digits, _(underscore) 3.Literals or Constants double check = 2.3; A Literal of any data type can exist, int literal, float literal, String literal,etc.. String inst_name = "java fast Track"; 2.3 is literal "java fast Track" is String literal

3 Tokens: 4.Operators Arithmetic, Logical, bit wise, relational or comparison 5.Separators ; - end of statement, - statement separator () - function name, casting,etc.. {} - indicates begin and end of method, class, a block 6.Whitespace and comments Java is free form language Comments are used or documentation purpose There are two types of comments in Java // single line comment /* with in a line or multi line comment */ nested multi line comments are not valid Eg. Int i/* variable i*/,j;

4 Primitive or Basic Java data Types 1.Integer Types Different Types differ in memory size and range of values. byte - 1 byte, -128 to 127 [i..e 8 bits] short - 2 bytes, -2 15 to (2 p 15)-1 int - 4 bytes, -2 p 31 to (2 p 31)-1 long - 8 bytes, -2 p 63 to (2 p 63)-1 Unsigned values are not supported in Java Signed and Unsigned keywords do not exist in Java 2.Decimal Types float - 4 bytes -3.7e-38 to 3.7e+38(Scientific notation) NOTE:-3.7e-38 means -3.7 X 10 power of -38 double - 8 bytes -1.4e-308 to 1.4e+308 Scientific notation is used to express very small or big values Sign bit(0- positive, 1 – negative) Data bits

5 3.Character Type char In C 1 byte is used to store each character ASCII(can represent only 255 different characters), and supports only English related characters In Java 2 bytes are used to store each character UNICODE Can represent 65,535 different characters. Though UNICODE uses extra 1 byte, for each character, it supports most of the international characters directly, unlike ASCII code. Java has built in support for internationalization(i18n) 4.Boolean uses 1 bit storage boolean true, false

6 Operators 1.Arithmetic +, -, *(multiplication), /, %(Modulo) - reminder of division ++(increment) x++; means x = x+1; --(decrement) Post increment x++; Pre increment ++x; 2.Relative or Comparison x, =, ==( checking equal to), !=(not equal to) Generally Relational or Comparison expression evaluates to true or false 3.Logical: Logical operators are used two combine two or more Relational or Comparison expressions. &&(Logical and) Eg.(y==3)&&(z>20) ||(Logical or) !(Logical not)

7 Operators 4.Assignment =, +=(short hand assignment) -=, *=, /=, %= x op= y means x=x op y; For eg. x+=y means x=x+y; X*=y; means x =x*y; 5.Bitwise &- bitwise AND,|-bitwise OR,^ -bitwise XOR, >(bit wise right shift) 16&8 0010000(binary representation of 16) 0001000(binary representation of 8) _______ 0000000

8 Programs: #1.Hello World Program #2.Add two numbers, multiply, #3.Display multiplication table #4.Bit complex mathematical expression

9 Array: An Array is simplest data structure which stores same type of items, sequentially in memory. For eg. To declare an int array of size 20 Int arr[] = new int[20]; How to initialize arrays Float marks[] ={ 34,21,42};

10 Conditional/Control Flow statements #1.if(condition) { //statements } Eg. If(z<20) { } #2. if(condition) { //statements }else { } #3. if(condition1) { } else if(condition2) { } else if(condition3) { }

11 Nested if is valid if(condition1) { //statements if(condition2) { //some statements }

12 switch() { case 1: //statement; break; case2: //statement; break; default: //statement }

13 Loops are used to perform an activity repeatedly 1.for loop for(initialization;condition;expression) { //…statements } 2.While loop while(condition) { //…statements } 3.Do while loop do{ //…statements }while(condition); while executes zero or more times do while executes one or more times Nested loops are valid i..e for within for or for within while, etc… break exits loop continue continues loop with next iteration

14


Download ppt "Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java."

Similar presentations


Ads by Google