Is there anyway I could create a operating system using java? Is there anyway I could embed the windows java library so I could develop my OS with things like JFrame, JFileChooser, JTextArea, etc? Or would I be better off In the long run learning C or C++?
-
2I doubt you can create an operating system in Java. Java needs to be run in a Java Virtual Machine. IE it's not running on the hardware directly. There may be ways to compile your Java code into C or another language that can run directly on a machine. I would suggest learning C and assembly if you want to make an operating system. Also writing an OS is much different from writing a program. You have to handle all of the code. You can't rely on others implementing the idea of a directory or input and output and memory management. – Timothy Murphy Jul 18 '15 at 03:06
-
1@Timothy Murphy I think Java **can** be run on the hardware directly: https://en.wikipedia.org/wiki/Java_processor – cadaniluk Jul 18 '15 at 08:11
-
@cad Fair enough. But you're operating system would run only on that type of processor. – Timothy Murphy Jul 18 '15 at 17:24
-
I updated my answer to also address your last question. I think its worth a read, but it's mostly opinion based. I also upvoted because it is a good question, even though it's been answered before :) – ydobonebi Jul 24 '15 at 16:05
2 Answers
Short answer: no.
First, Java using the OS to run your java code. A lot of the windows are using the OS to render.
Second, you should note that most, if not all, OS are started with machine/assembly code. If you have the goal of making an OS yourself and completely from scratch, you will need to learn assembly and there is no way around that. Luckily, you only need to write a small amount of assembly before you can get something written in C or C++ to run (and note that Java runtime is written in C/C++).
Since Java using the OS' native code to manage/render windows and controls, and assuming you've compiled Java from source without using said libraries, if you wrote your only code to handle all of the graphics of rendering controls and windows then yeah, suppose you could write a majority of the the OS in java once you got the basic stuff done. You should know that you wouldn't be able to use much of javafx or swing for anything since they rely on the OS.
Finally, I would strongly recommend going to college and getting a solid education , then I would further recommend working for a company with a team of experience programmers for at least 4 years (at minimum) before you take on such a herculean task as creating an OS. You aren't going to write a useful OS by yourself and with the amount of knowledge you seem to have in any language.
EDIT: There are machines who's microprocessor natively understand java bytecode as mention in other answer. However an OS written for that processor would only work on that processor and would not be widely distribute atm. For learning purposes, you would be better just sticking with JVM on whatever you have access to now in you really don't gain much.
Also, learning to write an OS is a task I encourage all programmers to learn. It will give you a better understanding of how computers work inside and out. From a programming point of view, in relation to high level languages, you don't lose or gain much by using one language over another. Some argue (and perhaps I agree) that Java doesn't use pointer and so that is lost to most however if your intent is to do everything in Java, then all you need to understand is Java.
As a matter of opinion, I would argue you are better off learning every programming language you come across, and every language that are the predecessors to those. I don't mean become a master programmer in BCPL or COBOL or anything on that level, but at least research, learn how to do basic things and know they exist and (in most cases) can do everything every other language can do.
My professional advice, learn and master what ever language your employer would have you use. If you change jobs be prepared to learn something new. Not all jobs use Java, or C++ so if you limit yourself to just Java or even C/C++ you will not be as marketable on the job market.

- 240
- 2
- 11
-
1...i like your reply,and i upvoted you,But In this new age,you dont need an education or experience working for someone else inorder to achieve something...all you need to sk yourself is,how badly do you want to achieve this goal of yours,,and then do everything in your power to make it happen,There are alot of free sources online to learn machine languages and programming languages in general.We need to learn to get out of that mind set of education is the only way and realize that we all have the potential inbuilt into our DNA's.You can do anything you dream.Just focus and push – RileyManda Jan 13 '18 at 10:46
-
1it was sooo good until you started talking about college :p “Don’t confuse schooling with education...” – parse Sep 25 '21 at 08:41
Yes, you can.
Many options available to do so:
- JNI provides communication of Java code with native code. you can develop boot loader in native code, but UI in Java
- Java Processor: implementation of JVM in hardware
- Java Optimized Processors
- Embedded Java
- picoJava
and so on..
There's nothing that can stop you from developing OS in Java. You can find many OSes written in Java: from CISCO to NASA...
However, even creating a tiny OS requires a lot of effort.

- 734
- 7
- 21
-
-
So basically, you can't do it without writing machine code to start with UNLESS you use a CPU that was built knowing Java already. Fair enough. Won't run on most home computers, but I certainly see it's purpose and value in the long wrong. You did fail to address the question about whether one should bother learning C/C++ – ydobonebi Jul 24 '15 at 15:54
-
@QuinnRoundy i think the person who asked the question is satisfied with my answer. Read 1st point i've provided carefully: I said, you can write Boot loader in native code, means C/C++, but other stuff in Java, and make them communicating using JNI. About your point `you can't do it without writing machine code to start with UNLESS you use a CPU that was built knowing Java already.`, i would say that computer doesn't even know C/C++, it only knows 0 and 1. And about ` Won't run on most home computers` comment, i would say it depends on the architecture and its support. . – Muhammad Imran Jul 24 '15 at 16:20
-
I was just cleaning up some old answers. I know how x86-32/64 works, I won't claim anything beyond that. When the computer turns on it knows nothing about stacks, heaps, etc etc. (it has the registers for them, just not configured) The OS does that work, which is done almost exclusively in machine/assembly. Yes I realize you mentioned that (as did I) I agree that Java could be used once you have a functional loader. Computer only knows 0 and 1... yes and no, it knows about address space, about arithmetic, etc. It doesn't know, yet, where the stack is, if a 'task manager' will be used etc. – ydobonebi Jul 24 '15 at 16:51