Newbies doubts on Java

T

Tanuki

Hi All:

I am mainly a C++ programmer. Recently, I need to do cross platform
development work and Java came across my mind. My worries are as
follows:

1. Is Java suitable as a language to develop software application in
an operational environment? My company needs to run application 24hrs
a day and 7 days a week (ie. non stop). I have heard that Java is
slower than C++ and Java has a larger memory footprint as compared to
C++. Are these true?

2. I have came across wonderfully written Java applications that works
smoothly. May I know is there any tips or tricks whereby one can
follow to streamline a Java program, such as conforming to certain
architecture or design principles etc.

Thank you for your time in answering these naive questions.
 
T

Tim Ward

Tanuki said:
I am mainly a C++ programmer. Recently, I need to do cross platform
development work and Java came across my mind. My worries are as
follows:

1. Is Java suitable as a language to develop software application in
an operational environment? My company needs to run application 24hrs
a day and 7 days a week (ie. non stop). I have heard that Java is
slower than C++ and Java has a larger memory footprint as compared to
C++. Are these true?

You do have to understand the garbage collector, it appears. If you're
perfectly happy to go back to the days of tuning config.sys then you should
be happy with tweaking the garbage collection.
 
H

Harald Hein

Tanuki said:
1. Is Java suitable as a language to develop software application
in an operational environment? My company needs to run application
24hrs a day and 7 days a week (ie. non stop).

Yes, in the same way a C++ application can do the job. There are
sometimes bug in C++ compilers and libraries, and there are sometimes
bugs in the Java compiler, VM (virtual machine) and API implementation.
In both languages you might not notice, or you might run into a
showstoper for your application.
I have heard that
Java is slower than C++

No. Benchmarks usually show that they are on pair by average, if a
recent Java implementation is used. Java applications typically have a
longer start up time, because the VM has to start, and the JIT (just-
in-time) compiler might also take some time. Once up and running,
things are usually the same.
and Java has a larger memory footprint as
compared to C++.

Well, the VM needs additional memory, and usually there are many object
instances involved in a Java application (some Java APIs tend to be
generous with objects). So yes, a Java application can need more memory
compared to a C++ application.

You also see a different memory allocation behavior, because the
garbage collector runs things behind the back of the application.
2. I have came across wonderfully written Java applications that
works smoothly. May I know is there any tips or tricks whereby one
can follow to streamline a Java program, such as conforming to
certain architecture or design principles etc.

If you are a good programmer, you can do that, too. I sometimes have
the feeling that Java is a little bit less forgiving regarding a bad
application architecture than e.g. C++. This might be an illusion. On
the other hand, there are a lot of possible hacks one can do in C++ to
partly compensate for a bad architecture, while a lot of that stuff has
been taken away from Java (no void *, no unions, no preprocessor ...).

So if you mess it up in Java, you better fix the root-cause of the
problem instead of hoping that you can work around it.
 
P

Peter Ashford

Tanuki said:
Hi All:

I am mainly a C++ programmer. Recently, I need to do cross platform
development work and Java came across my mind. My worries are as
follows:

1. Is Java suitable as a language to develop software application in
an operational environment? My company needs to run application 24hrs
a day and 7 days a week (ie. non stop). I have heard that Java is
slower than C++ and Java has a larger memory footprint as compared to
C++. Are these true?

2. I have came across wonderfully written Java applications that works
smoothly. May I know is there any tips or tricks whereby one can
follow to streamline a Java program, such as conforming to certain
architecture or design principles etc.

Thank you for your time in answering these naive questions.

I've done development commercially in C,C++ and Java. IMO Java is fine
for most applications. It does have a slower startup phase than a C++
app, performance might be down by say, 5-10% depending on the
application and memory usage will be higher - but by a constant one
one-off ammount (i.e. add 4MB or so to your application for JVM internals)
 
S

Scott Ellsworth

I am mainly a C++ programmer. Recently, I need to do cross platform
development work and Java came across my mind. My worries are as
follows:

It is a good place to work.
1. Is Java suitable as a language to develop software application in
an operational environment? My company needs to run application 24hrs
a day and 7 days a week (ie. non stop). I have heard that Java is
slower than C++ and Java has a larger memory footprint as compared to
C++. Are these true?

Yes and no. There is VM overhead, and the compliers are often a bit
weak, so that the out of the box code is slower. The just in time
compliers, on the other hand, often optimize surprisingly well.
Further, they work on the most critical sections of your code as it is
used, which makes it much faster in real world terms than indifferent
C++ code, and equally fast for good C++ code. (Note - the server VM has
a better JITC than the client, IME.)

Experts optimize for speed and space. C++ gives some great tools to do
that, which keeps the developer in control of their app. Java also has
good tools - I find the profilers better on the Java side, as well as
the testing tools. Good profilers and good tests improve code, often
better than design principles.

That said, an expert Java developer can often produce more functionality
in a given time, because the libraries and gc save so much effort. They
then can spend their time optimizing those things that need to work, and
thus they may end up with better code.

(This has been my experience, at least, and I have done both.
Windows/C++ for seven years, Java for six years.)
2. I have came across wonderfully written Java applications that works
smoothly. May I know is there any tips or tricks whereby one can
follow to streamline a Java program, such as conforming to certain
architecture or design principles etc.

Profiling and designing for performance at the proper times are your
friends. For example, know your performance goals, and make sure you
test them from the first. Then, do not optimize until the code _works_.
(In other words, fast broken code is not worth the effort.)

Test everything that matters to your app. This allows you to dramatic
restructuring if your app needs it without risking terrible breakage and
an unfixable mess.

These last two principles are major parts of what I do professionally.
First test that it works, then test that it works quickly, then profile
to understand why it works the way it does.

Scott
(e-mail address removed)
Java, Cocoa, WebObjects, and Database consulting
 
J

Jose Rubio

See my response in the comp.lang.java.help group. Please try not to post to
multiple groups as you may loose some responses to your question.

Jose
 
D

Dale King

Tanuki said:
2. I have came across wonderfully written Java applications that works
smoothly. May I know is there any tips or tricks whereby one can
follow to streamline a Java program, such as conforming to certain
architecture or design principles etc.


The key thing to having a responsive GUI is to understand the threading
model of AWT/Swing and making sure you are doing things on your own thread
and not the AWT thread. This is not an issue with Windows programming for
instance because you are isolated from the GUI threads by a queue.

For instance see these articles:

http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html
http://java.sun.com/products/jfc/tsc/articles/threads/threads2.html
http://java.sun.com/products/jfc/tsc/articles/threads/threads3.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top