Posts

public vs protected vs default access modifiers - Java

| Class | Package | Subclass | Subclass | World | | |(same pkg)|(diff pkg)| ————————————+———————+—————————+——————————+——————————+———————— public | + | + | + | + | + ————————————+———————+—————————+——————————+——————————+———————— protected | + | + | + | + | ————————————+———————+—————————+——————————+——————————+———————— no modifier | + | + | + | | ————————————+———————+—————————+——————————+——————————+———————— private | + | | | | + : accessible blank : not accessible

EJB - Spring vs EJB

 EJB is part of Java EE. Spring is a standalone framework which substitutes and improves many parts of Java EE. Spring doesn't necessarily require Java EE to run. A barebones servletcontainer like Tomcat is already sufficient. Simply put, Spring is a competitor of Java EE. E.g. "Spring" (standalone) competes EJB/JTA, Spring MVC competes JSF/JAX-RS, Spring DI/IoC/AOP competes CDI, Spring Security competes JAAS/JASPIC, etc.

EJB - Stateful vs Stateless

For  stateless session beans  the server can maintain a variable amount of instances in a pool. Each time a client requests such a stateless bean (e.g. through a method) a random instance is chosen to serve that request. That means if the client does two subsequent requests it is possible that two different instances of the stateless bean serve the requests. In fact there is no conversational state between the two requests. Also if the client disappears, the stateless bean does not get destroyed and can serve the next request from another client. On the other hand a  stateful session bean  is closely connected to the client. Each instance is created and bounded to a single client and serves only requests from that particular client. So happens that if you do two subsequent requests on a stateful bean, your request will be served always from the same instance of the bean. That means you can maintain a conversational state between the requests. At the end of the li...

Java - Thread join

In this code, what does the two joins and break mean?  t1.join()  causes  t2  to stop until  t1 terminates? Thread t1 = new Thread ( new EventThread ( "e1" )); t1 . start (); Thread t2 = new Thread ( new EventThread ( "e2" )); t2 . start (); while ( true ) { try { t1 . join (); t2 . join (); break ; } catch ( InterruptedException e ) { e . printStackTrace (); } } There is a thread that is running your example code which is probably the  main thread . The main thread creates and starts the  t1  and  t2  threads. The two threads start running in parallel. The main thread calls  t1.join()  to wait for the  t1  thread to finish. The  t1  thread completes and the  t1.join()  method returns in the main thread. The main thread calls  t2.join()  to wait for the  t2  thread to finish. The  t2  thread complet...

Garbage collection question - Java

class A { Boolean b ; A easyMethod ( A a ){ a = null ; // the reference to a2 was passed in, but is set to null // a2 is not set to null - this copy of a reference is! return a ; // null is returned } public static void main ( String [] args ){ A a1 = new A (); // 1 obj A a2 = new A (); // 2 obj A a3 = new A (); // 3 obj a3 = a1 . easyMethod ( a2 ); // a3 set to null and flagged for GC - see above for why a1 = null ; // so far, a1 and a3 have been set to null and flagged // Some other code } } Two objects are eligible for garbage collection (a1 and a3).  b  is not because it's only a reference to null. No  Boolean  was ever made. To get around the inane subtleties of what  // Some other code  might be, I instead posit the question be reworded into the following: Prdict and explain the following output: class A...

Class, Reference and Object

If you like housing metaphors a  class  is like the blueprint for a house. Using this blueprint, you can build as many houses as you like. each house you build (or instantiate, in OO lingo) is an  object , also known as an  instance . each house also has an address, of course. If you want to tell someone where the house is, you give them a card with the address written on it. That card is the object's  reference . If you want to visit the house, you look at the address written on the card. This is called  dereferencing . You can copy that reference as much as you like, but there's just one house -- you're just copying the card that has the address on it, not the house itself. Java methods are always pass-by-value, but the value could be an object's reference. So, if I have: Foo myFoo = new Foo (); // 1 callBar ( myFoo ); // 2 myFoo . doSomething () // 4 void callBar ( Foo foo ) { foo = new Foo (); ...

Hibernate 'hql' does not support UNION - Hibernate

So in this case run each query individually using 'HQL' and then add the results to a HashSet