Win a copy of Java by Comparison (eBook) this week in the Java in General forum!

Harshit Rastogi

Ranch Hand
+ Follow
since Apr 15, 2008
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 Harshit Rastogi

Paul Clapham wrote:Or, to put it more simply, the file is in the root directory of the jar? Then...

yes it worked. the file is already in the root. thnx
7 years ago

I have following structure in jar

myjar.jar -> com -> MYProgram.class
-> file.txt

The file.txt is inside the myjarar.jar and parallel to com folder..
In MYProgram i am trying to do:

I am getting NullpointerException when i try to read the inputstream..

Where is it going wrong ?
7 years ago
Objects created by new operator and global variables are stored in heap..

All local variables created inside methods are stored in stack...
Advantage of using enum:

1) can you in the switch case
2) can use the properties of an Enum class like using constructor etc
3) no need to implement the enum. can be used as an other class imported.

Prefer Enum only when all the constants belong to same category,. like No of days, Currencies etc.
8 years ago
while overriding the method the scope/access of the method cannot be more restricted.

For eg, in your case the protected method can be overriden with public and protected modfier. if you put private, compile time error will be there

similarily public method cannot become protected ...
8 years ago
Check out the question 4,5 & 6 . I hope this would help
Abstract class and interface
8 years ago

Change this to

you should always use the interface class . Thats a good practice. Because if in case you want to change it to Vector simply change the implementation
8 years ago
The second line is giving false because you have overloaded the equals method and not overriden, so in 2nd case the Object class equals method is called.

change your equals method to

please see the following code.

I know that line 3 will still point to "Monday" and have a new String object with the offset and count set to 0,3.
The line 5 will create a new String "Mon" in string pool and point to it.
But not sure what about line 6 whether it will behave like line 3 or line 5.

If i am wrong for line 2 or 4 also please correct..
9 years ago
i think it will depend on the available meomry in heap of JVM...
9 years ago
Hi ,

First question why do you need vector. IF your application is not multithreaded use arraylist.You can put an arraylist or array in an Arraylist .

I would recommend instead of using newList object create a Car class with all the properties in it . save the data in Car object and add it to the list.
9 years ago
Static methods are typically used for utility classes. Consider Math class though the class is final but all methods are static and doesnt needs an instance to access methods. If in case it had not been I can extend Math class and shadow or hide the method of Math class and implement mine in the custom class.

Overriding is done for instance methods and you can take any example in real world...

9 years ago
you can go through this link also :Use of hashcode and equals
9 years ago

Panumat Wiwatmaikul wrote:
At this time, "abc" and "def" will be eligible to GC.

Correct me if i misunderstood.

the String object are not eligible for GC. String "abc" is created in a heap but it has a reference in the String pool which is used by the String objects. But is string object is set to null, still a reference is present in string pool for further reference by an other variable.
Check this javaranch link on Strings :String literal