To run java code you first place it in a file with the extension ".java" on the end.
This file must contain one and only one class declared public and that class must contain a method named main which is declared like this:
public static void main(String args[])
The file also must contain a package declaration at the top like:
package MySillyJavaPackage;
Once you have these, you call the java compiler, either through using the build menu item in eclipse or on the command line. If you use the command line, you type "javac yourfile." If your program compiles without errors, the compiler will produce a directory with the name declared in your package declaration. Inside this directory their will be a file with the extension ".class" and the same base name as your original file. To run it, type "java PackageName/yourfile." Do not use any extension with name of the file you want to run.
With C you must have a main function. As pure C is not object oriented the main function is not part of any object. The incantation for compiling your file varies. If you are using GNU C on the command line, it is gcc filename. If your file is error free the compiler will produce a file called "a.out" in the same directory your source file was in. To run it, just type "./a.out" and away you go.
Now you may wonder what good all this does, after all I've given no way to get output from your code. I've delayed this longer than I should have because I wanted to discuss library routines and input and output at the same time.
To have your program print anything, you need to include or import prewritten code that does output for you. How does that code work? It directly manipulates the hardware interfaces connected to your screen and keyboard. Writing it is both highly specialized and fairly tedious for most people, which is why if you aren't an embedded systems hacker you usually don't bother with it.
Anyway the library used for input and output in C is called stdio. To gain access to it you use a preprocessor directive. The particular directive is
#include<stdio.h>
Which means get the file called "stdio.h" from one of a few standard places. You can use this include other libraries such as the C Math library. Included in stdio are definitions for the C functions printf and scanf. Printf is used like
printf("%d silly dogs played with the ball\n",&dogs);
The first argument to the printf function is called the format string. %d means insert an integer value into the format string. The "&" in front of the variable dogs, means that we are passing it's address rather than it's value into printf, another example of a C pointer.
In Java output is a little easier. Instead of using a format string you would just type
System.out.println(dogs," silly dogs played with the ball\n");
The "\n" used in both examples is just a sign for a carriage return.
Now, while raw text output is perfectly good for some things like program logs, most programs written today have other, more intuitive, ways of interacting with a user. How to make a GUI, a graphical user interface will be discussed in my next post.