|
Network Programming This website demonstrates using wikis as teaching and learning tool. The course instructor is happy to share the teaching materials here with those who find it readable. |
Lecture /
Introduction to Java ProgrammingA Network Programming Lecture by Steven Choy Lecture Overview: The Java Virtual machine - Different editions of Java - Install Java SE Development Kit (JDK) - A Simple Java Program - Primitive Data Types - Program Flow Controls - Object-oriented programming with Java The Java virtual machine (JVM)
(Java bytecode can be executed on any platform with a Java virtual machine)
(A functional block diagram of JVM)
Different editions of JavaJava is split into three different editions, each targeting a different platform:
It includes the tools necessary to develop Java applications and applets for desktop platforms.
It includes the tools necessary to develop robust, secure and scalable middleware applications for enterprises.
It includes the tools necessary to develop Java applications on portable or embedded devices such as mobile phones. A special version of virtual machine has been developed for Java ME due to restrictions usually found on the target platforms.
Install Java SE Development Kit (JDK)
A simple Java program/** * Hello World Demo */ class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } }
C:\>c:
C:\>cd temp
C:\temp>javac HelloWorld.java
C:\temp>java HelloWorld
C:\temp>java –classpath . HelloWorld
Hello World Primitive data types
Program flow controls
if (boolean expression)
statement or block of statements
else
statement or block of statements
switch (integer expression) {
case integer expression:
statement or block of statements
break;
...
default:
statement or block of statements
break;
}
do {
statement or block of statements
} while (boolean expression);
while (boolean expression)
statement or block of statements
for (initialization; boolean expression; step)
statement or block of statements
for (type variable : array or collection)
statement or block of statements
The for-each loop, also called enhanced for loop, is a new addition to the flow controls since Java 5. It provides a convenient way to iterate through the elements of an array or a collection. For example, the following code calculates the total of integers in an array:
int[] arr = { 12, 4, 23, 5 };
int total = 0;
for (int i : arr) {
total += i;
}
System.out.println("Total = " + total);
Object-oriented programming with Java
Java and Network ProgrammingWe will use Java as one of language to write network programs.
We will learn more about Java programming in the course of studying network programming.
So, don't worry if you can't understand all the topics about Java programming.
Some basic topics that are important to you are:
Homework for youReadings: The Java Tutorial (http://java.sun.com/docs/books/tutorial/)
This online reading contains a fair amount of material. Prepare to spend an additional four hours on the examples and exercises. Note that the reading covers some concepts that will be discussed again later. Use the reading as a preparation for this.
Thanks for ReadingIf you would rather like to have this lecture note in printed format, please click the print action link in the top right corner. If you find any problem in this lecture note, please feel free to tell Steven via steven@findaway.hk. |