Art
Birds
Butterflies
Books
Cats
China
Countries
Cosmetology
Education
English
Studies
Flight
& Space
France
Gifts
Health
Hebrew
Historical
Events
Holocaust
Iraq
Ireland
Israel
Italy
Japan
Japanese
>>>Java
Jewish,
Judaism
Law
Love
Lyrics
Love
Poems
Musicology
Nature
New
York
People
Photography
Professions
Spain
Weather
(1)
The Valentine Shop:
(2) The
Rainbow Valentine Shop:
|
Contructor - Overloading
Example
//dir ctor
class Person
{
String m_sName;
int m_nAge;
Person(String sName)
{
m_sName = sName;
m_nAge =200;
}
Person(String sName, int nAge)
{
m_sName = sName;
m_nAge = nAge;
}
void print()
{
System.out.println(m_sName + "
Age = " + m_nAge);
}
public static void main(String args[])
{
new Person("Shaul", 23);
}
};
|
dir intro
array example
//dir intro
class 2DimArr
{
public static void main(String args[])
{
int arr[][] = new int[5][5];
System.out.println(arr.length);
System.out.println(arr[0].length);
int arr2[][] = new int[5][];
for (int i = 0 ; i < arr2.length
; ++i )
{
arr2[i] = new
int[i + 1];
}
}
};
|
Parsing Console Input
//dir intro
class Ex2
{
public static void main(String args[])
{
/*
int i = 0;
int j = 33;
boolean b = true;
long l = 3l;
double d = 2.3;
float f = 2.3f;
System.out.println(j);
*/
int nUserVal = Integer.parseInt(args[0]);
nUserVal += 10;
System.out.println(nUserVal);
}
};
|
Some String Methods (Yvonne)
class Ex3
{
public static void main(String args[])
{
String s1 = "Hello";
String s2 = " World".toUpperCase();
String s3 = s1 + s2;
String myConcatated="";
String try1, try2;
myConcatated = s1+s2+" "+s3;
System.out.println("This illustrates
that the substring The substring begins at the specified beginIndex and extends
to the character at index endIndex - 1");
System.out.println("myConcatated="+myConcatated);
System.out.println("myConcatated.substring(0,4))="+myConcatated.substring(0,4));
System.out.println("myConcatated.substring(1,4))="+myConcatated.substring(1,4));
System.out.println("myConcatated.substring(0,5))="+myConcatated.substring(0,5));
System.out.println("myConcatated.substring(1,5))="+myConcatated.substring(1,5));
System.out.println("myConcatated.substring(5))"+myConcatated.substring(5));
System.out.println("myConcatated.toUpperCase()="+myConcatated.toUpperCase());
System.out.println("myConcatated.toUpperCase()="+myConcatated.toLowerCase());
System.out.println("myConcatated.substring(5))"+myConcatated.substring(5));
System.out.println("Did you notice
the empty space at the beginning?????)::"+myConcatated.substring(5));
//s4 = s4.toUpperCase();
System.out.println("Try Trim!! myConcatated.substring(5).trim()="+myConcatated.substring(5).trim());
//s4 = s4.toUpperCase();
//s4 = s4.trim();
//s4 = s4.subString(2);
//System.out.println(s4);
}
};
|
for statement
//dir intro
class Ex4
class Ex4
{
public static void main(String args[])
{
String s = "";
for (int i = 0 ; i < 10 ; ++i)
{
s += i;
System.out.println("s="+s);
}
}
}
/***
Method void main(java.lang.String[])
0 ldc #2 <String "">
2 astore_1
3 iconst_0
4 istore_2
5 goto 30
8 new #3 <Class java.lang.StringBuffer>
11 dup
12 invokespecial #4 <Method java.lang.StringBuffer()>
15 aload_1
16 invokevirtual #5 <Method java.lang.StringBuffer append(java.
19 iload_2
20 invokevirtual #6 <Method java.lang.StringBuffer append(int)>
23 invokevirtual #7 <Method java.lang.String toString()>
26 astore_1
27 iinc 2 1
30 iload_2
31 ldc #8 <Integer 100000>
33 if_icmplt 8
36 return
*/
|
String Buffer Append
//dir intro
class Ex4Improved
{
public static void main(String args[])
{
StringBuffer s = new StringBuffer();
for (int i = 0 ; i < 100000
; ++i)
{
s.append(i);
}
String s2 = s.toString();
}
}
/***
Method void main(java.lang.String[])
0 new #2 <Class java.lang.StringBuffer>
3 dup
4 invokespecial #3 <Method java.lang.StringBuffer()>
7 astore_1
8 iconst_0
9 istore_2
10 goto 22
13 aload_1
14 iload_2
15 invokevirtual #4 <Method java.lang.StringBuffer append(int)>
18 pop
19 iinc 2 1
22 iload_2
23 ldc #5 <Integer 100000>
25 if_icmplt 13
28 aload_1
29 invokevirtual #6 <Method java.lang.String toString()>
32 astore_3
33 return
*/
|
more arrays, int arrays,
byte arrays
//dir intro
class Ex5
{
public static void main(String args[])
{
int arr[];
arr = new int[3];
int temp[] = new int[6];
for (int i = 0 ; i < 3
; ++i)
{
temp[i] = arr[i];
}
arr = temp;
byte b[] = new byte[1024];
}
};
|
parsing arguments
//dir intro
class Ex6
{
public static void main(String args[])
{
for (int i = 0 ; i < args.length
; ++i )
{
System.out.println(args[i]);
}
}
};
|
parsing args, IF
//dir intro
class IfStatement
{
public static void main(String args[])
{
int i = args.length;
if (i > 0)
{
System.out.println(args[0]);
}
}
}
|
Thread.sleep
//dir intro
class Main
{
public static void main(String args[]) throws InterruptedException
{
System.out.println("Hello Java");
Thread.sleep(10000);
System.out.println("Done");
}
};
|
//dir intro
class Test
{
public static void main(String args[])
{
int arr[] = new int[Integer.MAX_VALUE
/ 1000];
}
};
|
dir /mem
//dir mem
class BigObject
{
int arr[][] = new int[50][50];
static int counter;
BigObject()
{
System.out.println("BigObject was
created" + counter++);
}
public void finalize()
{
System.out.println("##### BigObject
was deleted" + counter--);
}
public static void main(String args[])
{
while(true)
{
new BigObject();
System.gc();
}
}
};
|
dir obj base
//dir obj base
class Application
{
public static void main(String args[])
{
PhoneBook book = new PhoneBook();
Person p = new Person();
p.setPhoneNumber("03-6543215");
p.setName("Goofee");
book.addPerson(p);
book.addPerson(p);
Person p2 = new Person();
p2.setPhoneNumber("03-1111111");
p2.setName("Goofee 2");
book.addPerson(p2);
book.print();
PhoneBook book2 = new PhoneBook();
book2.addPerson(p);
//addPerson(PhoneBook, Person)
}
};
|
//dir obj base
class Person
{
String m_sName;
String m_sPhone;
void setPhoneNumber(String phone)
{
m_sPhone = phone;
}
void setName(String name)
{
m_sName = name;
}
void print()
{
System.out.println("Name = " +
m_sName +
" Phone = " +
m_sPhone);
}
};
|
//dir obj base
class PhoneBook
{
Person arr[] = new Person[100];
//Dim arr as Person(100)
int nNumOfPersons = 0;
void addPerson(Person p) //param0 -> this (PhoneBook),
//Person
p
{
if (nNumOfPersons < arr.length)
{
arr[nNumOfPersons++]
= p;
}
}
void print()
{
System.out.println("Num of persons
in book = "
+ nNumOfPersons);
for (int i = 0 ; i < nNumOfPersons
; ++i )
{
Person personToPrint
= arr[i];
personToPrint.print();
//arr[i].print();
}
}
};
|
dir StatObj
//dir StatObj
class Ex1
{
static Ex1 Instance;
static {
Instance = new Ex1();
}
static Ex1 getInstance()
{
return Instance;
}
void m1()
{
System.out.println("In m1");
}
void m2()
{
System.out.println("In m2");
}
static void main(String args[])
{
Ex1.Instance.m1();
Ex1.Instance.m2();
}
};
|
//dir StatObj
class MyInt
{
private int m_nValue;
void setValue(int nValue)
{
m_nValue = nValue;
}
int getValue()
{
setValue(m_nValue);
return m_nValue;
}
static int parseInt(String s)
{
return Integer.parseInt(s);
}
public static void main(String args[])
{
MyInt.parseInt("123");
}
};
|
//dir StatObj
class Sample
{
static int statInt;
void m1()
{
statInt = 2;
int i = 3;
}
static void m2()
{
statInt = 3;
Sample s = new Sample();
s.m1();
int i = 3;
}
};
|
ASDF
|
|