- 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.
-- Provide templates of method that other classes are expected to implement, introduce a form of multiple-inheritance.
- It defines a superclass consisting of static, final constant and
abstract methods.
- It is a kind of abstract class.
- It declares methods and constants.
-- Use of an interface is package only, unless declare public.
- class implement interface.
- subclass can only exist in a single class.
- interface variables are static and final(allocated at complied time).
- performance advantage.
Syntax:[Interface Modifier] interface [Identifier] extends [Interface1..Interfaces]
{ .... Body ... } class [class name] implements [interface] { .... Body
.... }
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... }
-- can contain any type of element value (even objects), but it cannot store different types in the same array.
class Pixel { short R, G, B; // Red, Green, Black } class Image { Pixel array[][]; Image(int x, int y) { array = new Pixel[x][y]; } void draw() { for (int i=0; i <array.length; i++) { for (int j=0; j <array[i].length; j++) array[i][j].draw(); } } } Usage: Image me, you; // Image object: me ,you me=new Image(640, 480); // me has array[640][480] of Pixel type you=me; // set you point to me System.array.copy(me, 0, you, 0, 640*480); // make you copy of me
-- 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:Integer P1 =new Integer [2000]; Integer P2 =new Integer [3000]; Pitch_dialog.hide()
{ try { P1 = Integer.valueof(P1_S); P2 = Integer.valueof(P2_S); } catch
(NumberFormatException) { System.out.println("****** Input Error ********");
}
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.