Java introduction
History
:- java was developed by James gosling and his team at sum micro systems in 1991 this language was initially called oak but was later renamed as java in 1995
:- java formally announce in may 95 .since then, java generated huge interest oak about to be cancelled when www came along project lead to the language oak based on c/c++
Java architecture
:- java architecture arises out of four distinct but intereted technology:
: The java programming language
: The java class file format
: The java application programming interface
: The java virtual machine
1) compile - time environment
Your program source file
A Java , b java , c java
| | |
Java compiler
| | |
A class , b class ,c class
Your program class files
2) run - Time class files
Your program class files
A class , b class, c class
| | |
Java virtual machine
| | |
Object class , string class
Java apls class files
Java : type of program
: Applets
Executes on html browser
Have severe security restrictions
: Gul application
Are interpy and executed
Use the current platform Gui widgets
Mostly use java awt or jfc package
: Console application
Simple text console
JDK basic tools
: Javac ( compiler )
The java Language compiler that you use to compiler program written in java into bytecode example : java hello world .java
: Java (interpreted)
The interpreter thet you use to run program written in java example : java hello world
: Javadoc ( doc.generator)
Generates documentation in html format from java source code
Example : javadoc hello world
Public class hello world {
Public static void main ( string argv[] }{
Systems .out .println ("hello world");
}
}
Java data type
1) java data type
1) primitive
2) reference
1) primitive
1) integral
2) floating
3) Boolean
2) reference
1) array
2) interface
3) class
4) enum
1) integral
1) byte
2) char
3) short
4) int
5) long
2) floating
1) float
2) double
Primitive data type
: Boolean true or false
: Char unicode!(16 bits)
: Byte singned 8 bit integer
: Short. Singned 16 bit integer
: Int. Singed 32 bit integer
: Long. Singned 64 bit integer
Float double IEEE 754 floating point
Other data types
Reference type
: Classes
: Arrays
: String are supported by a built- in class named string
: String literals are supported by the language
Java primitive data types
1) data types : byte
Characteristics: 8 bit signed integer
Rang : - 128 to127
2) data types : short
Characteristics: 16 bit signed integer
Rang: -32768 to 32767
3) data types: int
Characteristics : 32 bit signed integer
Rang: -2147483648 to 2147483648
4) data types : long
Characteristics : 64 bit signed integer
Rang : -9223372036854775808 to- 922337203654775808
5) data types : float
Characteristics: 32 bit floating point number
Rang : +14e-45to -34028235e+38
6) data types: double
Characteristics: 64 bit floating point number
Rang: +49e-324to+1797693134863157e+308
7) data types : Boolean
Characteristics: true or false
Rang: na note java Boolean cannot be converted to from other types
8) data types : char
Characteristics: 16 bit unicode
Rang : unicode character \u0000 yo\ufffff can mix with integer type
Type conversions
: Conversions between integer type and floating point type
: No automatically conversions from or to the type Boolean
: You can force convenience with a castsame syntax c/c++
Casting
Casting is the temporary conversation of a variable from its original data type to some others data types
Like benig cast a part in a play or movie
With primitive data types if a cast is necessary from a less Inclusive data types to a more inclusive data types it is done automatically
Int x= 5;
Double a=3-5;
Double b=a * x+a/ x;
Double c= x/2;
If a cast is necessary from a more inclusive to a less Inclusive data types the class must be done explicitly by the programmer
Failure to do so results in a compile error
Double a= 3-5 , b=2.7;
Int y=(int)a/(int)b;
Y=(int) (a/b);
Y=(int)(a/b;//syntax error
Operators
Assignment :=,+=,-=,*=,......
Number:+,-,*,/,%,++,--,.....
Relation: ==.!=,<,>,<=,>=,....
Boolean:&&,||,!
Bitwise:&,|,^,~,<<,>>,.....
Just like c/c++!
////Example : Compute distance light travels using long variables.
class Light
{
public static void main(String args[])
{
int lightspeed;
long days;
long seconds;
long distance;
// approximate speed of light in miles per second
lightspeed = 186000;
days = 1000; // specify number of days here
seconds = days * 24 * 60 * 60; // convert to seconds
distance = lightspeed * seconds; // compute distance
System.out.print("In " + days);
System.out.print(" days light will travel about ");
System.out.println(distance + " miles.");
}
}
0 Comments