Chandra Bairi

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

Recent posts by Chandra Bairi

HI All,

When we write the return statement in the main method where would the control go to?
20 years ago
Dear all,
I have a doubt regarding the static and instance methods. A class has static and instance methods. And the difference is that since object creation is expensive we can use static methods .
Now why can't we make all the methods static and why do we need instance methods if et all? Why not make all the methods static? And just like the properties for an object are different for each object are the instance methods different for each object or are they located at one place in the memory which would be accessed by different objects.
20 years ago
Thanks for the reply
It is working fine. but i still have some problems with the following code.
import java.util.*;
public class TestObs{
public static void main(String[] a){
Worker worker = new Worker();
supervisor shekar = new supervisor();
worker.addObserver(shekar);
supervisor shekar1 = new supervisor();
worker.addObserver(shekar1);
supervisor shekar2 = new supervisor();
worker.addObserver(shekar2);

System.out.println(" No of observers :"+worker.countObservers());

worker.setValue(50);
System.out.println(" Has change :"+worker.hasChanged());
}
}

class supervisor implements Observer {
public void update(Observable o , Object arg){
System.out.println("Object has changed");
}

}
class supervisor1 implements Observer {
public void update(Observable o , Object arg){
System.out.println("Object has changed1");
}

}
class supervisor2 implements Observer {
public void update(Observable o , Object arg){
System.out.println("Object has changed2");
}

}
class Worker extends Observable{
public int i=10;
public void setValue(int val)
{
i=val;
setChanged();
// System.out.println(" Has change :"+worker.hasChanged());
notifyObservers();
}
public void notifyObservers()
{
super.notifyObservers();
System.out.println(" Look boss, I'm doing some work!");
}
}

In the above code when I have added more than one observer for all the observers the update method in supervisor is getting called. I guess this is wrong because the corresponding observer's method should be called. Also when I say hasChanged it is giving the value false.
What could be problem and will update of every observer execute or only the update of particular observer exectutes for the changes .

thanks and regards,
shekar.
20 years ago
Consider the following piece of code...
import java.util.*;
public class TestObs{
public static void main(String[] a){
Worker worker = new Worker();
supervisor shekar = new supervisor();
worker.addObserver(shekar);
worker.i=50;
System.out.println(" Has change :"+worker.hasChanged());
}
}

class supervisor implements Observer {
public void update(Observable o , Object arg){
System.out.println("Object has changed");
}

}
class Worker extends Observable{
public int i=10;
public void notifyObservers(){
System.out.println("change has occured in the observed object");
}
}

in the above code i have changed the data in the observable object worker, i.e the value of i to 50. This is a change in the data of the observable object. When i do that the notifyObservers should run and the hasChanged method should return a true value but the value that is returned is false.
How can I correct my method or is there something missing with my understanding. Kindly help me out if I have understood the observable correctly.
Thanks and regards.
shekar.
20 years ago
If you are entering the wrong password then you would surely not get the connection and hence the error.
but for the arrayindexoutofboundexception you should give the complete code. because i am unable to under stand the problem seeing only that part of the code. kindly present the complete code.
regards,
shekar.
20 years ago
I could not get how it would happen.
because
when you say DriverManager.getConnection() we get the connection object which is a connection(interface) object. but driver manager object never implements statement object. and statment is again an interface and where does it implement the executequery methods. what is the total way of executing and where does the method definitions come
can you explain a bit clearly.
thanks and regards
shekar.
20 years ago
This is one of the very good questions asked. Marker interface does not have any methods. This is true. the basic thing is that when we implement a marker interface the java compiler notes that it has implemented a certain interface and it will try to assign some properties to the class that implemented it. Like if SingleThreadModel interface is implemented then there may be some variables which will get attached to the class and whenever the objects of these classes are accessed the variables which exist in the marker interface may come into picture. these will help in keeping the object accessed by the users one at a time as SingleThread model does. kindly correct if I am wrong.
regards,
shekar.
20 years ago
import java.lang.reflect.*;
public class Test
{
public static void main(String[] args)
{
try
{
Class c = Class.forName("Foo");
System.out.println("Loaded class: " + c);
Method m = c.getDeclaredMethod("getNum", null);
System.out.println("Got method: " + m);
Object o = m.invoke(null, null);
System.out.println("Output: " + o);
Foo.getNum(null,null);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
class Foo
{
public static int getNum()
{
return 5;
}
}
consider the above code.
How could the output for this program come correctly 5. What could be reason when the getNum() method is called with null, null as parameters it is called perfectly why did this happen.
regards,
shekar.
20 years ago
what will be the case if i use a java bean instead of stateless session bean.

regards,
shekar.
20 years ago
I am using a stateless session bean. Will there be a performance problem in this case.
shekar.
20 years ago
I am using singleton pattern because the first time I create an object of that class it will look up in the constructor of the class. But the next time another uses tries to create an object of the class he need not again go to the constructor and do the lookup. this would reduce the lookups to only one. So this would be the advantage of creating a single object. But because of the creation of only one object does the following happen.
When A logs in he creates the instance of the class and looks up the EJB and he calls some methods in the same ejb. will he keep the object with him until and unless he executes all the methods.
Therefore when user B logs in just after A he cannot get the instance of the class because user A already has acquired it and until and unless the user A releases it user B cannot get it. this would be same case for 10 users. I guess this would result in low performance. Is the reasoning correct. What should be the way I should be dealing with it so that the look ups for the session bean are very less and performance is more.
any help will be of great help.
thanks and regards,
shekar.
20 years ago
Hello friends,
I have an application where I have used the authentication mechanism. Now in the authentication mechanism I have a class WBCredentialVerifier. I have implemented singleton pattern where I created a single object and this object is created will look up the EJB object . I have used the singleton pattern to facilitate the looking up of the object only once. Now will this be a bottle neck if more than one user is accessing the business methods of the object because this will be only a single object. This has been a performance issue.
Regards,
shekar.
20 years ago
hello friends,
I have a page where an applet has to be displayed. Now i want to display an error message when the applet is not displayed (i.e if the IE or NN does not enable applets)on that page. How will I know if the browser is configured for applets or not?
Thanks and regards,
shekar
20 years ago
Java class : A java class is a class which normally has properties and methods through which these properties are modified. The class can perform some functions specific to the data in the class.

Java Bean: java bean is also a java class but its basic use is for storing the state of the class , i.e it has properties and there are setter and getter methods. This class is basically used for storing the state of the data and then retreiving the state at a later point of time. Even java bean is also a class.
java bean can be said as a class which normally does not have processing logic. It is however not illegal if the java bean contains processing logic.
regards
shekar.
20 years ago
Dear friends,
I have an application which has a search mechanism similar to the search in google. Now when I enter the expression and click on the search button I need to get the first 10 results and then when i press the next button the next ten results should be displayed. Similarly when I press the previous button the previous 10 records should be shown.
I am planning to get the result set and then store them in a model class and put them in he arraylist and then retreive the results one by one keeping the lower limit and upper limit in the session.
when I showed this approach my Pl was not satisfied. He asked me to do it in another way. Is there any way where I can traverse the records in a better way.
Thanks in advance
shekar.
20 years ago
JSP