Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!

Alexander Shrago

Greenhorn
+ Follow
since Aug 18, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
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 Alexander Shrago

There is the very strange situation.
The program prints nothing instead of expected answer (or it depends on types of shell and operation system - it very strange for java language).

Can someone explain the reason?

And can someone explain \d*+ regexp. Why it works correct instead of \d* ?



Mahmoud Hossam wrote:I know you can change it by using setOut(), but since it wasn't changed, then this line is redundant, right?



According to my debugger, in stack of System.out.print(String s) (jdk 1.6)
following method of PrintStream is invoked:


So I don't see the difference between System.out.print() and System.out.println() methods in context of System.out.flush() invocation after them. It is redundant, right?


I mean "1+2+12+(int)23" is an integer expression and should result to int value. Doesn't it?

The next sample get a compiler error:

int i1=23;
byte b1=1+2+12+i1;

But what is the difference?
K&B
TWO-MINUTE DRILL
Basic Assignments (Objectives 1.3 and 7.6)

❑ Literal integers are implicitly ints.
❑ Integer expressions always result in an int-sized result, never smaller.


public class Sample {
public static void main(String[] args) {

byte b1=1+2+12+(int)23;

System.out.println("Where is no compiler error. Why?");
}
}

Where is no compiler error. Can you explain it?

Guilherme Bazilio wrote:

Java does not support multiple inheritance! So answer D is false!



There are no problem for an interface to extend many interfaces. Check it!

-------------------
Sorry for all !!

I read the question inattentive - it is correctly formulated:
"Which of the following fragments represent this design?..."

The question is about the design representation, not about possibilities to have - so I am wrong about "D" ))

Chapter 2 Question 14 is

"You’re designing a new online board game in which Floozels are a type of Jammers, Jammers can
have Quizels, Quizels are a type of Klakker, and Floozels can have several Floozets. Which of the
following fragments represent this design?"

I get that you mean, but
where are no words "IS-A" or "HAS-A"

"HAS-A" relationships can appear later during realization

Where am I wrong?


I have a doubt about correct answers to Chapter 2 Question 14

What is Jammers, Quizels and so on? They are not strict names оf classes and interfaces but samples of real objects

So answer "D" is also correct inspite of authors opinion:

import java.util.*;
interface Jammer extends Quizel { }
interface Klakker { }
interface Quizel extends Klakker { }
interface Floozel extends Jammer, Floozet { }
interface Floozet { }

Checking it:
floozels are a type of Jammers - yes
quizels are a type of Klakker - yes
Jammers can have Quizels and Floozels can have several Floozets - Where do you see that they can not ??

Am I wrong?

You can declare public static enum within some class:

public class MealAdministrator1 {
public static enum Meal1 {
BREAKFAST, LUNCH, DINNER
}
public static void main(String[] args) {
System.out.println(Meal1.BREAKFAST);
}
}

Why such public enum is visible only within MealAdministrator1?
What does static modifier mean here?
And..Where is no compiler error. Why?

Aashu Mahajan wrote:Hi everyone, I also have the same quey and i little modified the existing code

I having Problem with this code is when we uncommented the Line-1 then the Line-2 compile and run but as the is stand there would be a compile error at Line-2. Anyone can explain reason of this??



I think the method declaration is required. Only then you can override it in some enum members.
But the question is why the compiler allowes such enum with undeclared method?

Stephan van Hulst wrote:Why would it throw an error?



because in this case getName() is not a jave method
any invocation code will not find out such method in this enum

Why compiler does not throw compilation error for such code??

(you only get compilation error when you try to use getName method somewhere )

Aashu Mahajan wrote:.. they also reside in the literal poll.


What does it mean?
the book p 246:

"In order to save memory, two instances of the
following wrapper objects (created through boxing), will always be == when their
primitive values are the same:
■ Boolean
■ Byte
■ Character from \u0000 to \u007f (7f is 127 in decimal)
■ Short and Integer from -128 to 127"

But it seems that
Long from -128L to 127L also should be included in this list
My jre 1.6 compiler generate an error in case of final field (static and nonstatic) may not be initializated. It doesn't even depends on if this field is used.
It is strange because class fields (static and nonstatic but not final) may be implict initialized during declaration.
And it's strange because the compiler requires the initialization of final local variables only in case of their usage.

I want to understand the logic of it to prepare to SCJP exam ...