Yes... I'm fairly able as a programmer in java, but I'm totally lost when it comes to computer science theory with the compilers and interpreters and everything. My main issue is school computers which don't seem to have any way of running code that is written on the spot. It is partially just for personal fun, as I can write java in text and move it between computers all the same, but it'd be nice to be able to run it from a school computer. Is there any chance of being able to directly write an exe or jar file, or is just not worth the effort?
@A Brain in a Vat: So if something were installed onto a flash drive, could it still run, even though it's not on the actual computer?
Nothing runs code "just from a text file." You either have an interpreter (as is the case with Python, batch, and many other scripting languages) or a compiler (as is the case with Java and C++). Some obscure languages, including older BASIC dialects and some flavours of C, can be run either way - but one of those tools must be present. An interpreter essentially runs the program "raw" whereas a compiler translates it into some other format, which can then be run "by itself" (for native programs) or with the aid of other programs again (for virtual-machine based platforms such as Java and C#).
Software relationships are incredibly complex and intricate; there may be literally dozens of different pieces of software involved in just installing and running something like Notepad or Calculator. Web browsers and programming language environments and video games can involve hundreds. Major server systems that power MMOs, web sites, and Youtube might involve thousands of distinct pieces of software, when you account for the entire ecosystem.
This is, by and large, actually a
good thing. It means we can rely on other people to do a good job at certain features, while we focus on the features that matter to
us. Hence the presence of libraries, APIs, platforms, frameworks, kits, and all manner of software that exists solely to help make
other software possible.
One of the deep truths of modern computing is that no program is an island. There will inevitably be many different pieces of software involved in even the most apparently trivial computing job performed on a modern PC or game console. This is
less true on embedded devices like the computer that runs the fuel injectors in your car engine, but it is still true to some extent.
So, all that to say: can you write an .EXE or .JAR file without needing a compiler or some other tools? No.
At the very least, you need a hex editor or something that can support writing out binary files. Even then, you'll need to master a handful of important things before you can make even trivial programs without a compiler:
- Executable file formats on your platform of choice (PE, ELF, etc.)
- Machine language encoding of instructions for your CPU of choice (x86, x64, PowerPC, ARM, etc.)
- How to program in machine language for your CPU of choice
- How executable files are packed and how they are loaded into memory on your OS of choice
- Dynamic as well as static code linking on your OS of choice
- Kernel vs user space distinctions
- How to invoke kernel code from user space, and vice versa
- Calling conventions, typical memory models, and other methods for communicating with other libraries, APIs, and programs
And of course that's just so you can write "hello world" on the screen. If you want to do anything
interesting, plan on learning about ten times that much, plus a lot of hard lessons in software architecture.
In a nutshell, your situation is this:
- You are learning to drive
- You can't afford your own car
- You can only borrow a car from, say, your parents, on an infrequent basis
- You really want to be able to drive more
The question you are asking is, "How can I drive without buying a car of my own?" The answer, of course, is you
build your own car.
But this is, unquestionably, ten million times harder than just getting a job and saving up for your own car. You have to learn a huge amount about how cars work, how the tools work that are used to make cars, and so on. If you're really hardcore, you have to learn about metallurgy, and how to cast your own engine blocks and such stuff. Maybe you refuse to buy wrenches from Home Depot and must manufacture those yourself, too. And so on.
Eventually, the obvious answer should start seeming attractive: just get a job, work for a while, pay your dues, and buy your own car when you can.
The analogous answer to your
programming question is similarly straightforward, although probably not what you wanted to hear: use the tools, learn how they work, and learn to appreciate them. They really are saving you a tremendous amount of pain; you just don't know it yet.
Best of luck :-)