Sanjit Kumar

Ranch Hand
+ Follow
since Dec 04, 2006
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
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sanjit Kumar

hi everyone,
Help me out, i got the error while writting generic dao class, saying jre5 is needed(i have jre6).
Has java 6 excluded parametrized type collection???

public interface GenericDAO<T, ID extends Serializable> {

T findById(ID id, boolean lock);
List<T> findAll();
T makePersistent(T entity);
void makeTransient(T entity);
void flush();
void clear();
}
[ March 10, 2007: Message edited by: Bear Bibeault ]
Thanks Philip for clearing my doubt.
Please guide me how to implement connection pooling in my application and what additional jar file i will have to include to make it working.

I am using following tools and software:
Application Server : jboss-4.0.5.GA
Editor : Eclipse-3.2.1
Java SDK : jre1.6.0
DataBase : MySQL

All are open source softwares.
11 years ago
Hi to everyone,

i am having following problem.please help me out.

I am retrieving context-param values in contextInitialized() method.
Those values are : databaseUrl(bdUrl), database driver, userName, passWord

Then created one Connection instance named "con".

My question is : Will the connection "con" be alive for all the resources in the corresponding web application.
The code for the contextInitialized given below:

private ServletContext context = null;
Connection con = null;

public void contextInitialized(ServletContextEvent sce){
this.context = sce.getServletContext();

String driver = context.getInitParameter("driver");
String url = context.getInitParameter("dbUrl");
String user = context.getInitParameter("login");
String pass = context.getInitParameter("password");

try{
//Class.forName("org.gjt.mm.mysql.Driver");
Class.forName("com.mysql.jdbc.Driver").newInstance();

con = DriverManager.getConnection(url, user, pass);

}catch(Exception ex)
{
System.out.println("Error in connection :"+ex.toString());
}

}
[ February 07, 2007: Message edited by: Bear Bibeault ]
11 years ago
Hey guys last two questions really don't fit for this category(SCJP) but the first one is really nice and it would be nice if you guys please explain "how JVM treats (regarding storing in memory etc..) final and non-final variables(local or instance).
11 years ago
Hi Victor, It seems you still have some problem in understanding of concurrency issues.

Every Threads share instance variables not local variables.So for thread t2 if condition does not get true, so small k remains 100 and since capital K is shared so its value got changed by thread t1. That's why you are getting
100 200 for thread t2.
------------------------------------------------------------------------------
No one is intelligent by birth
Hi Victor, It seems you still have some problem in understanding of concurrency issues.

Every Threads share instance variables not local variables.So for thread t2 if condition does not get true, so small k remains 100 and since capital K is shared so its value got changed by thread t1. That's why you are getting
100 200 for thread t2.
Thanks henry......... for good explanation. You are good in explaining things.
1> How does system(or compiler) calls run() method when we call start() method???
My guess is start() method is run() method from inside like this
public static void start(){
run();
}

Is start() method implemented the same way as i have written above ???
2> When we give our own implementation of start() method in class one which extends Thread class and another which implements Runnable interface.

After instantiating thread th1, when we call th1.start() then it is calling our own start() method for the class which extends Thread Class
but same is not true for the class which implements Runnable interface.

Please explain the above bizzarre behaviour.
Thanks
While going through the JAVA-doc-API, i got the following doubt.

public static List synchronizedList(List list)
The above method returns a synchronized list i.e. the list is threadsfae.

1> Since the returned collection is thread-safe then why do we need to implement synchronization explicitly while iterating or doing other operation.

2> What is the difference between an Vector() object and the List object created using Collections.synchronized() method.

Do we need to synchronize explicitly when we do iteration on vector object and the list object (created using Collections.synchronized() .???

Please clear the above doubt.
Thanks in advance
Hello Barry Gaunt,
Can you please make the option (a) more clear.
AND
IS "invoking garbage collector explicitly " same as "forcing the garbage collector"???

Q> Can we force garbage collector? [T/F]
The reason might be that one thread is gettign enough time to complete the for loop, so it is printing the same result even after removing the synchrinized block.

If you make your loop to iterate through 1000 times then we may get the result in unpredictable way after removing the synchronized block.
I guess Barry Gaunt is wrong. The compilation error is coming due to the fact that Exception is of kind "Checked Exception" and it must be handled using try/catch block when called or must be ducked with main().
----------------------------------------------------
Originally posted by Ankur Grover:
I think the compiler is giving error at this point.

public void displayInt() {
System.out.println("i in SubA "+i);
}

compiler is unable to decide weather you want to retrieve SubA.i or SuperClass.i.
-----------------------------------------------------
This will simply shadow the superclass variable i meaning when overriden method is bieng executed then simple the sub class variable i will be printed.

SuperClass objSuper1=new SuperClass(10);

SubA objSubA=new SubA();

objSuper1=objSubA;

System.out.println(objSuper1.i);
Now the superclass variable i will be printed as instance variables are never overriden.

If i am wrong please make y concept correct. And If Barry Gaunt is wrong then it is really very disappointing that such and old member(status bartender) is making mistake and giving wrong concepts to newbie.
While goiing through the K&B certifivcation book, I found the following code and lines:
FIRST : public int hashCode() {return name.length(); }
SECOND: public int hashCode() {return 4; }

It was written in the book that SECOND hashcode method is slower than the FIRST hascode.
What does it means of saying faster(or slower) hashcode in the present context??
Please explain if anyone having clear idea of this.
Thanks in advance.
--------------------------------------------------------
There is no fall through in the above code. You simply use your basic if else concept and you will get the correct answer.