Harold Ndou

Ranch Hand
+ Follow
since May 19, 2013
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
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Harold Ndou

Hi Rob

Thanks so much for your assistance, my program is working fine. I also change code in line 34 Reservation class to " for (int i=1; i<9; i++)".
3 years ago
Hi, i have problem with the following two java classes, driver class Reservations and Room class. When i run, it just show blank frame, can any tell me where i gone wrong.




3 years ago

Ankit Garg wrote:When you run the javac command, the filename has to be correct.

javac -classpath somedirectory FileName.java

The classpath is used to find classes to compile FileName.java. So if FileName uses a class which is in somedirectory it will be found. But the compiler will not look for FileName.java itself on the classpath. So the javac command needs you to provide a valid .java file name. It will not go searching the classpath for the .java file...



It seems like B.java in option E is a valid filename.








Given the default classpath:

/foo

And this directory structure:

And these two files:

package xcom;
public class A { }

package xcom;
public class B extends A { }

Which allows B.java to compile? (Choose all that apply.)

A. Set the current directory to xcom then invoke
javac B.java

B. Set the current directory to xcom then invoke
javac -classpath . B.java

C. Set the current directory to test then invoke
javac -classpath . xcom/B.java

D. Set the current directory to test then invoke
javac -classpath xcom B.java

E. Set the current directory to test then invoke
javac -classpath xcom:. B.java

Answer:

C is correct. In order for B.java to compile, the compiler first needs to be able to find
B.java. Once it's found B.java it needs to find A.class. Because A.class is in the
xcom package the compiler won't find A.class if it's invoked from the xcom directory.
Remember that the -classpath isn't looking for B.java, it's looking for whatever classes
B.java needs (in this case A.class).

A, B, and D are incorrect based on the above. E is incorrect because the compiler can't
find B.java. (Objective 7.2)

Hi Ranchers

I am buzy studying chapter 10 of K&B SCJP 6 studyguide. i have a problem with above code in question 3 seltest questions.
I would like to understand why compiler can't find B.java as they are saying E is incorrect because the compiler can't find B.java.
I will apprecite your assitance.

Thanks.





Given the following directory structure:



If the current directory is test, and you create a .jar file by invoking this,
jar -cf MyJar.jar myApp

then which path names will find a file in the .jar file? (Choose all that apply.)
A. Foo.java
B. Test.java
C. myApp/Foo.java
D. myApp/Bar.java
E. META-INF/Foo.java
F. META-INF/myApp/Foo.java
G. myApp/myAppSub/Bar.java

Answer:

C and G are correct. The files in a .jar file will exist within the same exact
structure in which they existed when the .jar was created. Although a .
a META-INF directory, none of your files will be in it. Finally, if any files
directory from which the jar command was invoked, they won’t be included
.jar file by default.

A, B, D, E, and F are incorrect based on the above. (Objective 7.5)


Hi everyone

I am studying chapter 10 of K&B SCJP studyguide and am struggling to understand the outcomes of the above code in question 10, selftest questions, a.jar file was created and they are asking which pathnames will find the file in the .jar file?
I suppose the jar command create a JAR file called MyJar.jar and it contain myApp diretory and myApp's entire subdirectory tree and files. If C is correct why D is incorrect and also i would like to understand why G is correct. Thanks in advance.



Given:


This class is to be updated to make use of appropriate generic types, with no changes in behavior
(for better or worse). Which of these steps could be performed? (Choose three.)

A. Replace line 2 with
private Map<String, int> accountTotals = new HashMap<String, int>();

B. Replace line 2 with
private Map<String, Integer> accountTotals = new HashMap<String, Integer>();

C. Replace line 2 with
private Map<String<Integer>> accountTotals = new HashMap<String<Integer>>();

D. Replace lines 06-09 with
int total = accountTotals.get(accountName);
if (total == null) total = 0;
return total;

E. Replace lines 06-09 with
Integer total = accountTotals.get(accountName);
if (total == null) total = 0;
return total;

F. Replace lines 06-09 with
return accountTotals.get(accountName);

G. Replace line 12 with
accountTotals.put(accountName, amount);

H. Replace line 12 with
accountTotals.put(accountName, amount.intValue());


Answer:

B, E, and G are correct.

A is wrong because you can't use a primitive type as a type parameter. C is wrong because
a Map takes two type parameters separated by a comma. D is wrong because an int can't
autobox to a null, and F is wrong because a null can't unbox to 0. H is wrong because you
can't autobox a primitive just by trying to invoke a method with it. (Objective 6.4)

Hi everyone

I dont understand the explanation given on that F is wrong( F is wrong because a null can't unbox to 0). I would like to understand why they say so. I will appriciate your assistance. Thanks in advance.


And the command line:
Java_ - A .

What is the results?
A. _A
B. A.
C. -A.
D. _A.
E. _-A.
F.Compalition fails
G. An exception is thrown at runtime
Answer is B according to the book, i would to know why B is the i wil appriciate it if you can explain to me.

The code is K & B SCJP 6 Study guide, self test questions chapter 10, question 2, page 811
Thanks milan

Now i got the picture
My question is how do we get this numbers, How do i know the ID of the current tread .ie 2 4 2 4


And given these two fragments:
I. synchronized void move(long id) {
II. void move(long id) {
The answer is C and E:

C. With fragments I, the output could be 4 2 4 2
E. With fragment II, the output could be 2 4 2 4


Hi everyone
I am having tough time in understanding the above output. I want to know how do we get these id's : 4 2 4 2 and 2 4 2 4

I got this code from K & B SCJP 6 Studyguide, chapter 9, self test questions, question 17

I wil real appreciate your assistance.







I was running it on the textpad, how to do it on the command line
I got this:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at Regex.main<Regex.java:4>


Here is the test run:
% java Regex "\d\w" "ab4 56_7ab"

The output is:

Pattern is \d\w
4 56
7 7a

Hi everyone

I have a problem with above code from k&b scjp 6 studyguide chapter 6 pg 499, i compile and run this code and i was expecting the above output, but i got an exception.

I would like to know where to put test run :

% java Regex "\d\w" "ab4 56_7ab" to get the above output .

I understand that d is looking for digit and w is looking for word character, am not clear about the output. Please can you explain to me, i will appriciate your assistance.


Thanks so much Jeanne for your clear explanation


Hi everyone

Am trying to understand the result of the above code, the result is:

D. Compilation fails due to an error on line 4

In the answer they say that the countGold() method cannot be invoked from static context, can anyone explain to me why it cannot accessed from static context.
This code is from k&b scjp 6 studyguide, chapter 1 page 78 sefltest questions

I will appreciate your assistance