• 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

Java support assembly Lang?

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does the java lang support for assembly pgming say similar to C++, with the intention to access the hardware? For example can a device driver be built in java for ethernet card or any other network devices?

If possible please guide a way, to let it be accomplished by me.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

No, Java can't access low-level hardware directly. It's possible to link in routines written in C or asm that do these things, but you can't do them from the Java language itself. The Java Virtual Machine is a fairly heavyweight thing, and because of its multithreaded nature and its nondeterminate garbage collector, you can't write real-time software in it.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Prathamesh Gaddam:
Does the java lang support for assembly pgming say similar to C++, with the intention to access the hardware? For example can a device driver be built in java for ethernet card or any other network devices?

If possible please guide a way, to let it be accomplished by me.



Yes, and No.... Yes, there is an assembler available for the Java Virtual Machine. With it, you can code directly in Java bytecodes.

However, No, the JVM doesn't provide the low level access needed to access hardware -- to the degree of writing a device driver. To do that, you need to escape Java, via the Java Native Interface (aka. JNI). This interface will get you to C/C++, which can be used to write device drivers (or even get to assembly, if you need to).

Google for the "Oolong Assembly Language" for the Assembler. And Google for "Java Native Interface" for information on JNI.

Henry
 
Prathamesh Gaddam
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Namaskar,

Sincere thanks to Henry and Ernest.

Henry, if java assembler can't directly make a low-level access, what's the use of the coding in bytecodes (reasons excluding speed, if any)?

Can it be used any way vide NetBeans editor?
(meanwhile I'll be surfing through the given search-keywords for JNI).
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Prathamesh Gaddam:
. . . what's the use of the coding in bytecodes (reasons excluding speed, if any)?

It verifies the code before execution, that it has compiled correctly.
It makes it harder to introduce malicious code.
It still keeps the code in a form which can be executed on any Java-enabled computer.
And other languages can create Java Bytecode from their compilers and run it on a JVM. There is an Eiffel compiler I know about which does that, for example.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell, I don't think you're answering the question that's been asked. You're answering "Why does Java use bytecode," but I think the question is actually "Why would you program directly in bytecode?"

The answer is, for the most part, you wouldn't. It's very rare. It's useful sometimes if you're generating code for the JVM; generating bytecode may be easier than generating Java source and compiling it. But Henry was just being helpful and complete. Java bytecode programming is in no way a substitute for machine code programming -- i.e., assembly language programming, as you originally asked about.

Can you use NetBeans to do bytecode programming? There's probably an add-on that will let you do it. But it's really not a mainstream thing to do, and as I said, it's rare and has little use. The most important bytecode-related skill is reading it, which can be helpful in debugging.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, Ernest. As you say, writing bytecode is very unusual, so it never occurred to me that the question meant that!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic