aspose file tools*
The moose likes Beginning Java and the fly likes Some Queries Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Some Queries" Watch "Some Queries" New topic
Author

Some Queries

Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
Hi,

I would like to know answers to some of the questions mentioned below:

1) Why Java programs are compiled & then Interpreted..What's the reason behind it & what's the advantage of doing this??

2) Java compiler is written in which language like C compiler was written in Assembly language??

3) I have not done much programming in C & C++.But sometimes i'm asked that what are the things that can be done in Java that cannot be done in C & C++??

4) Is it possible to do Lower-level programming with Java??
If yes then what are the sources to learn that(i.e site's addresses,books,etc)

5) What's the alternative in Java for pointers in C?

Thanking you,
Jignesh


Regards,
Jignesh

The Art Of Life Is To Know When To Be Useless And When To Be Useful - CHUANG TZU
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

I can answer a few of these...

1) portability. If you write a program in C, you need to compile is on every platform you want to deliver it on. You need to send the correct executable to each machine.

In java, since every physical machine will have a JVM, you can hand every machine the same compiled java code, and it will run.

Now, this may not SOUND like a big deal... until you think about the web. If i write something and want it to run in a browser, it's gonna be awful dang hard to have all those executables hanging around, figure out what version of what OS each machine has, send them the RIGHT one... OH, and then some NEW company comes out with a machine i've never HEARD of...

with Java, i have one file for everyone. Those new machines - odds are pretty good there will be a JVM for it if they want it to succeed. so i need to do NOTHING, and my program will work on it.

That is pretty cool.

2) i think for the first step, it was written in assembly, but then in Java. It's a technique called Bootstrapping.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
Hi,

Thanks for the reply.

I didn't got the first one clearly.I want to ask that after compilation it is being interpreted using "java ProgramName" wher java is an interpreter,right??.

Now what is the need of this interpreter after the program is being compiled.??

& what is its advantage??

if possible please solve my other queries also??

Thanks,
Jignesh
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

A language like C gets compiled to machine code. These are the basic instructions a CPU can understand. the compiled C code is fed directly in, and the CPU runs it.

Java is compiled into what is called java bytecode. It is not machine language, so no actual machine can understand it. BUT, each physical machine has a JVM - a Java Virtual Machine. this 'virtual machine' DOES understand bytecode, and it's job is to convert the bytecode into machine code, which in turn gets fed to the CPU.

the advantage is what i mentioned above - portability. I write the code once. i compile it once. i have the SAME file i send to EVERYONE, and EVERYONE can run it.

With a language like C, i need the compilers for EVERY machine i want to support, and i need to spend the time compiling and maintaining them.

if you supported 30 Operating Systems, would you rather compile the same code 30 times on 30 different machines, and send the correct one to each customer, or would you rather compile it once, and send the same file to everyone?
Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
Hi,

Thanks for such a clear & elaborate explaination.

But there are queries still remaining!!!
So please let me know regarding that.

Thanks,
Jignesh
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
Some more answers

3) There is really nothing that can be done in Java that can't be done in C/C++.

4) Yes, but how you do it depends on what lower level programming you are doing. Probably the most common way to do low level programming through Java is using JNI (google should have alot on that). If you use JNI you will be writing C/Assembly code and wrapping that with Java.

5) None. There are no pointers in Java as there are in C. No pointer arithmetic, no referencing/de-referencing. In Java you have a 'reference' to an object that is similar to a pointer, but you can't manipulate it.
Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
Thanks Steven for all you cooperation.
But one thing again for that 3rd query it s vice-versa of the original thing i.e. is there anything that can be done in C/C++ & not in Java???

Thanking you
Jignesh
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
As far as Java and C++ ... Another reason many people prefer Java is it lets you focus more on the business problem at hand and less on the housekeeping of managing memory, destroying objects, manipulating pointers, etc. It has a simpler syntax and fewer opportunities to hit your thumb with a hammer for most problems. That speaks more to improving productivity (over the entire life cycle including years of maintenance) than what can be done in Java that cannot be done in c++
[ July 01, 2005: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
Hi,

But my question is there anything that CAN BE DONE in C/C++ & NOT in JAVA??

Also sir, if you could let me know that :

Can Java & Hardware be interacted directly like it can be done in C ???

Jignesh
Srilakshmi Vara
Ranch Hand

Joined: Jul 21, 2004
Posts: 169
1.
In c you can extend more than one class, in java you cannot extend, you can extend only one class and inherit multiple classes.

2. Pointers, there are no pointers in java, except few default pointers.
Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
Thanks all of you for your cooperation.

Now I would like to ask is that Can Java & Hardware can be interacted directly like in C ??

Jignesh
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
Originally posted by Jignesh Gohel:

Now I would like to ask is that Can Java & Hardware can be interacted directly like in C ??


Only under certain conditions and it depends on the hardware in question. In general the answer is 'not directly'. Java does not have direct access to the hardware. If you need to do direct hardware access you can write the direct hardware access in C and use JNI to do the rest of the program in Java. This does remove, or at least make more difficult, the cross platform benifits of Java.

There do exist embedded chips that have a JVM built in. These usually include some addition API for accessing the hardware directly.
Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
Hi,

Another thing i would like to know is that: I have read discussions regarding comparisons between Java & Other languages . There i frequently read that Java rules regarding Security.

Can anybody please help me get that thing that i what sense Java is Secure & how it acheives this purpose??

Thanking you,
Jignesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Some Queries
 
Similar Threads
Java performance measurements
Java language
How Scala faster than Java?
do you recommend C++ for an introductory programming course?
Is java internally written in C