Lecture 7

homeContentsIndexPrevNext

Lecture Topic:

Applet Vs Java Application

- Java applets can be viewed in any Web browser.
A reference to applet is embedded in a Web page using a special HTML tag.
When a reader, using a Java-enabled browser, loads a Web page with an applet
in it, the browser downloads that applet from a Web server and executes
it on the local system (the one the browser is running on). - Java applications
are stand-alone Java programs that can be run by using just the Java interpreter.
 

Interface

-- Provide templates of method that other
classes are expected to implement, introduce a form of multiple-inheritance.
  
-- Use of an interface is package only, unless declare
public. 
  
  1. class implement interface.

     

  2. subclass can only exist in a single class.

     

  3. interface variables are static and final(allocated at complied time).

     

  4. performance advantage.
Syntax: 
  
Example: class 
Imaginary_number extends Number
implements Arithmetic { 
.... Body .... } 
public interface DataInput { 
int
skipbytes(); 
void readfully(Byte b[]); 
Bytes readbyte(Byte b[], int offset,
int length); 
} 
public class RandomAccessfile 
    implement DataInput, DataOutput { 
...body... 
} 

Array

-- can contain any type of element value
(even objects), but it cannot store different types in the same array.

Array Allocation

-- Java supports two ways of allocating arrays.
It not only has its own method, it also supports C's method. 

"C"

Syntax: [array_type] Array_name [] = new array type
[size] Allcation function: int wow(int i)[]
{ int [] a = new int[i]; return a; } 

"Java"

 Syntax:
[array_type] [] Array_name = new array type [size] Allcation
function: int [] wow(int i) { int [] a = new int [i]; return a; }
}
   
    Example:
 
 

Sample Quiz


 
1. Applets can only run within the Browser.
 
  a. True.
 
  b. False.
 
 
 
2. Array has "Fixed Size".
 
  a. True.
 
  b. False.
 
 
 
3. Java has "a different way to allocate arrays".
 
  a. True.
 
  b. False.
 
 
 


homeContentsIndexPrevNext

Last Update: 10/24/96
Copyright ©1996 - Douglas Lyon
Lyon@cse.bridgeport.edu