Thomas Markl

Ranch Hand
+ Follow
since Mar 08, 2001
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Thomas Markl

I just passed the exam and want to share some experience:
- You should have a good knowledge of Post- / Pre increment operators i. e. i++ and ++i.

There were two questions regarding assertions that involved the fact that
assertions are not automatically but typically enabled during test of a program
and that it is possible to enable/disable assertions on package AND class level.
There were a lot of questions regarding Threads and object lock with
„synchronized“ and the effects of „wait and notify“.
There were programs which started a new thread parallel to the main thread
so that main thread was competing with new thread and the output was impredictable
There was one thread with a synchronized run() method so that only one thread could
access the coding in the run method. Therefore it is assured that the run method is passed
completeley as a sequence by the current thread.
There was another program without synchronized run() method so that two threads could
share the coding in the run() method at the same time:

1. Abstract class and Interface
An abstract class can have methods with body and methods without body.
Those without body have to be declared as abstract.
When a class has a method without body, this method must be declared as
abstract and the whole class has to be declared as abstract.
An interface can only define methods with public or no access modifier.
Other modifiers or static or final are not allowed.
- The hashCode() returns the same value for two objects. The equals() method MIGHT return „true“ but
it MUSTN‘T return true.
- If two objects are equal the hashCode must return the same value.

