Sanjeev Narula

Greenhorn
+ Follow
since Mar 16, 2007
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 Sanjeev Narula

Hi,

I want to know that wheater we can give SCJP 1.4 Exam, means is it valid till now ?

Or we can only give SCJP 1.5 Exam.

Please clear my doubt.
Can anyone explain about wait() and notify() method giving some example.

Thanks in advance.
Thanks for explaining second statement.

Can you explain First Statement also

"Can one object access a private variable of another object
of the same class ? "

Ans is Yes
And also this statement:


Can a private method of super class be declared within sub classs ?

ans is Yes.
Can one object access a private variable of another object
of the same class ?

Ans is Yes

Can anyone justify this statement with example ?
Thanks Srinivasan .Now i am having better understanding of Scanner Class.
import java.util.regex.*;
class Regex2 {
public static void main(String[] args) {
Pattern p = Pattern.compile(args[0]);
Matcher m = p.matcher(args [1]);
boolean b = false;
while(b = m.find()) {
System.out.print(m.start() + m.group());
}
}
}
And the command line:
java Regex2 "\d*" ab34ef



Answer is : 01234456

I am getting confused why 6 has come in out put since length of ab34ef is 6 so starting from 0 last index should be 5.
hi

Regarding C option why did not it also prints other integers like 3 45 5 76
1. import java.util.*;
2. class Brain {
3. public static void main(String[] args) {
4. // insert code block here
5. }
6. }

Which, inserted independently at line 4, compile and produce the output
"123 82"?
(Choose all that apply.)
A. Scanner sc = new Scanner("123 A 3b c,45, x5x,76 82 L");
while(sc.hasNextInt()) System.out.print(sc.nextInt() + " ");
B. Scanner sc = new Scanner("123 A 3b c,45, x5x,76 82 L").
useDelimiter(" ");
while(sc.hasNextInt()) System.out.print(sc.nextInt() + " ");
C. Scanner sc = new Scanner("123 A 3b c,45, x5x,76 82 L");
while(sc.hasNext()) {
if(sc.hasNextInt()) System.out.print(sc.nextInt() + " ");
else sc.next(); }
D. Scanner sc = new Scanner("123 A 3b c,45, x5x,76 82 L").
useDelimiter(" ");
while(sc.hasNext()) {
if(sc.hasNextInt()) System.out.print(sc.nextInt() + " ");
else sc.next(); }
E. Scanner sc = new Scanner("123 A 3b c,45, x5x,76 82 L");
do {
if(sc.hasNextInt()) System.out.print(sc.nextInt() + " ");
} while ( sc.hasNext() );
F. Scanner sc = new Scanner("123 A 3b c,45, x5x,76 82 L").
useDelimiter(" ");
do {
if(sc.hasNextInt()) System.out.print(sc.nextInt() + " ");
} while ( sc.hasNext() );


Answer is A and C

Can any one explain how ?
Thanks in advance.
Actually these two lines:

Object o1 = a;
int[][] a2 = (int[][]) o1;

really scared me erlier..now i am having better understanding of these..Thanks all of you for participation
class Dims {
public static void main(String[] args) {
int[][] a = {{1,2,}, {3,4}};
int[] b = (int[]) a[1];
Object o1 = a;
int[][] a2 = (int[][]) o1;
System.out.println(b[1]);
} }


The output is 4
Can anyone explain. How?
Actually answer which i have given are right..Because i have taken these questions and answers from SCJP book by Katherine Sierra,Bert Bates in chapter :- 'Assignments'
The output for first question is "exception is thrown at runtime"


the out put for second question is "Compilation succeeds."


Can any one explain
Question 1)

1. class Dims {
2. public static void main(String[] args) {
3. int[][] a = {{1,2,}, {3,4}};
4. int[] b = (int[]) a[1];
5. Object o1 = a;
6. int[][] a2 = (int[][]) o1;
7. int[] b2 = (int[]) o1;
8. System.out.println(b[1]);
9. } }

Question 2)

1. class Zippy {
2. String[] x;
3. int[] a [] = {{1,2}, {1}};
4. Object c = new long[4];
5. Object[] d = x;
6. }



What is the result in these cases?

I could not figure out the assignment operators used in these questions. can any one explain ..
thanks in advance
public class Boxing9 {
public static void main(String[] args) {
int i = 10;
method(i);
}
static void method(Object o){
System.out.println("Object called");
}
static void method(Number n){
System.out.println("Number called");
}
}


what will be answer, after boxing of primitive 'i' to Integer i. it should get widen. Since Integer is a Number and also Integer is a Object.

Which method will be called?