• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Some Queries

 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jignesh Gohel
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for such a clear & elaborate explaination.

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

Thanks,
Jignesh
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Jignesh Gohel
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic