Java:
Description
|
Site
|
Support Sites | http://www.sun.com |
Sun's Java Developer Connection | http://java.sun.com/jdc |
Java Ranch | http://javaranch.com |
References For Notes Below
|
Shorthand
|
Deitel & Deitel, Java How to Program, 3rd Ed. | JHP |
Cadenhead, Sams Teach Yourself Java 2in 24 hours | SJ2 |
Bishop & Niegel, JavaGently for Engineers & Scientists, 3ed | JG |
JAR Files and JAVA | Some Java packages don't come precompiled so we must copy
the package and compile it using the JDK or Java IDE of choice. In my case,
I will be using JDK v1.3, downloaded from Sun. This step will allow the
import statement (from above) to work on any new classes How to download and compile Java packages(using JavaGently reference): 1. Download the compressed or zipped classes from the web (javagently and myutilities) http://javagently.cs.up.ac.za/jg3e/ 2. Go to a directory above that which all the programs are and setup *.jar files The two sets of classes we download (javagently and myutilities) must maintain their names. So They must stay in their own folders. The original class files will not be necessary, only the resulting *.jar file in each of these folders. To create each jar file: - in the directory containing the javagently classfiles to be jared: jar cf javagently.jar javagently/*.class or jar cf laughtrack.jar laughtrack.class laugh.wav - take the resulting javagently.jar file and stick it into the javagently directory jar tvf javagently.jar (allows you to view the contents of a jar file) - repeat for the directory containing the myutilities classfiles Note: jar command has several options: c = creates archive, f = specifies file names, v = view etc. 3. Add to the Classpath C:\myjava\javagently\javagently.jar;C:\myjava\javagently\myutilities\myutilities.jar to the classpath so that these packages will be available to all programs that use the reference them in their import statements |
|||||||||||||||||||||||||||
Java Intro: |
Allows distributed multi-tier computing over networks (parts of applications
operate on seperate computers distributed over a network). A step up from
just Client/Server Computing (where computers are just sharing information
in a network where certain computers act as file servers, print servers
etc..). Java is an Internet based Application capable of Multi-Threading
taking advantage of multi-processor hardware vs. sequential programming..
Since Java is Compiled and Interpreted it is portable and platform independant
but slow. This is because Interpreters execute slowly compated to fully
compiled machine code. Benefit is that an Interpreted program can be executed
once its downloaded unlike a source program which must be compiled first. |
|||||||||||||||||||||||||||
Java Escape Sequences |
\n, new line |
|||||||||||||||||||||||||||
Best Practices |
-Class -- capital |
|||||||||||||||||||||||||||
Java Arithmetic, Operators & Data Types | %, modulus (e.g. r mod s (remainder of r/s) = =, is equal to !=, is not equal to >=, greater than or equal to =, assignment operator used to assign values to variables Note: datatypes must be same when operating on numbers (Java is strongly typed)
------------------------------------------------------------------------- 1(base2) = 1, since 2^0 = 1 1101(base2) = 13, since 2^3 + 2^2 + 0 + 2^0 = 13 1000 0000 = 128, since ------------------------------------------------------------------------- (JHP 144, DataTypes) |
|||||||||||||||||||||||||||
OO Design (JHP 432) | -OO Design for implementation inheritance: Subclasses tent
to use superclass definitions of mehtods, thereby placing most of the functionality
high in the hierarchy. -OO Design for interface inheritance: functionality low in hierarchy. Subclasses provide custom implementation of methods. -Implementing an interface: must define all the methods specified by the interface |
|||||||||||||||||||||||||||
Applets vs Applications |
-Applications have a main statement, Applets do not |
|||||||||||||||||||||||||||
Java Packages |
Note: Only the package path's are searched and not subdirectories |
|||||||||||||||||||||||||||
Java Rules | -Only 1 class can be public, other classes are helpers. The
srouce file name must match the public class name. -Extend only 1 class, import many classes (idea is to decide on which class you want to subclass). -For applets, place all referenced classes in the same folder -When moving graphics or text over a static boundary, use double buffering to create animations (use 3 images: back, front, worksapce) |
|||||||||||||||||||||||||||
Java Terminology | static methods, called by following their class name
with dot notation. Note: make an object method into a class method by using
the "static" parameters -- arguments for an applet (e.g. background, foreground, text, fontname, fontsize) private variables and public methods-- restricts access to methods in the class itself. May also have private methods and public data in the case of utility classes. Note: Get and Set methods allow users to access and mutuate a private variable from another class (but in a restricted manner as outlined in the set and get implementations!). static variables-- applies to entire class, use when a single copy of data is good enough. Note: always use class name and not object name when dealing with class variables! Instance variable (ivar) --applies only to a single Abstraction -- Abstract classes are created to simply provide inherited interfaces & implementations. Can not be instantiated like "concrete classes". Polymorphism -- one method (in a super class) effects its subclasses differently (e.g. the drawYourself() method). This promotes extensiblity. Also allows dynamic binding so a new object calling the draw() method doesn't require that the superclass containing the draw() method be recompiled. Another example: Subclass animal with dog object to you can modify the override the sound it makes or the speed it runs etc.. Abstract methods -- e.g. earnings() may be an abstract method since it needs to know the type of employee object to operate on and can't peform on a generic object. This would differentiate between calculating a worker's earnings vs. a manager's earnings. (ref. How to Program pg. 414). final -- keyword indicating a variable, method or class can't be changed or over-ridden. primitive variables (attributes)-- variables of the basic data type reference variables (attributes)-- "remote control" for an object. In general, object variables have unique names and the objects they refer to have unique ID's. So we never use the actual objects created...we only use references to those ojbects. Reference vara casting -- converts data from one type to another access control -- if no statement is specified (ie public, private, protected then the variable is is available to any class in the SAME Package void -- use if a method should not return anything (ie. the main method) this -- referes to the current object super -- refers to the immediate superclass of the object java plug-ins -- add the Java VM and other functionality to web browsers attibutes -- have a name and value. Parameters are attributes. implements -- statement used to inherit additional methods beyond those inherited from the super class. (e.g. Runnable & ActionListener interfaces) importing -- makes classes available so we don't neet to specify the full path name of variables and methods components -- buttons, text fields created by using a component object and the add() method. Applets are examples of containers because they hold "components" content pane -- represents main area where components are diplayed. The pane is an object of the component class in java.awt. An objecte's content pane is returned by getConentPane() method. double buffering -- when you use 3 image objects to smooth an animation(e.g. front, back, and workspace EJB -- Enterprise Java Beans. Reuseable collection of classes and frameworks for implementing custom logic. Serverside component model and vendor independent programming interface for Java App servers Enterprise -- "Extremely Robust Computing" MDOA -- Multitier Distributed Architecture J2EE -- Java Enterprise Edition Platform (JSP, EJB). Component based, server centric, multitier applications architecture. Java Environment -- Java Programming Language, Java compiler, Java VM Components -- predeveloped pieces of application code, not standalone apps..need a container to run in. Container -- thread in which components can run CORBA -- Comprehensive Distributed Object Infrastructure based on an Object Request Broker RMI -- Remote Method Invocation Persistent Data Store -- e.g. relational database |
|||||||||||||||||||||||||||