Bye, Bye,
19 years ago
I think I've got the answer:
posted February 24, 2001 10:00 AM
No, StringBuffer.equals() does not behave in the same way as String.equals(). In the javadoc for StringBuffer, you can see that it just inherits the default implementation (Object.equals()), and The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any reference values x and y, this method returns true if and only if x and y refer to the same object (x==y has the value true).
In other words, two stringBuffer1.equals(stringBuffer2) only if stringBuffer1 == stringBuffer2. If you need to compare, sort, convert or otherwise process a StringBuffer, turn it into a String first.
- Peter
19 years ago
public class Test110c {

public static void main(String [] args) {
StringBuffer sb1 = new StringBuffer("abcd");
StringBuffer sb2 = new StringBuffer("abcd");
Delivers "false".
Objects have same content. Does StringBuffer not override "equals" correctly?
19 years ago
I want to transfert command line args[] to String array:
public class Test114 {

public static void main(String args[]) {

String s[] = args[];
if (s.equals(null))
System.out.println("s is null");
System.out.println("s is not equal");
I get this compiler error:
C:\Java\EigeneJavaProgramme>javac '.class' expected
String s[] = args[];
^ cannot resolve symbol
symbol : class args
location: class Test114
String s[] = args[];
^ unexpected type
required: value
found : class
String s[] = args[];
3 errors
Whats the mistike in line 5?
19 years ago
This code starts two parallel threads which print out:
... until every thread has reached 1000.

First question:
- What is the effect of „synchronized“ in the run() method?
The threads are running parallel despite of „synchronized“. I thought „synchronized“
would lock the run method for one Thread so that the threads don’t run parallel but sequential.
- What will happen if I inserted a „yield()“, try{sleep(1000);}catch (InterruptedException ie){} or
wait(1000) into the run() method?

Now the result is that the threads b1 and b2 run more parallel than before. In the first program the CPU
Changed threads on average on 500 loops. In the program with yield() the threads change on every loop.
- Is the result of the yield()that the two threads run better parallel than before???
- Did the two threads run parallel before in the first programm (no yield()) ???

C:\Java\EigeneJavaProgramme>java BussyThread
your program demands a password. Why?
If I want to sign up to register for a password
there is a "Network Error" althought Internet is on when I sign up.
Please help.
String s1=new String(" 5 + 5 = 10 ");
s1.replace('+', '-');
How many objects are created and g.c'd?
I think because of String immutablility the
string object s1 is not changed but for each
operation a new String object is temporarily created.
So I think 3 objects are created and g.c'd.
19 years ago
I think, now I got it:
Comparison of primitive numbers with „==“ and
Objects like Integer or String with „==“ and „equals“.

C:\Java\EigeneJavaProgramme>java Test104
19 years ago
that's the question:

public class OuterClass{
class InnerClass{ //instance inner class
public void innerClassDemo(){
//Explicit instance of InnerClass
In above example, how can you explicitly create an instance of InnerClass?
A. InnerClass i=InnerClass();
B. InnerClass i= new OuterClass.InnerClass();
C. InnerClass i=new OuterClass ().new InnerClass();
D. OuterClass.InnerClass i=new OuterClass().new InnerClass();
E. InnerClass i= new InnerClass();
I think correct solution is C, D, E.
E is correct, too because instance of Inner Class is created in a method of the enclosing
Class. Therefore I think it is not neccessary to create an Instance of the outer Class
Because of “this” reference automatically provided.
Is my oppinion regarding E correct???

In the program given above there is an InnerClass Instance a which is created in
Method which is not enclosing class => you must have instance of enclosing class
Created with “new OuterClass()” to create InnerClass instance.
On the contrary there is i which is in enclosing class therefore no explicit Inner class
Neccessary but you could create one?
Ist this correct?
Appreciate your answer.
19 years ago
The automatic cast from float to int takes only place for first parameter.
Why not for the second, too?
I get this error:Why?
Why don't I get the error before?
[ edited to make code and error message more readable -ds ]
[ January 15, 2003: Message edited by: Dirk Schreckmann ]
19 years ago
I wonder when to synchronize a method. Please consider this:

C:\Java\EigeneJavaProgramme>java Question47a
Thread-1 0
Thread-1 1
Thread-1 2
Thread-1 3
Thread-1 4
Thread-2 5
Thread-2 6
Thread-2 7
Thread-2 8
Thread-2 9

I have two questions:
1. Is the result always the same no matter which operation system you have? This is beause it always starts first thread t1 before it starts second thread t2. Is it possible that Java starts t2 before t1 if the two threads have the same priority?
2. I think it is not neccessary to synchronize "aMethod()" in this case as threads run() method doesn't have a sleep or yield which interrupts the current thread t1 to work on thread t2.
Is that true?
Thanks for your answers.
Does this return a random value between 1 and 6 or between 1 and 7??
private int throwDice(){
return 1+(int)(Math.random()*6);
//Math.random returns a double value between 0.0 and 6.0 and cast it
//to int and adds one. So the return value of throwDice() is an int
//number between 1 and 7.
19 years ago
private static int throwDice(){
return 1+(int)(Math.random()*6);
//Math.random returns a double value between 0.0 and 6.0 and cast it
//to int and adds one. So the return value of thrwoDice() is an int
//number between 1 and 7.
Is the result of "throwDice()" an int between 1 and 6 or 1 and 7?
19 years ago
Please take SUN's sample test for SCP2 v1.4.
I don't know the web site but when you search with google you may find it.
I downloaded JDCert from
Then I unizipped it into directory "C:\unzipped\cert\jdt\cert".
Then I wanted to start the program by running "run2.bat" which contains this DOS statements:
@echo Warning this must be run in the same directory as the questions file
java -classpath ".;c:\jdt\cert\jdcert.jar" jdt.cert.JDCert 2.0

My first question is:
What does this statement "java -classpath ".;c:\jdt\cert\jdcert.jar" jdt.cert.JDCert 2.0" mean. In the same directory there is a file "jdcert.jar".
My second question is:
I have the "jdcert.jar" and "questions2.0.txt" in the same directory as "run2.bat". But when I start "run2.bat" then I get this message:
"Exception in thread "main" java.lang.NoClassDefFoundError: jdt/cert/JDCert"
I think that "run2.bat" wants to start a java program but it doesn't find the class file or class path?
What is the error and what do I have to do?
Thank you for your answers.

When I run "run2" then it prints