1
ModelDesignMembersObjects.
class
class MyClass} {
class MyClass} {.
ObjectsInstance of a class
 [modifier] class Nameofnewclass [extends
Nameofsuperclass implements interface] { }
public
friendly
final
abstract
...

modifiers
class name
superclass
interface
...
...
public
friendly
friendly
...
final
finalsubclasses
abstract
instance
abstract class MyClass

$




extend

class ChildClassName extends ParentClassName
}....{
java.lang.Object
extends

int , float , short , long , String , char
int MyField;

...
public, protected, private
public
protected
private
friendly:

 MyClass Employee = new MyClass();
 MyClass Customer;
Customer = New MyClass();


Definition





void simpleMethod)( }........{
ACCESS MODIFIERS
public:
protected:
...
friendly:
extended
private:
ACCESS SPECIFIES
static
staticstaticstatic
abstract
...
final
overriding
synchronized
3.1.2RETURNED VALUES
int, double, String, char.
Void

public class date}
int day; int month ; int year;
public String getDate () { String str= day +
"/"+month+"/"+year;
return str;
}}
3.1.3PARAMETERS LIST



public void parMethod( int x, int y(
The output:
public
...

class MyClass
{
private int MyField;
public MyClass(int value)
{
MyField = value;
}
public void setField(int value)
{
MyField = value;
}
public int getField()
{
return MyField;
}
} // end of class MyClass
...
class MySubClass extends MyClass
{
private int MyNewField;
public MySubClass (int value)
{
super (value);
MyNewField = value ;
}
public void setNewField( int value)
{
MyNewField = value;
}
public int getNewField ()
{
return MyNewField;
}
}
...
MySubClasssuper(value(
MyNewField.
MAIN
public static void main(String args][( } ...... {
publicmain
staticmainclass method.
voidmain




public
class MyClass
}
int x;
public MyClass (int value)
{
x = value ;
}
{
...
public class ConsDemo
{
public static void main(String args[]) {
MyClass t1 = new MyClass( 10 );
MyClass t2 = new MyClass( 20 );
System.out.println(t1.x + " " + t2.x);
}
}
The output:
10 20

public class AddTwo {
int sum(int i , int j) { return i+j;}
float sum (float a, float b) { return
a+b;}
}

LIFO.
recursion

java.utilstack


...

class Elevator {
private boolean running = true;
public void ShutDown()
{ running = flase; }}
class SafeElevator extends Elevator {
public void ShutDown() {
if (isEmpty() )
running = false;
else
printErrormessage(); }
}
The output:
...
this
this


1this
2SUPER


void speak () {
if( people_present)
super.speak();
else
System.out.println("hello");
}
array size

 int [ ] ai; // one dimensional array of type int
 short [ ][ ] as ; // two dimensional array of type short
 object [ ] ao; // array of type object
...

// creates three objects stored in one dimensional array
 Exception ae[ ] = new Exception[3];
//create 6 objects stored in two dimensional array
 Exception aao[ ][ ] = new Exception[2][3];
 int [ ] Factorial = {1,1,2,6,24,120,720,5040}
 char ac[ ] = {'n','o','t',' ','a',' ','s','t','r','i','n','g'};
array_name[ ]=new array_type [array-size[
int int_table[ ] = new int[5[;
Integer int_obj_table[ ] = new Integer[5[;
Short graph[ ][ ]=new short [3[] [;
Graph[0][ ]= new short[4[;
Graph[1][ ]= new short[2[;
Graph[2][ ]= new short[7[;

Array-type array-name [ ] = {e1,e2,e3….};

char mchat[ ] = {‘t’,’e’,’x’,’t’};

char mychar[ ] = “text”;


Array-name[index[;
Arr1[3;]
Arr1
length
The output:
Systemarraycopy

short array_1 [] = {1,2,3,4,5};
short array_2 [] = new array[3];
System.arraycopy(array_1,1,array_2,0,3);
3

int x = new int[3[;
void SumUp(int b] [(;
,
SumUp(x(;
String40

valueOf)(String.
toString
indexOf
equalsIgnoreCase equals
SUBSTRINGS
SubStrings

Pointers
object

USING VECTORS
3
vector thevector = new vector)(;
1010
vector thevector = new vector(n(;
n
vector thevector = new vector(n , m(;
nm.
VECTORS METHODS
size()
length

X.size)(
x.
trimToSize()

...
setSize(n(
nnnn.
add(object obj)

a.add(x(
xa.
add(int index, object obj)
index
a.add(5,x(
xa.
addElement
public final synchronized void addElement( object obj(

...
insertElement

Vector vector1 = new Vector();
String current_name;
current_name="ali";
vector1.addElement(current_name);
vector1.addElement("Sami");
vector1.add("Ashraf");
current_name = "rami";
vector1.insertElementAt(current_name,0);
vector1.add(2,"hisham");
System.out.println(vector1);
System.out.println(vector1.size());
vector1.trimToSize();
remove( int index)
index
removeElement(object index)
namevector.removeElement(newName(;
...
removeElementAt(int index)
removeAllElements)(
Get(int i(
i
Set(int i(
elementAt(int index(
setElementAt(int index(
شرح مقرر البرمجة 2   لغة جافا - الوحدة الرابعة

شرح مقرر البرمجة 2 لغة جافا - الوحدة الرابعة