podonga poron

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

Recent posts by podonga poron

Originally posted by David O'Meara:
Firstly, the javadocs are important.

Rather than printing 'Hello' each time, why not use group() to print out what was matched in each case?



because i want to understand WHY "hello" is printed 3 times ! and why if i don't use "*" is printed only one time ..

this is NOT A PRACTICAL QUESTION of course, this is just for the SCJP exam, that's why i didn't use the group() method
16 years ago
public class Practice {
public static void main(String... args){
Pattern p = Pattern.compile("\\d*");
Matcher m = p.matcher("a1");
boolean b = false;
while(b = m.find())
System.out.println("Hello");
}
}

It prints,

Hello
Hello
Hello

WHY ??

and another question ...

%b = boolean

%c = ?

%d = digit

%f = float ?

%s = String


* please dont tell me that is because "*" or "?" is greedy because i don't understand what "greedy" means.

* don't tell me go read the javadoc (don't be mean )

Thanks a lot !
[ June 26, 2008: Message edited by: podonga poron ]
16 years ago
Is because the equalsIgnoreCase method !

hey thanks now is VERY clear
16 years ago
now i understand thanks !
16 years ago
class foo {
public static void main(String... args){
String s1 = "true";
String s2 = "TrUE";
System.out.println((s1==s2)?"YES":"NO");
System.out.println((s1.equals(s2))?"YES":"NO");
}
}

Prints, NO and NO

i don't understand the Javadoc the only thing it does is confuse me more, i will ask this question to my instructor, dont worry thanks anyway
16 years ago
In this case, it is a string, so... so what?

So it will be case sensitive but is NOT
16 years ago
public class Practice {
public static void main(String... args){
Boolean b = new Boolean("tRUe");
System.out.printf("%b", b);
}
}

that prints true !

Java wasn't case sensitive, what do i miss ?
16 years ago
I couldn't understand too
16 years ago
2. Given:

1. interface Animal {
2. void eat();
3. }
4.
5. // insert code here
6.
7. public class HouseCat implements Feline {
8. public void eat() { }
9. }
And the following three interface declarations:
interface Feline extends Animal { }
interface Feline extends Animal { void eat(); }
interface Feline extends Animal { void eat() { } }
How many, inserted independently at line 5, will compile?

1 - 0
2 - 1
3 - 2
4 - 3

The Answer is = 3

Explanation: An interface doesn't necessary have to implements methods, so knowing that you can say ..

interface Feline extends Animal { } /* it doesn't implement the Animal methods but is fine since its an interface */

interface Feline extends Animal { void eat(); } /* implements the method eat () */

BUT if you say

interface Feline extends Animal { void eat() { } } /* we have an error here INTERFACE METHODS CAN'T HAVE A BODY, can't have "{}", so it's wrong */
I will start ..

1. Given the two source files:

1. package com.sun;
2. public class PkgAccess {
3. public static int tiger = 1414;
4. }
And:

1. import static com.sun.PkgAccess.*;
2.
3. public class PkgAccess2 {
4.
5. int x1 = PkgAccess.tiger;
6. int x2 = tiger;
7. int x3 = com.sun.PkgAccess.tiger;
8. int x4 = sun.PkgAccess.tiger;
9. }

Which two are true? (Choose two.)

1 - The PkgAccess2 class compiles.
2 - Compilation fails due to an error on line 5.
3 - Compilation fails due to an error on line 6.
4 - Compilation fails due to an error on line 7.
5 - Compilation fails due to an error on line 8.
6 - The PkgAccess and PkgAccess2 classes both compile.

Answer: 2 and 5 are true.

Explanation : When you say import static com.sun.PkgAccess.*; you are importing every static value of the class PkgAccess, so you can call that value using

com.sun.PkgAccess.tiger // full path to access static "tiger" variable
tiger // use directly the static variable (because we import it !)

you CAN'T SAY

sun.PkgAccess.tiger // because the path is incorrect
PkgAccess.tiger // same as above
[ June 20, 2008: Message edited by: podonga poron ]
Here is the link to the Official Test Exam by Sun

http://www.sun.com/training/certification/assessment/index.jsp

I propose to response all the question here, and add a little description/explanation to them ...
A taked this code from K&B book, WHY IT THROWS Total is: 4950


[ June 20, 2008: Message edited by: Campbell Ritchie ]
16 years ago
lol is true, but i wrote that example looking for answers, and i didn't think about compiling
16 years ago
class example{

String s = "one"; // goes to the Stack ?
// if this is true WHY ? aren't strings treated like objects (auto-wrap)?

String s2 = new String("two"); // goes to the Heap ?

int i = 3; // to the Heap ?

example e = new example(); // Stack ?

}


Stack is in the Ram Memory ?

Heap is in the HD ?

i read that both (stack and heap) lives in the Ram, but that doesn't make sense because you have to worry about the Stack and you can use freely the Heap ...

please help me here, as you can see i'm really confused ..
16 years ago
ok, so the method2() is lost in the heap with no reference ?

what is reflection ?

thanks !
16 years ago