Avinash Rai

Ranch Hand
+ Follow
since Apr 26, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Avinash Rai

Hi All
Is there any way to store compile time data in Java?
For example I want to compile one class which displays today's date and time. I am using Calender class to do this.
And This today's date is displayed in About box of my application.
But what is happening is if I open my application 4 days from now it displays the date current on that day and not today's date when I compiled my application.
I know all objects are created at runtime in Java.
But was interested does any one knows a trick on how to do this.
Thanks
Avinash.
21 years ago
Thanks a lot Shailesh.
Avinash.
23 years ago
Thanks Jane,
Could you please suggest study forums for Architect Certification.
Offcourse there is Java ranch but are there any other resources?
Thanks.
Avinash
23 years ago
Thanks Ashik,
The Java2 Exam Notes book is not available online.
You will have to buy it.
Bookpool.com offers maximum discount on books, I purchased this book from bookpool.
Best Luck for your exam.
Avinash.
23 years ago
Thanks Paul,
I have posted JQ+ question about thread on Java ranch.
For that you replied saying the question is correct in your copy.
Well maybe that was a typo in my copy.
After asking about errata page you never replied.
I havn't sent that question to jqplus_t@hotmail.com
Anyway your product is too good.
And I strongly recommend this to everyone who is preparing for SCJP.
Avinash
23 years ago
To ALL Javarachers:
Passed SCJP2 yesterday with score 89 (53/59)
Made some stupid mistakes, otherwise would have gone close to 59.
Thank you all for your kind help.
I visited JavaRanch everyday.
Finding Java ranch site was a turning point while studying for certification.
RHE & Mughal both are great books.
Java2 exam Notes by Heller is also another good book.
JQ+ was a big help.
Though service provided by these people was very poor.
There were no replies for some of the queries.
Never mind.
Also very helpful was exam cram "question of the day".
I would say that the 4 exams from RHE book have a very similar look to the actual one. The difficulty level in my opinion is same as SCJP exam.
RHE(4 tests), Java2 exam notes, JQ+ have questions similar to SCJP exam.
Once again thank you all.
Next I want to do Sun's Architect Certification.
Please suggest useful sites and resources.
Avinash.
23 years ago
Paul
In my copy it shows setXY().
Does it mean I have an old copy.
Please let me know how I will get the latest one.
Thanks.
Avinash
Hi All,
Following is the question from JQPlus
Question ID :988383539812
Consider the following code:
public class Test extends Thread
{
static int x, y;
public synchronized void setX(int i) { x++; }
public synchronized void setY(int j) {y++; }
public void setXY(int i, int j) { setX(i); setY(j); }
public boolean testXY() { return x != y;}

public void run(){ setXY(); System.out.println(testXY()); } //line1
public static void main(String[] args)
{
new Test().start();
new Test().start();
}
}
The above code will always print "false".

The anwser given is false means it will always prints TRUE.
But the above program will fail to compile because at line 1 method setXY() is called with no arguments and there is no such method.
Also if you call method with (1,1) or (1,2) it will always prints false.
I think this is a wrong question.
Paul please correct me if I am wrong.
Thanks,
Avinash
Hi all,
I am planning to give my exam next week.
I am getting around 70% in JQ+ mocks.
Wondering whether I am ready or not??
Guys please advice.
Thanks
Avinash
Thanks Roopa, Ashish, Namrata and Bill.
I was really saturated while sending the last post.
But yes I can always rely you guys on Java ranch.
Thanks again.
Hi all,
The code:
public class example{
public static void main(String[] args) {
int a[] = {4,5,9,8,2,6,0};
int i=0;
a[i] = i= a[++i];
System.out.println(a[i]);
System.out.println(i);
}
}
The output is 6 followed by 5.
If I change i =1 then output should have been 0 followed by 6.
But at runtime it throws ArrayIndexOutOfBoundsException.
Can anyone explain why is this??
Thanks
Avinash
I have scheduled my exam on 20th July.
If Sun changes there exam pattern on July 15th then I will have to appear for the new format of exam or what??
Or Will it be same because I registered earlier?
Avinash
In Java we pass by value.
So copy of variable a is passed into the contructor and not the actual value.
And that should change the value of a in constructor and not the actual value of a.
But why the output is showing the permanent chang in the value of a??
Or is it the rule is different for Constructors than methods??
Anyone any comments.

Originally posted by michelle hou:
class Test {
int y=1;
static int a=6;
// Test() passed into int a=6
Test() {
this(a);
}
//Test(a) sign Test(int x), x=a=6, x>y true
//if y=7 not 1, x>y false, output will be 22
Test(int x) {
if ( x > y )
a = y*2;
else
a = y*3;
a++;
}
public static void main(String [] args) {
Test t = new Test();
System.out.println(a);
}
}

>>Thanks Suneeta question, let me learn lot


Consider the following code:
public class Test
{
int temp;
Test Test()
{
this.temp=10;
return this;
}
public static void main(String[] a)
{
Test t=new Test();
Test t2=t.Test();
if(t==t2)
System.out.println("Equal");
else
System.out.println("Not Equal");
}

}

The output is "Equal"
Can anyone explain why?
Test()in the code above is considered as method or a constructor?
If is a method then it should print "Not Equal"
Thanks in advance,
Avinash

Originally posted by Trevor Green:
The code fragment below is provided:
1. class Test{
2. public static void main(String [] args){
3. aMethod();
4. }
5.
6. static void aMethod(){
7. try{
8. System.out.println("abcd");
9. return;
10. } finally {
11. System.out.println("1234");
12. }
13. }
14. }
This compiles.
My queries are
1) Why does it not complain about a return on line 9 when the method is null? (Is this to do with the fact the compiler looks to see what is returned - in this case nothing - and so the presence of null works like a break?)
2) Why doesn't it complain about a try without a catch?
What are the rules about including keywords in the code without actually using them?



1) If you add some return value for this method then compiler will generate an error.
2) A catch , finally or both may follow try block.
A try block must be followed by one of them.
Similarly catch , finally without try block will generate compiler error.