As I thought about writing an operating system, I came across a point that I really couldn't figure out on my own:

Can an operating system truly be written in an Object-Oriented Programming (OOP) Language?

Being that these types of languages do not allow for direct accessing of memory, wouldn't this make it impossible for a developer to write an entire operating system using only an OOP Language?

Take, for example, the Android Operating System that runs many phones and some tablets in use around the world. I believe that this operating system uses only Java, an Object-Oriented language. In Java, I have been unsuccessful in trying to point at and manipulate a specific memory address that the run-time environment (JRE) has not assigned to my program implicitly. In C, C++, and other non-OOP languages, I can do this in a few lines.

So this makes me question whether or not an operating system can be written in an OOP, especially Java.

Any counterexamples or other information is appreciated.

  • 3
    Being that these types of languages do not allow for direct accessing of memory. Really?
    – tibur
    Commented Nov 27, 2011 at 3:23
  • Yes. cosmos.codeplex.com But not entirely, see 'plugs' Commented Nov 27, 2011 at 3:25
  • 4
    So Java sucks. Doesn't mean you can't do it with C++. Commented Nov 27, 2011 at 3:39
  • 5
    @nmagerko Java isn't a "true Object Oriented" language either, maybe you should try SmallTalk instead.
    – Raynos
    Commented Nov 27, 2011 at 4:13
  • 2
    It sounds more like you're asking if you can develop an OS in a language that runs in a sandbox or VM, rather than OO vs non-OO. Commented Nov 27, 2011 at 13:41

3 Answers 3


The android backbone is written on top of linux so not really. It is possible to write an Operating System in C++ and there are many ones out there albeit not popular. C++ gives you the OOP concepts you want while still allowing you to do the low level stuff that you need in order to communicate with hardware. C still is the language that most operating systems are written in (with some assembly backbone required) and this is because C is lightweight and personally I find it better just because it removes a lot of the OOP stuff that I find isn't needed to write an operating system (that's just my opinion though).

Technically it is possible to write an operating system in Java in a sense you would need to hook into C/C++ code (I can't remember how to do it in Java but I believe you can) which would in turn call on the assembly required to talk to some of the hardware. The java code would also have to compile directly to machine language instead of the current bytecode scheme that runs on the Java Virtual Machine.

The high level concept of the OS could be done in java but the problem is that a lot of the functionality would have to exist in another form as doing some of the required things for handling data from devices and such cannot easily be accomplished in Java if at all.

  • Very interesting. I did not think of how the Linux kernel would aid in the creation, but this is a large oversight on my part.
    – nmagerko
    Commented Nov 27, 2011 at 3:26
  • 1
    Yes the android base is the linux kernel but the subsystem for android is java based which runs on a JVM on top of that kernel. Commented Nov 27, 2011 at 3:28
  • You don't need to hook into C/C++ code. You do need some way to tell your Java compiler to generate the assembly instructions you need. Since you're probably writing your own compiler, you can do that. Commented Dec 11, 2020 at 14:00

You are miss-using a lot of terminology in your question.

OOP is a style of structuring programs. As such it is independent of programming language, you can easily do OOP in C. A lot of OS-APIs are in fact object-oriented, for example everything that returns a handle. OOP has nothing to do with not being able to unsafe operations in your programming language.

I think what you are really asking is: Can you write an OS in a language with automatic memory management and memory-safety?

The answer to that is: You have to cheat at some place.

Some options:

  • Make the compiler/runtime map some special objects directly to the addresses you need.
  • Add the necessary hardware-representation objects to the compiler/runtime build-in library (and do the unsafe stuff within the compiler) - somewhat similar to the first option
  • Extend the language/library with unsafe operations
  • Change the hardware so that it directly supports your language objects (e.g. http://en.wikipedia.org/wiki/Java_processor)
  • +1 OOP is a design style, not a language feature. much less a language restriction!
    – Javier
    Commented Nov 27, 2011 at 13:16
  • easily do oop in C? I'm not sure I agree with the easily part, but it's certainly possible. Commented Nov 27, 2011 at 13:44
  • I do not understand the miss-use of terminology part. Please elaborate.
    – nmagerko
    Commented Nov 27, 2011 at 14:54
  • 3
    You are talking about memory-safety and automatic memory management in your question but are calling those things OOP.
    – Patrick
    Commented Nov 27, 2011 at 15:57
  • OOP is certainly possible in C albeit not trivial. C++ is implemented in C so it had to be done somehow ;) Commented Nov 27, 2011 at 22:44

You can't write an entire operating system in C either. A small amount of it must be written in assembly for things like bootstrapping, entering supervisor modes, etc. Add a little more assembly wrapped with a small peek/poke class and an interrupt handler class, and you're pretty much good to go in any OO language. There will be obvious inefficiencies without direct pointer manipulation, but that just makes the language ill-suited.

The main problem with Java is not its object-orientation, but the fact that it doesn't compile to native bytecode, so you require a JVM that has to be written and bootstrapped via some other means.

  • 1
    Though I agree Java is not really suitable as an OS implementation language, there are Java compiler that generate real op-codes and there are actual physical implementations of the JVM; so the last point does not hold. Commented Nov 27, 2011 at 5:19
  • How could you add Assembly into a Java class? I know there is inline Assembly in C (C++?), but is there such an API in Java?
    – nmagerko
    Commented Nov 27, 2011 at 14:56
  • Java has the Java Native Interface to cover such contigencies. Most languages have something similar. Commented Nov 27, 2011 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.