Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

java doubts

0 views
Skip to first unread message

amar...@gmail.com

unread,
Jul 8, 2008, 9:13:04 AM7/8/08
to
hi,

what we call a concrete class in java api with out constructors(Like
DriverManager)?

detail data about protected constructor. Can we have protected class?

why all exception classes implementing the serialzible interface?

what is the difference between the "A class by defaultly
synchronized(Vector)" and "A class which is manuvally synchronized"?

Roedy Green

unread,
Jul 8, 2008, 12:32:17 PM7/8/08
to
On Tue, 8 Jul 2008 06:13:04 -0700 (PDT), amar...@gmail.com wrote,
quoted or indirectly quoted someone who said :

>what we call a concrete class in java api with out constructors(Like
>DriverManager)?

Class with private or protected constructor.

>detail data about protected constructor. Can we have protected class?

Try the experiment.

>why all exception classes implementing the serialzible interface?

It was possibly for a program like Lotus Ensuite, that could save the
program state, do something else, then pick up where it left off. It
used serialisation to encapsulate the entire state of the app.
The other reason is it was easy to do. Exceptions don't have much
inside them.

>what is the difference between the "A class by defaultly
>synchronized(Vector)" and "A class which is manuvally synchronized"?

It is the difference between using Vector and ArrayList+
Collections.synchronizedCollection( a );

or Hashtable and HashMap + Collections.synchronizedCollection( a );

or doing the threading manually, only where needed.

see http://mindprod.com/jgloss/arraylist.html#THREADSAFETY

Normally you have onely one thread, so there is no point in the sync
overhead.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Arne Vajhøj

unread,
Jul 8, 2008, 5:15:59 PM7/8/08
to
amar...@gmail.com wrote:
> what we call a concrete class in java api with out constructors(Like
> DriverManager)?

DriverManager only expose static members so you could not do much
by constructing one.

You can not. Not because it does not have a constructor - that is not
possible - even if you do not create one because then it will
get the default. But because SUN has made the constructor private.
Small service to prevent programmers from doing silly things.

> detail data about protected constructor. Can we have protected class?

Top level : no

Sub class : yes

> why all exception classes implementing the serialzible interface?

Because they will often be send over the wire for remote calls
like RMI and remote EJB calls.

> what is the difference between the "A class by defaultly
> synchronized(Vector)" and "A class which is manuvally synchronized"?

The first is thread safe for single calls out of the box (but not for
many real world situations). For the latter you need to do something
typical Collections synchronizedXxxx for single call or more practical
synchronized on something to make more than one call safe just like you
have to for the first.

Arne

Lew

unread,
Jul 9, 2008, 12:31:45 AM7/9/08
to
amar...@gmail.com wrote:
>> what is the difference between the "A class by defaultly
>> synchronized(Vector)" and "A class which is manuvally synchronized"?

Arne Vajhøj wrote:
> The first is thread safe for single calls out of the box (but not for
> many real world situations). For the latter you need to do something
> typical Collections synchronizedXxxx for single call or more practical
> synchronized on something to make more than one call safe just like you
> have to for the first.

There are, of course, other differences between Vector and another List
implementation like ArrayList (its closest true-collections cousin) besides
that one has its methods synchronized for you and other does not.

--
Lew

0 new messages