4 Replies - 388 Views - Last Post: 31 May 2019 - 02:36 PM

#1 InsaneChiken   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-May 19

Java or C++ for OS/Kernel interactions?

Posted 24 May 2019 - 06:16 AM

Alright, So I am an intermediate in Java and I got into wanting to learn about the Operating System, so I learned as much as I could then came to a halt because of how limited you are with Java. You see, Java runs in its own little Virtual Machine called the JVM and this ended up limiting me to what I can do. My end goal is to just begin to interact with the OS, or even learn how to program a Kernel, or at least communicate with it. I am self-taught in Java, (As, let's be real, most people are) so there may be gaps in my knowledge. I also self-taught myself some C++ which is very different then Java, first thing I learned there was the new function in java is completely different. But in my short weeks in C++ I think I understood (Correct me if I am wrong) that C++ is more integrated with the System, in the sense it can interact with OS and kernel (I think, still working on basics, found this cool into to C++ tutorial on youtube that's 2 hours, tbh probably a marketing scheme for some "amazing future of coding technology school that charges $200/month for lessons you could learn more in depth by reading stack overflow posts for about an hour") Anyways, can someone help me choose whether to go C++ or Java, and maybe give examples or an explanation of why, and maybe if it doesn't trouble you a place to get started learning how to interact with OS and/or kernel in this language? Thank you.

I don't have code for this as it is a question, I couldnt find a subforum/topic in which this would be most appropriate so I put it here, if there is a subtopic that suits this better please let me know where to move this thread (and how to move this thread lol) (or if you are an admin please move this to a more appropriate topic for me if this is not the most appropriate thread).

I put what I got from my first person research here and now I am asking someone to help me reason which one, with an explanation, and point me in the right direction. I did my homework on this yet am still confused, so I decided to take this to the forum, where people help with this stuff.

Thank you in advance for any help that may be offered.

Is This A Good Question/Topic? 0
  • +

Replies To: Java or C++ for OS/Kernel interactions?

#2 modi123_1   User is online

  • Suitor #2
  • member icon

Reputation: 15307
  • View blog
  • Posts: 61,387
  • Joined: 12-June 08

Re: Java or C++ for OS/Kernel interactions?

Posted 24 May 2019 - 06:48 AM

If you want to learn c++ then pick up a c++ book and go nuts. You gave a whole mess of reasons to move on from Java so go there!

Though if you want to get super nitty gritty with an OS assembly (ASM) would be where it's at. Heck I think there are classes taught where you make an OS!
Was This Post Helpful? 0
  • +
  • -

#3 NicVene   User is offline

  • New D.I.C Head

Reputation: 9
  • View blog
  • Posts: 9
  • Joined: 28-May 19

Re: Java or C++ for OS/Kernel interactions?

Posted 31 May 2019 - 12:03 PM

View PostInsaneChiken, on 24 May 2019 - 06:16 AM, said:

But in my short weeks in C++ I think I understood (Correct me if I am wrong) that C++ is more integrated with the System...

You are getting warm, but here's the rest of that story.

There was a time when operating systems were written in assembly (the machines native language), but with the rare exceptions that hasn't been true for a long while.

The C language was developed in the late 60's as means to create the near equivalent of native machine code with complete independence from a specific CPU.

This made it possible to write the UNIX operating system almost entirely in C. THAT is the reason you are someone correct about C++. The C language is still "inside" the C++ language, so there is a natural, seamless connection between the two languages.

Windows (from NT through Windows 10) is written in C. UNIX was the first documented to be written in C (and as history tells it, C was created to write UNIX to be portable). This means the C language and the UNIX operating system have a shared history, and the since C is the language, the OS interfaces are all C function calls.

This is true, by the nature of the design, of Linux. Since OS X (Apple) is UNIX (they're registered to be called so), OS X is, at it's root, written in C, too.

THAT is the reason you think of C++ as "more integrated"....the "parent" language to C++ is what the operating system is written in, so certainly "integrated" might be a way of saying that.

You are also correct in saying Java can't play in this domain. You can invoke native calls (JNI) to the operating system, but the whole point of Java (and the JVM model) was to completely abstract the operating system, making the specific OS irrelevant to the applications written in Java. One might say Java has it's own abstract representation of what an operating system is (another way of saying it's a virtual operating system).

A significant point to make here is about which language to study, C++ or C.

This comes up often at this juncture, when Java programmers realize they've been inside a sandbox and want to drop down to the operating system.

You'll get contradictory answers. Let me see if I can clarify.

A Java programmer may be disoriented by the shear complexity and "raw nature" of writing software in both C and C++, but of these two, C is BY FAR more "RAW" and complicated. That's not really a good thing.

You choose C if you are participating, for example, in the open source development of the Linux operating system. The project leaders simply will not accept C++. Whatever reasons they have, debate on the subject is irrelevant. Their decision stands with respect to Linux.

You choose C if you are writing device drivers for Linux, maybe even Windows or MAC. These are targets directly related to the operating system, so this seems appropriate.

Some people have negative reactions to C++, but between these two languages, generally you choose C++ for everything else (where C is your only other option).

If your purpose is NOT writing device drivers and extending operating system kernels, you probably should study C++ and not C.

Even if you think you want to use C, study C++ first and then study C after you have a firm grasp on C++.

On the path from Java toward assembler, C++ is the one stop that is at least OOP, and therefore related to your knowledge in Java. It is, however, nothing like writing in Java except on superficial levels.

What you learn about basic syntax in C++ is related to what you know from Java, and that is related to base C syntax, but syntax is just the basics. The way we consider what to write in C++ differs greatly from that of C due to the libraries, in particular how to deal with memory management.

I do suggest familiarity with Assembler, but later, even after or during the study of C.

I disagree with modi123_1 on one minor detail - the OS is not usually addressed with assembler,
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7093
  • View blog
  • Posts: 24,107
  • Joined: 05-May 12

Re: Java or C++ for OS/Kernel interactions?

Posted 31 May 2019 - 02:11 PM

When I used to work in the Windows team (Windows 7 and early Win 8), the kernel itself was C, but most everything else was C++. Some of the older device drivers were written in C++, but as "C with classes", but most of the newer pieces of the shell were were written in C++. With the Win 8 development, a lot of C# was also going in to the OS both as WinRT and UWP applications, as well as some vanilla .NET Framework based applications.
Was This Post Helpful? 0
  • +
  • -

#5 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5485
  • View blog
  • Posts: 14,448
  • Joined: 18-April 07

Re: Java or C++ for OS/Kernel interactions?

Posted 31 May 2019 - 02:36 PM

As I think many of the talented programmers here have alluded to, OS systems are more than just one language these days. So I wouldn't necessarily look to a silver bullet language as your means to build an OS that will function in the modern era effectively. I would start with C, leverage that knowledge into C++ and from there decide what kind of OS do you want to build and choose further tech from that point. I don't think you have to go as far as assembly.

Not only do you have to choose the language(s), but you should really study up on topics such as memory management, data structures, drivers and stream manipulation. All of which are going to be needed at some point.

Good luck to you!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1