Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am somewhat new to programming and the best way I can ask this question is with an example.

I know how to do basic things in Java and C#. Things like a small windows forms application or make a generic class. I've basically been learning and haven't tried to do anything big yet. Anyways, I've always been curious about how things are done "under the hood" I guess you could say.

I know it all gets boiled down to 1s and 0s and that assembly languages basically give commands to patterns of 1s and 0s, but its seems like there's this jump from there to: use a library for this a library for that. It seems to me like all C# can do without a library is arithmetic and binary logic. To get input or output, you use libraries, etc...

I know this question probably seems obvious to some and I know that I have a lot to learn but I don't even know where to begin with a question like this. Thank you.

So my question is this:

If someone were going to make a virtual machine or a Playstation emulator, or an operation system, or a driver, or add mp3 support to a media player, or make your own file type, etc... How? I can't see the way that would be done with C# or Java.

In other words, if I read a book like Professional C# by WROX or Programming C# by OReilly, would I know how to do these things? Or do you have to learn assembly language or something more low level like C++?

share|improve this question
7  
One trick to understanding what's going on "under the hood" is to focus and use paragraphs to make things easy to read and understand. Please edit this question to be easier to read. –  S.Lott Apr 26 '11 at 14:49
1  
Given your interest you might want to pick up a copy of Charles Petzold's Code: The Hidden Language of Computer Hardware and Software. It's a good read. amazon.com/Code-Language-Computer-Hardware-Software/dp/… –  DKnight Apr 26 '11 at 19:11
    
@S.Lott To the rescue :-) –  Martin Wickman Apr 26 '11 at 20:47
    
@Martin Wickman: While very nice work, did it help @fender1901 to edit or focus? –  S.Lott Apr 26 '11 at 20:57
1  
@Martin Wickman: Undoing the changes is not the point. Encouraging others to learn by doing is my point. You clearly already know. @fender1901 needs to learn by doing. My question is this: "did it help @fender1901 to edit or focus?" What do you think? –  S.Lott Apr 26 '11 at 21:02

6 Answers 6

Interesting question! You'll find that languages like Java and C# do in fact support fairly low level programming. For example look at some of the I/O source code in the OpenJDK for Java. You'll see that the higher level methods are implemented with lower level socket technologies, byte arrays and bit twiddling.

With regards to C# and Java, those languages compile down to bytecode, which gets eecuted on a virtual machine. You can actually quite happily view and learn from the bytecode (e.g. Seeing how Java deals with concatenating String objects).

If the environment you are developing in does not host one of these higher level VMs (often due to space and performance requirements), then you need to use a 'lower level' language.

I believe that C/C++ still rules the roost in the area of writing low level drivers etc as you can tweak the memory management and the data structures to the nth degree.

Assembly is pretty specialised these days, it's good to take at least a quick course in it to appreciate what happens at that level. When you write some Assembly to back fill a register while it's emptying, you start to appreciate the sorts of lengths that each programming language layer has to go to.

HTH

share|improve this answer
    
Can you actually program with the intermediate languages or are they just there to examine? –  fender1901 Apr 27 '11 at 13:34
    
Are you asking whether you can write 'bytecode' source code? –  Martijn Verburg Apr 27 '11 at 18:31
    
I think. I'm wondering if you can just start coding using bytecode or il just like you would java or c#? –  fender1901 Apr 29 '11 at 12:49
    
Java or C#, very few people are into manipulating bytecode, however a larger set of people do look at what byte code their particular higher level code boils down to –  Martijn Verburg Apr 29 '11 at 13:24

Most "low-level" programming basically amounts to directly interfacing with the Operating System. The reason it doesn't seem to you like there is an "obvious" way to do this is because generally speaking, higher level languages like Java strive for ease of use and portability. Code that directly interfaces with the Operating System is generally a lot less portable than higher-level code, unless it is wrapped in an abstraction.

In lower-level languages like C and C++, the Operating System API is directly accessible (largely due to the fact that most Operating Systems are written in C, so they expose an API through the C language). For example, in C on a UNIX system you can call the ioctl function to directly interface with a device.

Of course, higher-level languages like Java and C# also need to talk with the Operating System. Every time you open a file or read from a network socket, you're interfacing with the OS. It's just that Java and C# wrap the low-level OS system calls in higher-level abstractions, like a Socket object. This higher-level approach has the advantage that the same Java code will work on different platforms. Whereas, the way you would open up a socket in C on UNIX is quite different from the way you would do it on Windows.

In general, the more higher-level the language is, the less control you'll have over how your program interfaces with the Operating System. That said, a lot of things you mention are possible to do in a higher level language. For example, there's no reason you can't write a Virtual Machine in Java or C#.

share|improve this answer

The good news is, it can be done with Java or C#. The only problem you need to know is how. Basically, you need to know this nice little things about Hardware Architecture (not necessary PC, but Playstation if that's what you want to emulate). And I am afraid you would need to go deep, like Assembler and Machine Language.
All ALUs, registers, MMUs and stuff could be abstracted and emulated with high level language. You can even call low-level functions to obtain hardware support (learn about PInvoke and JNA for example).

However, since you are beginner I wouldn't recommend to start with such enormous task. I would suggest that you learn C/C++, a bit about Linux (or other Unix-like OS, i.e. FreeBSD), Computer Architecture, then Assembler... It could take a few years, so...
What you really need is motivation and patience.

share|improve this answer

What I did what learned a high level language (Java) then became more interested, as you are, about low level languages and hardware. In its most primitive state, a computer is electronics. 1's and 0's are just figures for electrical charges (on and off). Once I began to understand the logic behind processors, and what is inside an Arithmetic Logic Unit, things really fell into place.
I think you should start your studies with things like boolean logic (AND, OR, XOR, etc.), then start designing small ALUs and looking at how memory and registers play into things. After that learn some assembly language and then youll realize how a compile works. Pretty soon high level languages will seem boring! :) Just kidding. It's beautiful how everything falls into place though, and it should be enjoyable to learn. Once you start following the path of curiosity, you'll pick things up in no time.

share|improve this answer

While you can do low-level stuff with C# or Java (or most other languages), most people don't. Therefore, any reasonably popular book you pick up on either will leave low-level stuff out. They're likely to cover the language features you'd need, but not apply them the way you're curious about. Similarly, books on low-level stuff will probably be in C, with perhaps a little assembly language.

Learning C itself won't be hard for a C# programmer, aside from pointer manipulation, although learning to do things in it will take longer. Since C is a less expressive language than C#, some things that you know how to do efficiently in C# will have to be done in a much different, and often clumsier, way in C.

What you should look for next is books on the lower-level stuff you want to learn. There are books on the Linux kernel, for example, but kernel-level programming is going to be difficult to grasp without some background, so you might want to study operating system fundamentals first.

share|improve this answer
    
I think my biggest problem right now is that a lot of these topics are going to be difficult to grasp because I don't have the background. I need, I guess, a bridge into those areas. –  fender1901 Apr 27 '11 at 13:39
    
@fender1901: That could be a problem. The Linux kernel does some things that would look really odd to somebody who doesn't understand what operating systems do. The emulator, of the things you mentioned, would probably be the easiest to understand, and there are simple emulators out there, often for early microcomputers. –  David Thornley Apr 27 '11 at 13:42

You must find out, that is it possible to do the low-level function with the used platform/language or not:

  • storing a byte into a variable,
  • reading/writing files by bytes,
  • setting up an array of bytes, accessing elements,
  • use true procedural features, OOP,
  • accessing the screen, keyboard, sockets.

Hm, sounds that choosing a language should be random.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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