this() and super()
to access overloaded or overriden constructors in the current
or a parents class.
import java.awt.*;
public class Test() extends Frame {
public Test(String a) {
this(a,0);
}
public Test( String a, int b) {
super(a);
this.b = b;
}
}
class Super extends Object {
private float f = 10f;
protected double g = 0.0;
public Super() {
me;
}
private me() {
g=8.0;
}
}
class Sub extends Super {
public Sub() {
super();
}
public static void main( String [] args) {
Super s = new Sub();
print("g=" + s.g );
}
}
overloading=methods with the same name but a different
argument list are overloaded.overridden=methods with the same name and with the same
argument list as the super class.
// overloading
class Car {
public Car( Color c) {
}
}
class SportsCar extends Car{
public SportsCar( Color c) {
}
public SportsCar( int r, int g, int b) { //overloading the default constructor
}
}
java.awt.Event
and identify the affected component, mouse position, and nature
and time of the Event.
public void action( Event e) {
System.out.println("target= " + e.target); // the affected component
System.out.println("[x,y]=" + e.x +"," + e.y); // mouse position
System.out.println("time&nature=" + e.when ); // timestamp
}
public class Test {
static final char CODE = '\u0a30';
public static void main( String [] args) {
int []x[] = new int [10][9];
float [] g = { 0.5f, 7.1f, 3.1459f };
char ch = 'c';
}
}
false are: interrupt, const, constant, unsigned, repeat, until
true are: synchronized, transient, volatile, throws, throw, this, super, try, catch
byte 8 bits (-128)-127
short 16 bits (-32768)-32767
int 32 bits ()
long 64 bits ()
java.lang.Math
class in an assignment expression.
class Test {
public static void main( String [] atg ) {
double x = -1.675;
System.out.println("abs=" + Math.abs( x ) ); // prints 1.675
System.out.println("ceil=" + Math.ceil( x ) ); // prints -1.0
System.out.println("floor=" + Math.floor(x) ); // prints -2.0
System.out.println("max=" + Math.max( x ,0 ) ); // prints 0
System.out.println("min=" + Math.min( x, 0 ) ); // prints -1.675
System.out.println("random= " + Math.random() ); // any thing between 0.0-1.0
// ..etc
}
}
// NOTE: also asin, acos, atan, and atan2 are valid methods.
class Test {
static int x[] = new int [10];
int y[] = new int [10];
}
// x is initialized, and y!
class Test2 {
static int x[];
int y[];
}
// compiles fine but gives NullPointerException, x is not initialized, and y not!
class Test {
public static void main( String [] args ) {
int x = -31;
int y = x >> 1; // will give -16
int z = x >>> 1; // will give 2147483632
System.out.println( "x= " + x + ", y= " + y + ", z= " + z );
x = -1; // NOTE: THIS IS A SPECIAL ONE!!
y = x >> 1; // will give -1
z = x >>> 1; // will give 2147483647
System.out.println( "x= " + x + ", y= " + y + ", z= " + z );
}
}
instanceof
operator.
public class Car {
}
class SportsCar extends Car {
public static void main( String [] args ) {
Car c = new SportsCar();
Car d = new Car();
SportsCar e = new SportsCar();
System.out.print("c=sportscar=");
if ( c instanceof SportsCar) { System.out.println("true"); } else { System.out.println("false"); }
System.out.print("c=car=");
if ( c instanceof Car) { System.out.println("true"); } else { System.out.println("false"); }
System.out.print("d=sportscar=");
if ( d instanceof SportsCar) { System.out.println("true"); } else { System.out.println("false"); }
System.out.print("d=scar=");
if ( d instanceof Car) { System.out.println("true"); } else { System.out.println("false"); }
System.out.print("e=sportscar=");
if ( e instanceof SportsCar) { System.out.println("true"); } else { System.out.println("false"); }
System.out.print("e=scar=");
if ( e instanceof Car) { System.out.println("true"); } else { System.out.println("false"); }
}
}
Will proof that a: c and e are a both SportsCar
and a Car but that d is a Car but not a SportsCar.
Dunno!!
class TestAgain {
final int y = 53;
public static void main( String [] args ) {
int x = 1;
double d = 1.652;
String s = "Andre";
System.out.println( d + x + "=" + s ); // will do ( d+x ).toString() and will print 2.652
System.out.println( "" + d + x + "=" + s ); // is different because d.toString() and x.toString() will print 1.6521
System.out.println( x + s + "=" + d );
System.out.println( s + x + "=" + d );
}
}
== comparison
operator to any two objects of any type. Determine the result
of applying the equals() method to any combination
of classes java.lang.String, java.lang.Boolean, and java.lang.Object
class TestIt {
public static void main( String [] args) {
String s = "Andre";
Object o = new String( "Andre" );
Boolean b = new Boolean( true );
System.out.print("s==o");
if ( s == o ) { System.out.println("true"); } else { System.out.println("false"); }
System.out.print("s.equals(o)");
if ( s.equals(o) ) { System.out.println("true"); } else { System.out.println("false"); }
o = b;
System.out.print("b==o");
if ( b == o ) { System.out.println("true"); } else { System.out.println("false"); }
System.out.print("b.equals(o)");
if ( b.equals(o) ) { System.out.println("true"); } else { System.out.println("false"); }
}
}
Will proof that a: b==o, because the object references
are the same (see line o=b;) also s.equals(o)and b.equals(o)
because they have the same content. But s!=o because
s and o have different object references.
String x = "Andre";
String y = "y";
x = "" + x + "y" + y;
y = null;
Dunno??
class Count {
public static void main( String [] args ) {
outloop:
for (int i=0; i <7 ; i++)
for (int j = 0 ; j < 10) {
if (i==5)
break outloop;
}
}
}
}
if(),
and switch().
class Count {
public static void main( String [] args ) {
outloop:
for (int i=0; i <7 ; i++)
if ( i == 1) {
} else if ( i == 2) {
}
switch (i) {
case 1: //do
break;
case 2: case 3:
break;
default:
break;
}
}
}
}
private, protected, public,
static, final, or abstract.
Test {
static int x = 1;
public int y =1;
Test() {
}
public int m1() {
//
}
static int m2() {
}
}
class A extends Test {
public static void main( String [] args) {
A a = new A();
a.m2();
int b = a.x;
}
}
stop(), suspend(), wait(), sleep(), yield(), destroy()
java.lang.Runnable.
class Thready extends Thread implements Runnable {
public void run() {
//
}
public static void main( String [] args) {
Thready t = new Thready();
}
}
Thread t = new Thread();
(new Thread()).start();
t.start();
wait()
method of an object.
// it will wait to get notified by notify() or notifyAll()
public synchronized run() {
try {
t.wait();
} catch (InterruptedException ie) { }
}
notify(),
and the notifyAll() methods of an Object.
the interaction is handled by the synchronized statement in the method.
thread,
the wait()???? java.awt.Component
class.
Button b = new Button("OK");
repaint();
repaint======>update(g)=====>paint(g)
handleEvent()
and action() methods in the java.awt.Compontent
class, of mouse clicks and or keystrokes on each of these components:
java.awt.TextField, java.awt.Panel,
and java.awt.Canvas.
TextField t = new TextField(6);
action = , keystrokes
handleEvent = mouse clicks, keystrokes
Panel p = new Panel();
action = keystrokes
handleEvent = mouse events
Canvas p = new Canvas();
handleEvent = mouse events
java.awt.TextArea or java.awt.TextField
that prefers to display a specific number of columns
// 30 columns,
TextField s = new TextField(30);
TextArea ta = new TextArea( 4, 30); // row, columns
<applet code=my.class width=100 height=100>
<param name=1 value="Andre">
</applet>
// javacode
String andre = getParameter("1");
show(), hide(), enable(),
disable(), size(), setForeground() and setBackground
for a java.awt.Component class.
Frame f = new Frame("My Frame");
f.resize(100,100);
if ( f.size().width == 100) {
f.setForeground( Color.red );
f.setBackground( Color.orange );
Button b;
f.add( b = new Button() );
f.show();
b.disable();
}
else {
f.hide();
}
java.awt.Container.
add( "Center", new Button() ); // BorderLayout()
add( new Button() ); // FlowLayout()
valid are: Container, Component, Frame, Canvas, Button, TextField, TextArea,
Scrollbar, List, Choice, Checkbox, Window, Panel,
not valid are: Menu, MenuItem, Event
component layout: LayoutManager,
implementation: BorderLayout, FlowLayout, GridLayout, GridBagLayout
Panel p = new Panel();
p.setLayout( new BorderLayout() );
// second part of the question???
&,
|, && and ||.
5 | 2 = 7
5 || 2 = true/false
5 & 2 = 0
5 & 2 = true/false
Object s = new String("Andre");
String b = s;
class TestIt { public static void main( String [] args) { String s = "Andre"; Object o = new String( "Andre" ); Boolean b = new Boolean( true ); System.out.print("s==o"); if ( s == o ) { System.out.println("true"); } else { System.out.println("false"); } System.out.print("s.equals(o)"); if ( s.equals(o) ) { System.out.println("true"); } else { System.out.println("false"); } o = b; System.out.print("b==o"); if ( b == o ) { System.out.println("true"); } else { System.out.println("false"); } System.out.print("b.equals(o)"); if ( b.equals(o) ) { System.out.println("true"); } else { System.out.println("false"); } } }
Exception given
a specified test that returns true
public boolean test() {
try {
if ( a < b )
throw new Exception();
} catch (Exception e) { }
}
public boolean test() throws Exception {
if ( a < b )
throw new Exception();
}
the default constructor is invoked when there is other constructor.
// normally
public class Test extends Object {
public Test( int a ) {
bee = a;
}
public Test() { //default constructor
bee = 0;
}
}
// implicitly
public class Test extends Obect {
public static void main(String at[]) {
Test t = new Test();
}
}
?What is scheduling? setPriority??
class Test implements Runnable {
Thread t;
void start() { t = new Thread(); }
void stop() { t= null; }
void run() { //do somthing }
public static void main( String [] args ) {
Test t = new Test();
t.start();
}
}
synchronized keyword
to require a thread of execution to obtain an object lock prior
to proceeding.
// it will wait to get notified by notify() or notifyAll()
public void run() {
try {
t.wait();
} catch (InterruptedException ie) { }
}
handleEvent()
or action() method to control propagation of the event
up the container hierarchy.
return true = event is handled by the component do push it to the parent component class
return false = event is not handled so push it to the parent component class
we just want react on a specific mouse event , but the rest we dont want to implement so
we pass it on the container hierarchy which has defaults to handle these events.
BorderLayout,
FlowLayout, and GridLayout.
FlowLayout: default add and resizes the components to the container in rows.
BorderLayout: has 5 ways N, E, W, S and Center to put layouts
GridLayout: is a cell structure.
FlowLayout
String
expressions.
valid are: length(), substring(), trim(), toLowerCase(), toUpperCase(), charAt() etc..
String methods:
length(), toUpperCase(), toLowerCase(), equals(), equalsIgnoreCase(),
charAt(), concat(), indexOf(), lastIndexOf(), substring(), toString()
and trim().
// the most unusual
String a = "Andre"
String b = "andre"
b.equalsIgnoreCase( a); // true
b = b.concat(a); // "andreAndre"
|
DISCLAIMER
|
|||
|
More is added to the list, but what I realy need is your help to keep this information up-to-date and may be it needs correcting in one way or the other. Please feel free to help me complement these question and answers drop us an email at this address. (C) 1998-2001, BMC88 - Personal WebSite of Java Certification Exams |
|||
![]() |
|
|||
|
|
||||