Final Slide Java
Final Slide Java
• If the computer is not doing what you want, it’s because YOU made a
mistake.
History of Java
• Java was developed by James Gosling, who is known as the father
of Java, in 1995. James Gosling and his team members started the
project in the early '90s.
• James Gosling and his team initiated the Java language project in
June 1991. The small team of sun engineers called Green Team.
2. Compile it.
• compile: Translate a program from one language to another.
• byte code: The Java compiler converts your code into a format named byte code
that runs on many computer types.
class: a program
Example:
1) byte 5) float
2) short 6) double
3) int 7) char
4) long 8) boolean
Reserved words for flow control:(11)
1) if 6) for
2) else 7) do
3) switch 8) while
4) case 9) break
11) return
Keywords for modifiers:(11)
1) public 7) synchronized
2) private 8) native
6) abstract
Keywords for exception handling:(6)
1) try 4) throw
2) catch 5) throws
1) class 4) extends
2) package 5) implements
3) import 6) interface
Object related keywords:(4)
1) new
2) instanceof
3) super
4) this
Void return type keyword:
• If a method won't return anything compulsory that method should be
declared with the void return type in java but it is optional in C++.
1) Void
Unused keywords:
goto: Create several problems in old languages and hence it is banned in java.
1. public(valid) 4. main(invalid)
2. static(valid)
3. void(valid)
Data types:
• Every variable has a type, every expression has a
type and all types are strictly define more over every
assignment should be checked by the compiler by
the type compatibility hence java language is
considered as strongly typed programming language.
Diagram:
• Except Boolean and char all remaining data types are considered as signed data types
Integral data types :
Byte:
Size: 1byte (8bits)
Maxvalue: +127
Minvalue:-128
Range:-128to 127[to]
Example:
byte b=10;
byte b2=130;//C.E:possible loss of precision
found : int
required : byte
byte b=10.5;//C.E:possible loss of precision
byte b=true;//C.E:incompatible types
byte b=“Ali";//C.E:incompatible types
found : java.lang.String
required : byte
Short:
Size: 2 bytes
Example:
short s=130;
Size: 4 bytes
Range:-2147483648 to 2147483647 ( to )
Example:
int i=130;
Size: 8 bytes
Range: to
Note: All the above data types (byte, short, int and long) can be used to
represent whole numbers. If we want to represent real numbers then
we should go for floating point data types.
Floating Point Data types:
float double
boolean b=true;
boolean b=True;//C.E:cannot find symbol
boolean b="True";//C.E:incompatible types
boolean b=0;//C.E:incompatible types
Char data type:
• Size: 2 bytes
• Range: 0 to 65535
Example:
char ch1=97;
char ch2=65536;//C.E:possible loss of precision
Summary of java primitive data type:
Data Size Range Corresponding Default value
type Wrapper class