Download Java Network Programming-Computer Networks-Lecture and more Lecture notes Computer Networks in PDF only on Docsity!
DCIS,PIEAS
Java Network Programming
DCIS,PIEAS
About this course
o 2 weeks o 5 days a week o Two lecture and two labs daily
o Books o Lectures
- Course completion exam
- Course Completion Certificates
DCIS,PIEAS
JAVA
o Java is a simple, secure object oriented language, it inherits features from C/C++. o Developed by James Gosling, Patrick Naughton, Chris Warth, Ed Frank, Mike Sheridan at Sun Microsystems in 1991 o Initially named “Oak” o Primary motives
- Platform independence
- Embedded Software for electronic devices e.g. remote control.
- C/C++ could solve the problem but require separate compiler for each platform o Failed to gain the primary objectives and turned towards the internet programming, later it gain success as internet programming language.
DCIS,PIEAS
Highlighted Features of Java
- Platform Independent o Once compiled can be deployed on any platform without recompilation
- Platform independence is achieved by
- Java Bytecode
- Highly optimized set of instruction designed to be executed by JVM
- Java programs are initially compiled to bytecode.
- Bytecode is remains same for all platforms
- Java Virtual Machine
- A java virtual machine converts byte code to native machine code.
- Different platform require different implementation of JVM
- All JVM have same standard for bytecode
- Internationalization
o The unicode character set
- Pluggable look and feel
- Interpreted Language
- Less efficient than languages that generate native code about 1/2 to 1/ times
DCIS,PIEAS
Application Development tools
- Java Development Kit o Non-IDE command like resource kit contains core java library o JDK is part of all java development environment o Developed by Sun
- Borland Jbuilder o A rapid application development tool , by Borland ( Inprise)
- Net Beans
- Eclipse
- Visual Age o A rapid application development tool by IBM
- Visual Café o An integrated development tool by Symantec Corporation
- Visual J++ o By Microsoft Corporation
- Others e.g. Kawa
DCIS,PIEAS
Java Development Kit~JDK
- Developed by Sun-microsystem
- Provides
o Core development tools o Standard set of libraries
o Javac
- Java compiler o Java
- Java interpreter o Javah o javap o Javadoc o others
DCIS,PIEAS
Flavors of Java Programs
- Java Programs fall in the following major categories
- Applets
- For web browsers
- Examples web animations, online chat clients, online purchase clients etc.
- Applications
- Standalone or client server
- Examples: database program, a face recognition program
- Text/Command Line applications
- GUI base applications
- Server side programs
- Embedded Applications
- Designed to be executed in embedded devices such as electronic devices
- microwave oven scheduler
DCIS,PIEAS
How
Java
Works
DCIS,PIEAS
A simple Java Program
public class HelloWorld {
public static void main ( String s[] ) {
System.out.println(“Hellow World”);
The program should be saved to a file named HelloWorld.java
main method
Class Name
a Class
an object method
DCIS,PIEAS
Compiling and Executing HelloWorld Program
Open jdk/bin on command prompt and write
javac HelloWorld.java It will generate the HelloWorld.class on command prompt write java HelloWorld Output Hello World c:> cd jbuilder C:>jbuilder7>cd jdk1.3. C:>jbuilder7>jdk1.3.1> cd bin C:>jbuilder7>jdk1.3.1> bin>javac HellowWordl.java C:>jbuilder7>jdk1.3.1> bin>java HelloWordl Hello World C:>jbuilder7>jdk1.3.1> bin>
DCIS,PIEAS
Primitive Data Types
Numeric Data Types
byte 8 bits
short 16 bits
int 32 bits
long 64 bits
float 32 bits
double 64 bits
Non-Numeric
char 16 bit (java uses unicode character set,that is the unification of many character set of other languages and can represent almost each human language character set , a major part of this set is empty)
DCIS,PIEAS
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;
DCIS,PIEAS
Declaring and initializing cont..
Constants final data_type CONSTANTNAME = VALUE;
- final double PI = 3.14159;
- final int SIZE = 3;
Strings
- String are not primitive data types
- Implemented by a class called String
- Can be used like primitive data type
- Example String country=“Pakistan”;
DCIS,PIEAS
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