Thread: Java vs C to make an OS

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2007
    Location
    Tustin, CA
    Posts
    1

    Java vs C to make an OS

    Sorry if this is the wrong section. I'm new here and did not see a topic for Misc programming topics and its not in the FAQ one. Its either specifically this language or specifically not programming at all along with no Java sections. I picked C since thats the OS language I am assuming. Unix and Windows is C I believe and not C++. Thats not what I am asking though.

    I'm a beginner programmer. I'm learning C for a few reasons including its the OS language. One of my teachers at college thinks Java is the worlds best language and can do anything. I dont remember how it came up but someone said that Java can not make an OS. He said otherwise and because no one could specifically say why Java cant do that, he wins the argument. I really need to know why :P

    Can someone enlighten me on this?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Welcome, we actually use the Tech board for such questions, so this thread has been moved.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Java "can" make an O/S that would run off of a VM of sorts. Does that mean it's appropriate?

    You came to a C board, so the answer will probably be no.

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    As MacGyver said you'd need a VM. Java is interpreted by a VM, and you couldn't write the VM in Java 'cause you'd need a VM to interperate your VM.

    SunOS (Solaris) is mostly in Java, except the kernel. However the Kernel is the biggest component of the OS. So you could write an OS in Java, just not entirely in Java.

    I myself am not a fan of Java, and your teachers comment is rather narrow minded. Creating an OS that is run through a VM is stupid and slow.

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Quote Originally Posted by zacs7 View Post
    SunOS (Solaris) is mostly in Java, except the kernel. However the Kernel is the biggest component of the OS. So you could write an OS in Java, just not entirely in Java.
    Sun developed both Solaris and Java, but Solaris is definitely not written in Java in any way.
    Callou collei we'll code the way
    Of prime numbers and pings!

  6. #6
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Quote Originally Posted by QuestionC View Post
    Sun developed both Solaris and Java, but Solaris is definitely not written in Java in any way.
    I believe he's referring to the Java Desktop System, though, whatever he meant he clarified he was not talking about the kernel.

  7. #7
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    An OS is responsible for handling low-level hardware interfaces. Java doesn't provide any means for low-level access to hardware. Calling anything written in Java an Operating System is like calling Windows Explorer an Operating System.

    Besides, Java necessitates the presence of virtual machine. The OS is responsible for loading and providing memory for the virtual machine. If the OS is written in Java, you end up with a very nasty bootstrap problem.
    Callou collei we'll code the way
    Of prime numbers and pings!

  8. #8
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You can't write a complete OS in C, much less Java. I shudder to think how slow it would be if it were coded in Java.

    If you want information on programming operating systems I suggest the book MMURTL. It is very heavy on assembly language (but OS programming necessitates being heavy on asm) so you may want to brush up on that or learn it. I don't have a link for the book but perhaps Fordy might.

  9. #9
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    The Solaris front-end (Java Desktop System) is written entirely in Java. As I said, the kernel is not.

  10. #10
    Registered User
    Join Date
    Feb 2006
    Posts
    65
    Quote Originally Posted by zacs7 View Post
    The Solaris front-end (Java Desktop System) is written entirely in Java.
    Actually the JDS is simply a branded version of the GNOME desktop which is written entirely in C, together with programs most of which are written in C (StarOffice, Evolution, Mozilla). Despite the name it has nothing to do with Java.
    http://www.sun.com/software/javadesk...em/details.xml

    Besides, if the professor that claims that you can make an operating system in Java shouldn't it be him/her who should prove it? He might aswell argue that unicorns exist and let you prove that they don't.
    Last edited by joni; 05-21-2007 at 02:18 AM. Reason: added link to JDS details

  11. #11
    Registered User
    Join Date
    May 2007
    Posts
    147
    Interesting debates running in this thread...just had to chime in myself

    There was an experiment in some Scottish university some years ago (sorry, references lacking, not much was ever really released about it) that was an object oriented OS based on an object oriented CPU. C couldn't have been used as an application development tool because the OS exposed it's API as a set of objects. C++ didn't exist at the time, as I recall.

    The project evaporated into obscurity, but the concepts were interesting, and demonstrated it could be done. Now, there's .NET, and one could argue the viability of C++ there (MS had to mangle C++ into C++/CLI after the failed 'managed C++' they produced).

    I had the great privilege of meeting and working with one of the handful of people involved in developing the Alto at Xerox (the first GUI based system from which both Jobs and Gates were inspired for their attempts). It seems that was largely based on and written in Lisp, an object oriented Lisp if this man's description is to be believed (I'll withhold his name as he's not consented to my discussion of him in public).

    A lot of this question about Java (a two part, here I address the question of Java applied to an OS development) really boils down to what you define for an operating system. The popular operating systems (including the now defunct OS/2, AmigaOS, BeOS, etc) expose their API as a set of C oriented functions (perhaps some used an alternate calling definition, like the Pascal convention, but still - a set of function calls). A Java OS would probably expose the API as a set of Java objects, meaning the only language suitable for development of applications would be Java or something compatible with Java. Attempting to fit Java with C like memory exposure would be sacrilege to Java programmers, and largely useless, violating one of the tenets that Java developers identify as the very reason of the languages superiority. That limit alone, however, deprives the world of applications developed in any other language approach, and while it's debatable if that would really matter, the result would be an abandonment of all legacy applications. The platform would be starting from 'under' the level of Linux today. It may prove an interesting experiment, but I doubt the result could escape academia.

    I worked on a few proprietary systems where the OS was written in Pascal. That was long before Windows was what it is, and since it competed with Unix of the day, there really wasn't much interest, but at least it's OS exposure was similar enough that tools from other systems could be used, even C compilers.

    To hear Torvalds say it, C++ is crap. I'm only repeating what I read. His opinion, drawn from interview, was that C++ couldn't be used for an OS, largely because, in his unsubstantiated opinion, it would be slow and buggy. He lamented that C++ programmers were, and I paraphrase for lack of memory of the exact word, snobs - that should admit they're really using C.

    So much for the presumed authority of the great Linus. He may know what he's doing in C, but it seems he really doesn't understand C++, because while I don't recall the rest of the nonsense he muttered in the interview, I do recall repeatedly wondering how on earth anyone could say such things with a straight face and conviction of meaning.

    It is from that attitude that most have thought Windows was written entirely in C. Be assured, the guts of Linux are in C, as Linus apparently would have it no other way. I suppose, too, it depends on what you call an operating system. Gates would have us believe IE was an integral part of the OS, and I have little doubt much of that is C++ code. Since the OS is exposed, until .NET, as a set of C function calls (given the caveat of the calling convention for a particular version), I submit those portions we generally regard as OS code within the kernel is largely C, and almost certainly the early versions of NT were all C, because the C++ compilers were so weak to that date, and code written in 1994/96 is quite different from the C++ we expect written today.

    .NET is an attempt, among a great many other things, to expose the operating system as a set of objects rather than a set of functions. Laudable, but better if the objects were C++ objects, IMO - or at least there should have been thin C++ wrappers for that kind of exposure. I'm with Stroustrup on this point.

    Now, I switch gears to the claim that Java is the best language. Ooooo, them's fightin' words in some quarters!

    There's little doubt that C++ is a tad messy, which is largely a relic of history (it's basis upon C, chosen to invite an existing population of developers into a new paradigm). The sentiment already expressed here regarding 'the best tool for the job' is up to you most certainly applies. However, a blanket claim that Java is the best language is hardly backed up by history, example or experiment.

    RAII is one prime point that Java missed entirely. As an OOP concept, I find it irreplaceable. It's absence from C# is lamentable, though there is some nearly satisfactory workaround - if I'm considered a member of the Jury, I'm still not voted for C# as a superior language.

    Aside from RAII, though, Java has much to offer. Indeed, the absence of pointers and memory management issues related to the machine, which is the C legacy imposed upon C++ (perhaps some might preferred shared with C++) is laudable. There are suitable C++ means by which similar effects are achieved, but as Java fans will no doubt counter, they're optional. Well, curse words are optional to spoken languages - would an insulting idea be poorly conveyed without them? I think it's still possible to sting one's opponent with language clear of the FCC rules, but there is a deliciousness to their use when the time is right, isn't it? I'm told Italian is the best for curses, but I'm not so educated. That famous line in the Matrix 2 about cursing in French certainly tickles my fancy (the villain claimed it was like wiping one's, ahem, behind with silk).

    The pejoratives of C++ aren't so nasty, but they do have side effects and seasoned C++ developers respect that, and avoid them at prudent cost. Smart pointers, STL containers and a good knowledge of development patterns goes a long way to making solid code. Bugs are of many kinds, though, and Java has no immunity.

    Java proponents also point to it's 'pure' object oriented nature as a superior point in its favor, but I submit that after an application object is opened, there's no reason a novice can't continue to write more procedural code than good design demands.

    I'd retort with a simple question. What ambitious, successful, popular applications were written in Java, and which ones were written in C++? That list alone should say something, though just what will still leave the professor's nose in the air in a pose of obstinate defiance as he fashions a retort backed by his authority as the one in charge of the current forum. It wouldn't be the first time a professor waxed for a career about something with which few others ever agree.

    Java is superior if your intent is to provide rapid development results from engineers less competent than would be required to do the same thing in C++. If the Java produced application were compared by consumers to that of the C++ version, I'd dare say that the consumer wouldn't be able to explain why they prefer the C++ version (assuming it was generated by competent developers), but the probably would. The lower the ambition of the product compared, the less likely the consumer could tell any difference. It's in the products of higher complexity where features and performance expectations are critical that the Java version would fail to shine. This is less due to the language itself than to the exposure it gives to the developer of the underlying operating system and the speed it runs for a given hardware spec, which itself is highly dependent on the quality of the JVM.

    In that way, C# is also superior to C++ - if your intent is to provide productive tools to less competent, and therefore less expensive, personnel. An entire industry depends on this sort of thing - I call them "bag of fields" applications. I did that work for years, years and years ago. I certainly don't profess to demean those thus currently employed - I was one of them for many years - but you must admit, it's quite different to be a developer on a team making products for the market of the ambition of, say, 3DS Max or Photoshop than it is to be a developer creating forms upon forms for a corporate IT department.

    C++ is for those that operate without a net (as I write that I'm also thinking without .NET, but I'm just making myself chuckle). C is for those walking without a tightrope and without a net - floating in air, so to speak. For that, I suppose, Torvalds is owed his due. I wrote in C for years before C++ appeared, and I personally would never go back. I've toiled in Java and in C#, but only when required. Once you develop a considerable expertise in an area, you just tend to dive in deeper, becoming even more specialized. It's like the difference between a surgeon and a physician, or the general physician and the hematologists that are curing my son. Specialties can make for fascination in one's career. Torvalds is an example, I'm sure.
    Last edited by JVene; 05-22-2007 at 04:55 PM.

  12. #12
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    Quote Originally Posted by JVene View Post
    Interesting debates running in this thread...just had to chime in myself

    There was an experiment in some Scottish university some years ago (sorry, references lacking, not much was ever really released about it) that was an object oriented OS based on an object oriented CPU. C couldn't have been used as an application development tool because the OS exposed it's API as a set of objects. C++ didn't exist at the time, as I recall.
    Would love to know what is meant by an object oriented CPU.
    Im pretty sure C could have been used though because you can write OO code in C easily

  13. #13
    Lean Mean Coding Machine KONI's Avatar
    Join Date
    Mar 2007
    Location
    Luxembourg, Europe
    Posts
    444
    Quote Originally Posted by KIBO View Post
    Im pretty sure C could have been used though because you can write OO code in C easily
    No. According to the definition,

    object-oriented programming language (also called an OO language) is one that allows or encourages, to some degree, object-oriented programming techniques such as encapsulation, inheritance, interfaces, and polymorphism.
    C is definitely NOT an object oriented language.

  14. #14
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    An OS is a mixture of C and C++ as MacGyver stated on a thread a while back. With some assembley thrown in the pot too.
    Double Helix STL

  15. #15
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Quote Originally Posted by swgh View Post
    An OS is a mixture of C and C++ as MacGyver stated on a thread a while back. With some assembley thrown in the pot too.
    I don't remember saying that, but sure.

    Quote Originally Posted by Frobozz View Post
    Unless of course the VM is the actual hardware. http://www.soc.tuwien.ac.at/courses/jvmhw

    Also someone is already trying a Java OS. http://cjos.sourceforge.net/archive/
    I suppose the debate would then be about the performance of the VM-turned-hardware.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Java for real-time applications
    By zacs7 in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 08-26-2008, 06:34 AM
  2. Mats, the java answers
    By Jaqui in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 04-22-2008, 02:12 AM
  3. Why C Matters
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 136
    Last Post: 01-16-2008, 09:09 AM
  4. Problem using java programs within C code
    By lemania in forum Linux Programming
    Replies: 1
    Last Post: 05-08-2005, 02:02 AM
  5. What to make?
    By Caldus in forum C++ Programming
    Replies: 4
    Last Post: 04-06-2005, 01:12 PM