Download Java Programming: Installing Java, Java Versions, IDEs, and Data Types and more Slides Java Programming in PDF only on Docsity!
Programming
Today’s Lecture
- Installing Java
- What is Java
- IDEs for Java
- Basic Data Types
What is Java 2?
- Early version of java were named as JDK
- JDK 1.0 (January 23, 1996)
- JDK 1.1 (February 19, 1997)
- For JDK 1.2 version renamed to Java 2 Standard Edition ( Java 2 )
- J2SE 1.2 (December 8, 1998)
- Initially called JDK 1.2 ,Later renamed (after 3 days)
- J2SE 1.3 (May 8, 2000)
- J2SE 1.4 (February 6, 2002)
- After 1.4 numbering changed to 5.
- J2SE 5.0 (September 30, 2004) (1.5)
What is Java 2?
- Sun replaced the name "J2SE" with Java SE and dropped the
".0" from the version numbers
- Java SE 6 (December 11, 2006)
- Java SE 7 (July 07, 2011)
- Simply Java 7 , Internal version JDK 1.
- Java SE 8
- Simply Java 8, Internal version JDK 1.
- Java 9
- Internal version JDK 1.
Data Types
- Primitive
- Reference
Primitive Types
- boolean
- char
- float
- byte
- int
- double
- short
- long
Primitive Data Types
Numeric Data Types
- byte 8 bits
- short 16 bits
- int 32 bits
- long 64 bits
- float 32 bits
- double 64 bits
- Java Integers and floats are platform independent unlike C/C++
- For long integer suffix L is used
- For floats suffix F is used
- For double suffix D is used
- A real number without any suffix is always considered as double
- For Hexadecimal and Octal 0x and 0 is used respectively
Java Network Programming 10
Declaring and initializing variables
Identifiers
An identifier must start with a letter, an underscore, or a dollar sign.
- An identifier cannot contain operators, such as +, -, and so on.
- An identifier cannot be a reserved word.
- An identifier cannot be true, false, or null.
Declaring and Initializing Integers and Floats
int i = 34;
long l = 1000000;
float f = 100.2f; or float f = 100.2F;
double d = 100.2d or double d = 100.2D;
Java Network Programming 11
Declaring and initializing cont..
Characters char letter = 'A'; (ASCII) char numChar = '4'; (ASCII) char letter = '\u000A'; (Unicode) Special characters char tab = ‘\t’; Booleans
boolean lightsOn = true;
boolean fansOn = false
Java Network Programming 13
Displaying values
System.out.println(“Any string”+variable+”Other string”);
Exanmple
public class Student{
public static void main(String s[]){ int code=911; System.out.println(“Mr. Anonymous “+code); System.out.print(“Mr. “); System.out.print(“ Anonymous “); System.out.print(code); }
}
Mr.Anonymous 911
Mr.Anonymous 911
Java Network Programming 14
displaying values cont..
Exanmple public class Student{
public static void main(String s[]){ int phy=90, math=90,chem=70,bio=70; int sum1,sum2; sum1=sum2=0; sum1=phy+math+chem+bio; sum2+=phy; sum2+=math; sum2+=chem; sum2+=bio; System.out.println(“Sum1 = “+sum1); System.out.println(“Sum2 = “+sum2); } }
Sum1 = 320 Sum2 = 320
Java Network Programming 16
Reference Variables
- There are three types of reference variables
- Classes
- Interfaces
- Arrays
Java Network Programming 17
Arrays
- Arrays in java are a bit different than other languages
- Arrays are implemented as objects in Java
- Declaring arrays
- There are two methods for declaring an array
- int numbers[ ];
- Int [ ] numbers;
- Allocating memory to arrays
- After an array has been declared it must be assigned some memory to hold the members this is done using “ new” keyword
- Numbers= new int [100];
- Assigning values
- One step for all
- Int numbers[]={12,34,5,67,78,90};
Java Network Programming 19
Comments
- Comments serves as a message/guide line for code reader
- Java supports three styles of comments
- Traditional Comments
- C++ Style Comments
- Javadoc
Java Network Programming 20
Traditional Comments
- C-Style comments
- Begins with slash-star (/*)
- Ends with star-slash (*/)
- Can span many lines
- Can contained within a single line
- Cannot be nested
- Can be used any where in the program.
- Example
/* Day-01 of java short course exercise - topic Java Comments */
Or
/* Day-01 of java short course exercise -01 topic Java Comments */