introduction to java programming. contents 1. java, etc. 2. java's advantages 3. java's...
TRANSCRIPT
![Page 1: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/1.jpg)
Introduction to Java Programming
![Page 2: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/2.jpg)
Contents
1. Java, etc.
2. Java's Advantages
3. Java's Disadvantages
4. Types of Java Code
5. Java Bytecodes
6. Steps in Writing a Java Application
7. Steps in Writing a Java Applet
![Page 3: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/3.jpg)
1. Java J, 2 SE, JSDK, JDK, JRE
There are several 'Java' names: Java is the name of the language
Java 2 is the current version
the language + tools (e.g. compiler) is called J2SE, the Java 2 Standard Edition J2SE 1.6.0. is the current version its also known as J2SE 6.0
continued
the samething
![Page 4: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/4.jpg)
JSDK stands for "Java Software Development Kit JDK is the old name for JSDK don't be surprised to also see J2SDK
or Java SDK
continued
![Page 5: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/5.jpg)
JSDK contains all the libraries (packages), compiler, and other tools for writing/running/debugging Java code.
JRE = "Java Runtime Environment" a cut-down version of JSDK with only the pack
ages/tools needed for running Java code most often used by Web browsers
![Page 6: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/6.jpg)
More New Names
Sun is trying to get people to drop the "2" from the Java platform names. e.g. J2SE becomes Java Standard Edition, abbre
viated as "Java SE" not really popular, yet
![Page 7: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/7.jpg)
2. Java’s Advantages
Productivity object orientation many standard libraries (packages)
Simpler/safer than C, C++ no pointer arithmetic, has automatic garbage
collection, has array bounds checking, etc.
continued
![Page 8: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/8.jpg)
GUI features mostly located in the Swing and Abstract
Windowing Toolkit (AWT) packages
Multimedia 2D and 3D graphics, imaging, animations,
audio, video, etc.
continued
![Page 9: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/9.jpg)
Network support communication with other machines/apps variety and standards:
sockets, RMI, CORBA security, resource protection
Multithreading / concurrency can run several ‘threads’ at once
continued
![Page 10: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/10.jpg)
Portablility / Platform Independence “write once; run anywhere” only one set of libraries to learn
J2SE is free
continued
![Page 11: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/11.jpg)
Good programming environments: Eclipse, Blue J, JBuilder, NetBeans, Sun One Studio do not use them when first learning Java http://java.coe.psu.ac.th/Tool.html
Applets (and Java Web Start) eliminates the need for explicit software installation.
continued
![Page 12: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/12.jpg)
3. Java’s Disadvantages
Java/J2SE is still being developed many changes between versions
Sun has not guaranteed backward compatibility of future versions of Java. at the moment, when old-style code is compiled,
the compiler gives a “deprecation” warning, but will still accept it
continued
![Page 13: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/13.jpg)
Java compilation/execution was slow, but ... not any more: J2SE 1.5 is the same speed as C
(perhaps a tiny bit slower for some things)
there are compilers to native code, but they destroy the “write one; run anywhere” idea
the first version of Java, back in 1995, was about 40 times slower than C
continued
![Page 14: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/14.jpg)
Slow Internet connections makes it difficult (and irritating) to download
medium/large size applets e.g. GIF89a/flash files have replaced Java
animations
Lots to learn Java language (small) and Java libraries
(very, very large)
continued
![Page 15: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/15.jpg)
4. Types of Java Code
There are two kinds of Java code:
1. Java applications ordinary programs; stand-alone they don’t run inside a browser
(but they can use Java’s GUI libraries)
continued
We will seeexamples inthe next part.
![Page 16: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/16.jpg)
2. Java applets they run in a Web browser
they are attached to Web pages, so can be downloaded easily from anywhere
applets have access to browser features
![Page 17: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/17.jpg)
5. Java Bytecodes
The Java compiler (javac) generates bytecodes a set of instructions similar to machine code not specific to any machine architecture
A class file (holding bytecodes) can be run on any machine which has a Java runtime environment.
![Page 18: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/18.jpg)
The Bytecode Advantage
Java code(.java file)
javac (Windows)
javac (Mac)
javac (Linux)
Java bytecode(.class file)
Java runtime (Windows)
Java runtime (Mac)
Java runtime (Linux)
![Page 19: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/19.jpg)
6. St eps i n Wri t i ng a J ava Appl ication
Foo.javatext file holding the application
javac Foo.java call the Java compiler
Foo.class class file holding Java bytecodes
java Foo execute the class usingthe Java runtime system(the JVM)
![Page 20: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/20.jpg)
.
import java.io.*;
public class Hello {
public static void main(String args[]) { System.out.println(“Hello Andrew”); }
} // end of class
![Page 21: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/21.jpg)
Compile & Run
![Page 22: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/22.jpg)
7. St eps i n Wri t i ng a J ava Applet
AFoo.java text file holding the applet
javac AFoo.java call the Java compiler
AFoo.class class file holding Java bytecodes
appletviewer AFoo.html
AFoo.html
Web page that calls AFoo.class
execute the applet using the Java runtime system (the JVM)
![Page 23: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/23.jpg)
execute the applet usingthe Java runtime system(the JVM)
AFoo.classAFoo.html
Web page that callsAFoo.class
browser downloads Web pageand Java class
Using a browser
For Java 2, the Java Plug-in is required,
or use the Opera browser
![Page 24: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/24.jpg)
WelcomeApplet.java
import javax.swing.JApplet;import java.awt.Graphics;
public class WelcomeApplet extends JApplet {
public void paint(Graphics g) { g.drawString(“Welcome Andrew”, 25,25); }
}
![Page 25: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/25.jpg)
WelcomeApplet.html
<html><head><title>Applet Testing</title></head><body><applet code=“WelcomeApplet.class”
width=300 height=30></applet></body></html>
![Page 26: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/26.jpg)
Compile & Run
$ javac WelcomeApplet.java
$ appletviewer WelcomeApplet.html
![Page 27: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/27.jpg)
Browser Execution
Microsoft IE and Netscape do not directly support Java 2.
A common solution is to use the Java plugin, available from Sun a drawback is that it requires the Web page conta
ining the applet to contain more complicated tags (and JavaScript code) so that the applet can run inside Netscape and Microsoft IE
continued
![Page 28: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/28.jpg)
A better solution is to use the Opera browser: free from http://www.opera.com
it comes with JRE 1.5, the latest version of the Java Runtime Environment, or it can be linked to the JRE already on your machine
there is no need for a Java plugin
Opera is very fast, small-size, and supports many networking standards
continued
![Page 29: Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps](https://reader031.vdocuments.mx/reader031/viewer/2022032006/56649dcf5503460f94ac37df/html5/thumbnails/29.jpg)
Load WelcomeApplet.html