Rupesh Mhatre

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

Recent posts by Rupesh Mhatre

remove <!doctype html> and try
In simple terms local variables get preference over instance variable.
13 years ago

john price wrote:java.lang.StringIndexOutOfBoundsException: String index out of range: 0


In this case you are getting empty String thats why you are getting StringIndexOutOfBoundsException.

In first case just check whether your firewall is blocking the port you are using.

nirjari patel wrote:sName is declared as static, that is one per class. So if I modify sName value in anywhere in the class, will it not be affected ? Thats why I am confused, that when a variable is static, how come the vaue is not affected ?


As already said local variables always shadows instance variables.
public void nameTest(String sName) and in this method definition you are passing parameter as sName which becomes local variable for nameTest method and it does shadow instance variable sName evenif it's a static variable.

nirjari patel wrote:String s1 = "hello";
s1 = s1 + " world" ;
when we do this, does s1 refer to a new object ? Does it mean that String which s1 referred to earlier (hello) becomes garbage collectible ?


yes s1 does refer to new Object and yes String which s1 referred to earlier (hello) becomes eligible to be garbage collected
13 years ago

Jesper de Jong wrote: It will not be easy to understand it, however, because the JVM is a large and very sophisticated piece of software that has been under development for 15 years.


Thats the real trouble but thanks anyways i will make this thread as resolved.
13 years ago
any suggestions please.
13 years ago
String is always immutable.
You are getting confused with local variable and instance variable.

nirjari patel wrote:
public void nameTest(String sName){
sName = sName + " idea ";
//start();
}


In this case variable sName is local variable which does shadow the instance variable sName. As sName is local variable in this case scope of it is limited only for that method and instance vaeiable sName still pointing to "good", hence the result
Output : good
----------------

nirjari patel wrote:
Now when I am using name in place of sName in nameTest(), sName output is changing as follows

public void nameTest(String name){
sName = name + " idea ";
//start();
}


In this case local variable name is name and you are assigning value to instance variable i.e. sName hence the
Output : good idea
---------------------
13 years ago
Naina Excellent work Congrats.
13 years ago

Himanshu V Singh wrote:

But Method can be accessed via object of the class, why is it so, please guide me with a brief explanation ?



It has very simple reason static members are class level members and you don't need instance for that and non static members are instance specific so they need instance to get called so in your case if run method had been static method then you could use it without creating any instance like TryCatchTest.run();. Now as your run method is not static so it is a instance specific method so when you call it from static method i.e. main method you get compiler error saying non-static method can't be referenced from static context. I guess this will help.
13 years ago
If these strings are getting created once in while its ok but still Nobody will recommend you this implementation. If you want your code to be more readable and easy to understand please make use of comments like
myBean.setName(message[1]); // name
myBean.setAddress(message[2]); // address

This will help code to be easily maintained.
13 years ago



I think this should help
13 years ago
Thanks for reply

Rob Spoor wrote:The way it works now is pretty good.


Thats absolutely perfect and we all aware of this.

Rob Spoor wrote:It does compile the byte-code internally, but when the JVM exits that data is discarded again.


Now here is my confusion does it compile every time when particular resource is demanded for or does it do it only for once or how?

Rob Spoor wrote:Because that means you will have to compile your code for each platform.


This is what JVM does for us for any platform, thats fine. Now the same question again does it compile code every time for same resource again and again e.g. if we create String Object 100 times will JVM convert byte-code for String to binary 100 times?

Rob Spoor wrote:Or perhaps I understood you wrong. Did you mean that the JVM uses byte-code for each class, but compiles that internally and stores that somewhere to use it for future use?


thats the question for which i am searching answer for.

Rob Spoor wrote: If so, then that has some overhead too. If the class changes the JVM would need to check if the compiled data is still up-to-date.


wont those overheads will be lesser than converting byte-code to binary, if it does this again and again?

Rob Spoor wrote:And what about the storage required if the JVM has encountered hundreds of classes?


True i had not thought of this.
13 years ago
Hi all,
Please correct me if I am wrong
As we know we have separate JVM for separate platform and our byte code gets converted to binary code at runtime whenever JVM needs to execute particular code it searches for it, interpret Java byte code and translate this into actions or Operating System calls using JIT compiler.
If this is true then my question is why don’t JVM uses same binary file which it already created (obviously we can maintain version of those) and will is not improve application performance?
13 years ago
request.isRequestedSessionIdValid() will give you boolean return if session is valid. As Bear Bibeault has already explained this can not happen automatically and you have to set JS timer for that nut using this atleast you can take care that if user is on the same page till timeout happens and try making new request it will redirect user to your session expire page for this you have to place your code inside the if block having this check condition.
13 years ago
You can use request.isRequestedSessionIdValid()
13 years ago