It is extremely useful in engineering and especially robotics to be able to write computer programs. The ability to write and understand computer code gives you the flexibility to put your own ideas into practise. There are thousands of programming languages around, most of which can be used to achieve the same results. Of the languages used in robotics the language C, introduced in the 1970s, is still one of the most popular. Some of the reasons why C has remained so popular are due to its minimalist design, requiring less run-time support compared to most other languages, and its ability to access low-level memory. The C++ language builds on C, adding many enhancements, such as classes, multiple inheritance and error handling. In 1994 Sun Microsystems released its first version of Java, which was developed using much of the C/C++ syntax. The main motivation behind Java was to design a language that would be platform independent and more manageable than C/C++. Java has fast become the programming language of choice in education, and is taught on the majority of computer science courses in colleges and universities. 

Learning Java

We highly recommend learning Java as your first language. The benefits are: an excellent community of support on the web, C/C++ syntax (so you will be able to understand those languages as well), automatic garbage collection (meaning no need to allocate and de-allocate memory) and numerous tools can be downloaded for free!


My First Program


At this point we will be assuming that you have installed java and everything is working correctly. If this is not the case please follow the steps on the ‘Installing Java’ page.

This first program simply displays ‘I’m Learning Java!’ on the Java console window.

  /**
   * The MyFirstProgram class implements an application that
   * simply prints "I'm Learning Java!" to the screen.
   */
  class MyFirstProgram 
  {
     public static void main(String[] args) 
     {
        // Display the string
        System.out.println("I'm Learning Java!");
     }
  }




My Second Program



Have a look at this second program, notice how we are now using a function called ‘displayText’.

  /**
   * The MySecondProgram class implements an application that
   * prints "My second Java program" to the screen.
   */
  class MySecondProgram 
  {
     public static void main(String[] args) 
     {
        /* Call function to display text */
        displayText("My second Java program");
     }
     
     public static void displayText(String textToDisplay) 
     {
        System.out.println (textToDisplay);   // Display the string
     }     
  }