Hasitha Randika

Ranch Hand
+ Follow
since Sep 04, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Hasitha Randika

can we restrict access to a mobile phone for certain users
i'm doing a mobile application where i can connect to google takl through my phone. there i'm declaring a text wit 200 inputs but when the chat goes on i want to increse the capacity of the text field can any one help me???


public class GetReply extends Thread {

public void run() {

status = true;
while (status) {
if (getTextField3().getString().length() < 50) {
reply = chat.getHistory();
textField3.setString(reply);
System.out.println(reply);
System.out.println(getTextField3().getString().length());
} else {
textField3.delete(0, getTextField3().getString().length());
status = false;
status =true;
// textField3.setString(textField3.);

}
}
try {
GetReply.sleep(2000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
look at the code carefully if you are not using brackets the immediate statement take as the if and the next one as the else
i got a exception called incorrect file name when i try use a dynamic push registry why is that?
whats the code to get a call
why no one is replying for my questions?
it will print techno until the loop ends what you want to remember is Strings are immutable so it will print techno
hi i think you have heard about polymorphysm.

A a = new B(); this is polymorphysm the advantage of this is non static methods when overriding goes to the object type.

class A{
int x = 10;
void m(){
System.out.println("Mike");
}
}
class B extends A{
int x = 20;
void m(){
System.out.println("You");
}
}
class C{
public static void main(String ar[]){
A a = new B();
a.m();
System.out.println(a.x);
}
}

now here the out put will be You
but in second out put will be 10 other than non static methods all the others goes to the Referance type.
i think you have got it incorrectly the truth is you can override the static method but its useless.

first you must remember the 5 rules of overriding

wider or same access range
same method name
same return type
same argument
narrower checked exception

so according to the first rule the compiler will throw a compile error at line three.

because first you have declared your static method using public modifier
so if you override the method it must be public not anything else.

remember this thing also in polymorphysm static methods goes to the referance type
i passed the SCJP last week wit 86% now i'm preparing for SCMCD so if somebody can mail me da specification for the SCMCD i would greately appriciate it my mail address is mikehassel@hotmail.com
hi guys i got a good news i got through the SCJP 5 with 85%. in that AC room i'm sweting any way i got through. it was a tuff exam.
16 years ago
class A extends Thread{
public synchronized void run(){
for(int i = 0;i<5;i++){
System.out.println("A");
}
}
public static void main(String ar[]){
new A().start();
// synchronized(this){
for(int i = 0; i<5;i++){
System.out.println("B");
// }
}
}
}
i thought that the answer is going to be AAAAABBBBB or BBBBBAAAAA but here this keyword cannot use inside the main method its a static variable.
can you explain this program.what will hapen when we insert the Synchronized key word
class B extends Thread{
static String s[] = new String[]{"x","y","z"};
public void run(){
System.out.println(s[0]+s[1]+s[2]);
}
public static void main(String ar[]){
new B().start();
s[0]= "A";
s[1]="B";
s[2]="C";
}
}
i thought the answer is going to be xyz,ayz,abz,abc
how come that happen the answer should be xyz because i think it's not going to print ABC caz its below the new B().start();

if i place it over the new B().start(); the output is going to be ABC why is that?

and what will happen if i place synchronize like this

class B extends Thread{
static String s[] = new String[]{"x","y","z"};
public "synchronized" void run(){
System.out.println(s[0]+s[1]+s[2]);
}
public static void main(String ar[]){
new B().start();
s[0]= "A";
s[1]="B";
s[2]="C";
}
}
i think the answer is still going to be same. why is that?


check this one

class B extends Thread{
static String s[] = new String[]{"x","y","z"};
static B a = new B();
static B b = new B();
public void run(){
synchronized(a){
System.out.println(s[0]+s[1]+s[2]);
}
synchronized(b){
s[0] = "A";
s[1] = "B";
s[2] = "C";
}

}
public static void main(String ar[]){
// new B().start();
// B b = new B();
a.start();
b.start();

}
}
this is giving xyz,xyz why is that
[ October 13, 2007: Message edited by: Burkhard Hassel ]
class A extends Thread{
static A a = new A();
static A b = new A();
public void run(){
synchronized(a){
System.out.println("Mike");
}
synchronized(b){
System.out.println("Gayani");
// }
}
}
public static void main(String ar[]){
a.start();
b.start();
}
}
here the answer is mike gayani &mike gayani how come that happen
because when a.start calls it'll hold "mike" while b.start execute so it should be mike gayani or gayani mike.

please explain me what happens when i use synchronize key word
[ October 13, 2007: Message edited by: Burkhard Hassel ]
class B extends Thread{
static String s[] = new String[]{"x","y","z"};
public synchronized void run(){
System.out.println(s[0]+s[1]+s[2]);
}
public synchronized static void main(String ar[]){

new B().start();

s[0] = "A";
s[1]= "B";
s[2]="C";


}
}
i thought the answer is going to be ABC nothing else.but it is 99% printed XYZ then ABC and AYZ how come is that?
because if you synchronize the main method it should return only one output isn't it?