Microteaching Element
Microteaching Element
Java can open and access “objects” across the Net via
URLs (Uniform Resource Locator)----eg.
“http//:gamut.neiu.edu/~ylei/home.html”,
• Robust
The single biggest difference between Java
and C/C++ is that Java has “a inner safe
pointer-model”, therefore it eliminates the
possibility of overwriting memory and corrupting
data, so programmers feel very safe in coding.
Java’s Features(continue)
• GUI [Java-Swing]
For some reason, Sun believe their java-swing
is very important, so they always put it in their
certificate-tests.
• Multi-threaded
• Secure [ Exception handling ]
• Dynamic [ for Server-side coding]
Java’s cross-platform
• Interpreted Execute: cross-platform
why: For cross-platform purpose. Once coding, run anywhere.
The Java interpreter ( java.exe and its javaVirtualMachine) can
execute compiled Java-byte-codes(Xxx.class) directly on any machine to
which the interpreter has been ported.
How: ( eg. Dos command line style)
- Edit source code “demo.java” , by notepad/or other IDE tools
- Compile ( javac.exe ) “demo.java” javac Demo.java Java byte
codes, namely, Demo.class
- Execute (Interpreted Execute) java Demo
Ps: Compiler and Interpreters: Run in Physical CPU
1. Compilers use the traditional compile/link/run strategy.
Examples: C, C++, ML.
source [complie] native-files [link] nativeprogram [run]
demo.c --- obj - demo.exe --Intel cpu
Demoh.h
2. Interpreters execute the source code directly. Examples:
BASIC, Perl, TCL/Tk, ML.
source [load] [interpret run]
demo.perl - source-program - Intel cpu
data
Java: Run in Virtual Cpu
:cross-platfrom
Demo.java Compile Demo.class link xxx.class
Source-code “javac” byte-code files bytecode program
Java program
1 // Fig. 2.1: Welcome1.java
2 // A first program in Java
3
4 public class Welcome1 {
5 public static void main( String args[] )
6 {
7 System.out.println( "Welcome to Java Programming!" );
8 }
9 }
Java program
A Simple GUI Program: Printing a
Line of Text
• Display
– Most Java applications use windows or a dialog box
• We have used command window
– Class JOptionPane allows us to use dialog boxes
• Packages
– Set of predefined classes for us to use
– Groups of related classes called packages
• Group of all packages known as Java class library or Java
applications programming interface (Java API)
– JOptionPane is in the javax.swing package
• Package has classes for using Graphical User Interfaces (GUIs)
1 // Fig. 2.6: Welcome4.java
7 {
8 JOptionPane.showMessageDialog(
9 null, "Welcome\nto\nJava\nProgramming!" );
10
12 }
13 }
Packages
• Collection of classes, interfaces etc.
• How to use:
– Java: import xxx.*, or
import xxx.xx
A Simple Java Applet: Drawing a
1 <html>
2
3
String
<applet code="WelcomeApplet.class" width=300 height=30>
</applet>
4 </html>
1 <html>
2 <applet code="WelcomeLines.class" width=300 height=40>
3 </applet>
4 </html>