Manoj Gupta

Greenhorn
+ Follow
since Oct 31, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Manoj Gupta

I haven't heard of any scheduled fee hike here in India.
I guess the nearest to you will be New Delhi. The vouchers for the exam are available in Delhi from INT (Institute of Network Technology) and STG (Software Technology Group) South Extension centers. You can then give the exam at the Prometric centers at NIIT (Safdarjung Development Area) or INT East Delhi.

------------------
Cheers,
Manoj
(http://www7.brinkster.com/manoj9/)
int a,i=3;
a=i+++i+++i++;
also results in 12. So, parentheses don't alter anything here.
Postfix ++ operator is evaluated as the highest precedence operator and works as
put the value and increment, put the value and increment, put the value and increment which make the expression evaluate to 3 + 4 + 5.
And so, prints 12.

------------------
Cheers,
Manoj
(http://www7.brinkster.com/manoj9/)
This may amaze many a people at first sight.
Check this: http://www.w3.org/TR/MathML2/bycodes.html#U0000A
The unicode character u000a is the line feed (newline) character. That ends the comment in your code and the '; fall to next line resulting in compile error.

------------------
Cheers,
Manoj
(http://www7.brinkster.com/manoj9/)
On second thoughts, I guess there might be questions which might have no correct answers. These might be questions, that you need to skip and not answer. So, that's what you do, just in case. Hope not.

------------------
Cheers,
Manoj
(http://www7.brinkster.com/manoj9/)
I never heard of any such thing. Never read either.
Too bad to be true for Sun.
Don't bother yourself for such whims and hoaxes. Keep yourself at work for the exam.
Wishing you success at your exam.
------------------
Cheers,
Manoj
(http://www7.brinkster.com/manoj9/)
Look at following expression as individual expressions:
(the comment text is the expression result for each case)
Note: consider k=1 for start of each statement.
k=k*2+(k=4); // 6
k=(k=4)+k*2; // 12
k=k*2+(k+=4); // 7
k+=k*2+(k=4); // 7
k+=k*2+(k+=4); // 8
k+=(k+=4)+k*2; // 16
k=(k+=4)+k*2; // 15
Read JLS (15.7.1 Evaluate Left-Hand Operand First) http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#4779
Try to understand each of the above cases by relating them to the text from JLS. If you still need some help understanding this, ask for more.
------------------
Cheers,
Manoj
(http://www7.brinkster.com/manoj9/)
The output of the code as given will be
Invoking light constructor setting indicator to true:
Before assignment indicator = true
Before assignment this.indicator = false
After assignment indicator = true
After assignment this.indicator = false
Here, the code you have given the variable indicator is local to constructor and not the instance variable indicator. The statement indicator = indicator; assigns the same variable to itself.
And if you replace
indicator = indicator;
with
this.indicator = indicator;
the output will be:
Invoking light constructor setting indicator to true:
Before assignment indicator = true
Before assignment this.indicator = false
After assignment indicator = true
After assignment this.indicator = true
Here, the statement this.indicator = indicator; assigns the local variable indicator to the instance variable indicator. Result is evident in the output.
------------------
Cheers,
Manoj
(http://www7.brinkster.com/manoj9/)
Compile and run:
TestA.java

prints 5.
So, ii) does work. It starts with a letter (a valid unicode character).
------------------
Cheers,
Manoj
(http://www7.brinkster.com/manoj9/)
The line in your code that you have commented with a //no will work.
objRefA.superclassVarA = 10; //no.
Reference objRefA points to a SubclassB2 object (Superclass references can legally point to a subclass object in Java), which is extending SuperclassA with a public member variable superclassVarA. Public member variables can be accessed with an object.variable notation anywhere.
To see it yourself compile and execute these:
SuperclassA.java

SubclassB2.java:

Compile using
javac -d . *.java
and execute using
java packageB.SubclassB2

------------------
Cheers,
Manoj
(http://www7.brinkster.com/manoj9/)
Though I still wonder what you are trying to do with this?
------------------
Cheers,
Manoj
(http://www7.brinkster.com/manoj9/)
I just posted a reply to your post in the other forum. Get it there.
------------------
Cheers,
Manoj
(http://www7.brinkster.com/manoj9/)
I made a few changes to your code and it looks like this now.
class shared {
static int i=0;
synchronized static void print(long id) {
System.out.println("print() called from thread id :"+id+", i ="+i);
i++;
}
synchronized void display(int id) {
System.out.println("display() called from thread id :"+id+", i = "+i);
i--;
}
}
class thread1 extends Thread {
int i=0,id=1;
shared s;
thread1(shared s) {
this.s =s;
}
public void run() {
try {
while( i < 50 ) {
Thread.sleep(100);
s.print(id);
i++;
}
} catch(Exception e) {
}
}
}
//
class thread2 extends Thread {
int i=0,id=2;
shared s;
thread2(shared s) {
this.s =s;
}
public void run() {
try {
while( i < 50 ) {
Thread.sleep(100);
s.display(id);
i++;
}
} catch(Exception e) {
}
}
}
//
public class TestA {
static void main(String[] args) {
shared s = new shared();
thread1 t1 = new thread1(s);
thread2 t2 = new thread2(s);
t1.start();
t2.start();
}
}
This code works and keeps printing:
print() called from thread id :1, i =0
display() called from thread id :2, i = 1
print() called from thread id :1, i =0
display() called from thread id :2, i = 0
display() called from thread id :2, i = 0
print() called from thread id :1, i =-1
display() called from thread id :2, i = 0
print() called from thread id :1, i =0
display() called from thread id :2, i = 0
print() called from thread id :1, i =-1
display() called from thread id :2, i = 0
print() called from thread id :1, i =-1
display() called from thread id :2, i = 0
print() called from thread id :1, i =-1
display() called from thread id :2, i = 0
print() called from thread id :1, i =0
display() called from thread id :2, i = 0
print() called from thread id :1, i =-1
display() called from thread id :2, i = 0
print() called from thread id :1, i =0
print() called from thread id :1, i =0
display() called from thread id :2, i = 1

------------------
Cheers,
Manoj
(http://www7.brinkster.com/manoj9/)
Identifier names in Java can begin with a letter, dollar sign or underscore. Letters can be any unicode character.
Java reserved words cannot be used as identifiers.
i) is correct even though Integer is a wrapper class name in Java. Java does not prevent you from using class names as variable names.
ii) is correct as the identifier name begins with a valid unicode character (The exam might not contain such variable names, and ask you to guess if a character is a valid unicode character or not).
iii) is incorrect the identifier name cannot begin with a hyphen (-).

------------------
Cheers,
Manoj
(http://www7.brinkster.com/manoj9/)
Panel p is only one object and can exist as only one. The same stands for any other object (even for buttons). You cannot ask the same object to exist in multiple places simultaneously.
------------------
Cheers,
Manoj
(http://www7.brinkster.com/manoj9/)
AWT
Change your code a bit and see the effects to understand this better:

You may try removing the lines for buttons "hello", "bye" and "hi" from the above code and see the effect.
------------------
Cheers,
Manoj
(http://www7.brinkster.com/manoj9/
)