kiennjal shah

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

Recent posts by kiennjal shah

Consider this:

String a = "Hello";
String b = "World";
String c = b;
System.out.println("String a is" + a);
System.out.println("String b is" + b);
System.out.println("String c is" + c);
System.out.println("String ab is" + a+b);
System.out.println("New" + b);

String b = "something else";

System.out.println("String b now is" + b);
System.out.println("String c now is" + c);

Output:
------------------------------------------------
String a is Hello
String b is World
String c is World
String ab is Hello World
New World
String b now is something else
String c now is World
---------------------------------------------

Consider a pool of strings, what we mean by "strings are immutable" is that once I say a="Hello", in the string pool is created a string object with a certain value and reference. now variable a actually holds the reference. For strings, if I say: a= a+"world", it will actually abandon the string "hello" and create A NEW string object with a value "Hello World" and variable a will now refer to it, the string "hello" is now lost in the pool and cannot be recovered (unless u had assigned it to another variable before changing variable a to point to another String.

However, if you use stringBuffer, u can preserve the values as well as modify them.

Hope this helps.

In case I am wrong anywhere please feel free to correct me.

Thanks

-Kiennjal
20 years ago
Before you even begin working on this problem, you must really get familiar with the basic syntax (conditional statements etc..) As stated earlier, Hello World! would be a good start.

Then, you should write pseudocode (or an algo) so that things are very clear when you actually begin writing your code.

For simplicity, you can just stuff all your code into the main method (though that is not a very good approach, but you can learn that as you proceed).

After that if you are stuck anywhere you can always post your questions here.

Hope this gets you started

-Kiennjal
20 years ago
hey joel,

does it mean, that at the time of compiling (if I haven't compiled a certain file in the package I am about to use, I should first compile tht file) and then compile my code that imports that package/class.

Also, when you mentioned classpath with regards to this problem, I want to ask you if:

1. At the command prompt, I get into that directory (package) and then compile tht particular file OR
2. just compile from the same directory using something like ../Food/Fruits.java

I am not sure if the two make any difference at all....

the question may sound silly, but once I had this problem (it did not recognize the package when I tried compiling), however I am not sure what I did but after that it worked
20 years ago
i havent tried to check if the code compiles, however I partially agree with Raghu's code modification, except for the part where he has declared the method to be static,i don't see the reason for doing so.

Can you please explain.

Thanks

Kiennjal
I do not understand as to how dot.com.boom has assertions enabled since com package has assertions disabled. so com and all subpackages would not recognize assert as a keyword.

then, howcome (c) is one of the correct answers for Q2?

thanks

-Kiennjal
Jeroen,

that's so thoughtful of you!

No humble deed goes unappreciated!

Have a good one.

-Kiennjal
20 years ago
for the first Q:


Q1: Assuming assertions are enabled, which of these assertion statements will throw an error?

a. assert true:true;
b. assert true:false;
c. assert false:true;
d. assert false:false;



I think it is (c) and/or (d) (is it select one or two answers?) because assert false will cause the assertion error.


Q2: Given the following command, which classes would have assertions enabled?
java -ea -da:com... net.example.LaunchTranslator

a: com.example.Translator
b: java.lang.String
c: dot.com.Boom
d: net.example.LaunchTranslator
e: java.lang.AssertionError



As per my understanding: a,c,b,e: disabled, d: enabled

However, i wonder if b and e are also enabled, since it looks as if d is too obvious an answer!
your ConvertXXX() methods should have return type float/double.

Also, according to the question: i get an idea tht:

public float milesPerHour(Distances distance, float time)
{
//my understanding as per the problem: here is where u call the ConvertXXX methods using the object distance
//now u have float/double miles converted from yards and feet
//use these values to calculate rate (which btw, u are not doing)
// return rate
}

also, where are you calling this milesPerHour method?

hope this helps.

- Kiennjal
20 years ago
So according to Jim's explanation, I feel that both cases: # of objects: 2

Is that correct or not?



-Kiennjal
Can you post ur new code and also the question as specified in the book or wherever that you got it from... so that we can get a better idea.

Thank You

-Kiennjal
20 years ago
Prerna,

As Rick pointed out, you can perform the + operation only on string and numeric primitives. Your return type is an object: distances.

Secondly, you do not need to instantiate a new Distances in the same class, coz u can use the private variables (they are not local, they are instance variables) as they are.

Also, I didnt quite get the purpose behind declaring distance1 in the main method.

You need to change your methods and return types in Distances to make this function work.

Have a good one!

-Kiennjal

[ April 01, 2005: Message edited by: kiennjal shah ]
[ April 01, 2005: Message edited by: kiennjal shah ]
20 years ago
Jeroen,

K&B already provide CD with their Java Certification book. However, I am not sure if it functions the way game CDs function (play only while in the CD Rom types..).

Unfortunately, there is no fool proof way to prevent piracy, it can only be restricted/limited... and sometimes as Anselm popularity and sales increase by such kinda approach

What do you think?

-Kiennjal
20 years ago
If it does compile fine, then it prolly isnt a problem with ur classpath. However, while talking about classpath, have u set ur path and classpath correctly? (you could find your answer to this on the fAQ posted here)

Also, is main method defined correctly? make sure you do that and if it does accept any command line arguments, you are passing them when u actually run the code after compiling it.

Hope this helps.

Have a good one!

-Kiennjal
20 years ago


There are only two objects created on the heap in both the cases: s1 and s2.

Your code will not create two String objects for: String s2 = new String("b");
Hello,

I partially Agree with Anselm regarding putting a pdf version on the web for free of cost. However in order to keep the publishers happy and also maintain its uniqueness, the authors could prolly have some scheme like keep it available for readers on the web for a month or so and then if they like it, they can purchase it or maybe it should be made available for free to all JavaRanch members only... Also readers can donate if they wish to...

How does that sound?

As far adding color to the book...while I would like that (who wouldnt!!!) I dont think I would pay tht extra $5 ....I just make it colorful once I get the book home, with all my different marking pens...
Moreso, coz the content of the books by K&B normally is pretty interesting and well written that colors or no colors , I keep on reading!!!
[ March 31, 2005: Message edited by: kiennjal shah ]
20 years ago