Intro To Java API
Intro To Java API
Intro To Java API
Core Java
Page:1
Copyrights 2009
BVU Amplify DITM
What is Java?
Java (with a capital J) is a high-level, third generation
programming language, like C, Fortran, Smalltalk, Perl,
and many others.
You can use Java to write computer applications that
crunch numbers, process words, play games, store data
or do any of the thousands of other things computer
software can do.
Compared to other programming languages, Java is most
similar to C. However although Java shares much of C's
syntax, it is not C. Knowing how to program in C or,
better yet, C++, will certainly help you to learn Java
more quickly, but you don't need to know C to learn
Java. Unlike C++ Java is not a superset of C.
Core Java
Page:2
Copyrights 2009
BVU Amplify DITM
What is Java
A Java compiler won't compile C code, and most large C
programs need to be changed substantially before they
can become Java programs.
What's most special about Java in relation to other
programming languages is that it lets you write special
programs called applets that can be downloaded from
the Internet and played safely within a web browser.
A Java applet cannot write to your hard disk without
your permission. It cannot write to arbitrary addresses
in memory and thereby introduce a virus into your
computer. It should not crash your system.
Core Java
Page:3
Copyrights 2009
BVU Amplify DITM
Core Java
Page:4
Copyrights 2009
BVU Amplify DITM
Copyrights 2009
BVU Amplify DITM
Core Java
Page:6
Copyrights 2009
BVU Amplify DITM
A Brief History
January 1996: first official release JDK 1.0
Web: applets, security, URL, networking
GUI: Abstract Windows Toolkit (AWT)
Copyrights 2009
BVU Amplify DITM
Copyrights 2009
BVU Amplify DITM
Copyrights 2009
BVU Amplify DITM
Java is a Platform
Java (with a capital J) is a platform for application development.
A platform is a loosely defined computer industry buzzword that
typically means some combination of hardware and system software
that will mostly run all the same software.
Java solves the problem of platform-independence by using byte code.
The Java compiler does not produce native executable code for a
particular machine like a C compiler would. Instead it produces a
special format called byte code. Java byte code written in
hexadecimal, byte by byte, looks like this:
CA FE BA BE 00 03 00 2D 00 3E 08 00 3B 08 00 01 08 00 20 08
This looks a lot like machine language, but unlike machine language
Java byte code is exactly the same on every platform. This byte code
fragment means the same thing on a Solaris workstation as it does on a
Macintosh PowerBook.
Core Java
Page:10
Copyrights 2009
BVU Amplify DITM
Java is a Platform
Java programs that have been compiled into byte code still need an
interpreter to execute them on any given platform.
The interpreter reads the byte code and translates it into the native
language of the host machine on the fly.
The most common such interpreter is Sun's program java (with a little j).
Since the byte code is completely platform independent, only the
interpreter and a few native libraries need to be ported to get Java to run
on a new computer or operating system.
The rest of the runtime environment including the compiler and most of
the class libraries are written in Java. All these pieces, the javac
compiler, the java interpreter, the Java programming language, and more
are collectively referred to as Java.
Core Java
Page:11
Copyrights 2009
BVU Amplify DITM
Java is Simple
Java was designed to make it much easier to write bug free code.
Java has the bare bones functionality needed to implement its rich
feature set. It does not add lots of syntactic sugar or unnecessary
features. Despite its simplicity Java has considerably more functionality
than C, primarily because of the large class library.
Because Java is simple, it is easy to read and write. Obfuscated Java isn't
nearly as common as obfuscated C. There aren't a lot of special cases or
tricks that will confuse beginners.
About half of the bugs in C and C++ programs are related to memory
allocation and deallocation. Therefore the second important addition
Java makes to providing bug-free code is automatic memory allocation
and deallocation. The C library memory allocation functions malloc() and
free() are gone as are C++'s destructors.
Core Java
Page:12
Copyrights 2009
BVU Amplify DITM
Java is Simple
Java is an excellent teaching language, and an
excellent choice with which to learn programming.
The language is small so it's easy to become fluent.
The language is interpreted so the compile-run-link
cycle is much shorter.
Core Java
Page:13
Copyrights 2009
BVU Amplify DITM
Java is Object-Oriented
In object-oriented programs data is represented by objects.
Objects have two sections, fields (instance variables) and methods. Fields
tell you what an object is. Methods tell you what an object does. These
fields and methods are closely tied to the object's real world
characteristics and behavior. When a program is run messages are passed
back and forth between objects. When an object receives a message it
responds accordingly as defined by its methods.
Object oriented programming is alleged to have a number of advantages
including:
Simpler, easier to read programs
More efficient reuse of code
Faster time to market
More robust, error-free code
Core Java
Page:14
Copyrights 2009
BVU Amplify DITM
Java is Object-Oriented
In practice object-oriented programs have been just as
slow, expensive and buggy as traditional non-objectoriented programs.
In large part this is because the most popular object-
Copyrights 2009
BVU Amplify DITM
Copyrights 2009
BVU Amplify DITM
Copyrights 2009
BVU Amplify DITM
Copyrights 2009
BVU Amplify DITM
Java is Multi-Threaded
Java is inherently multi-threaded. A single Java program can have many
different threads executing independently and continuously. Three Java
applets on the same page can run together with each getting equal time
from the CPU with very little extra effort on the part of the
programmer.
This makes Java very responsive to user input. It also helps to
contribute to Java's robustness and provides a mechanism whereby the
Java environment can ensure that a malicious applet doesn't steal all of
the host's CPU cycles.
Unfortunately multithreading is so tightly integrated with Java, that it
makes Java rather difficult to port to architectures like Windows 3.1 or
the PowerMac that don't natively support preemptive multi-threading.
There is a cost associated with multi-threading. Multi-threading is to
Java what pointer arithmetic is to C, that is, a source of devilishly hard
to find bugs. Nonetheless, in simple programs it's possible to leave
multi-threading alone and normally be OK.
Core Java
Page:19
Copyrights 2009
BVU Amplify DITM
Java does not have an explicit link phase. Java source code is divided
into .java files, roughly one per each class in your program. The compiler
compiles these into .class files containing byte code. Each .java file
generally produces exactly one .class file.
Copyrights 2009
BVU Amplify DITM
Copyrights 2009
BVU Amplify DITM
Core Java
Page:22
Copyrights 2009
BVU Amplify DITM
Core Java
Page:23
Copyrights 2009
BVU Amplify DITM
Copyrights 2009
BVU Amplify DITM
Copyrights 2009
BVU Amplify DITM
Copyrights 2009
BVU Amplify DITM
If the CLASSPATH environment variable has not been set, and you do
not specify one on the command line, then Java sets the CLASSPATH to
the default:
Unix: .:$JAVA/classes:$JAVA/lib/classes.zip
Windows: .:$JAVA\classes:$JAVA\lib\classes.zip
Mac: ./$JAVA:classes/$JAVA:lib:classes.zip
Here . is the current directory and $JAVA is the main Java directory
where the different tools like javac were installed.
Core Java
Page:27
Copyrights 2009
BVU Amplify DITM