What is programming? What does a programmer do, exactly? You likely use many different applications (programs) on your computer. Where do these applications come from? Developers and designers work together to create and write these applications. Some programs are written by a team of developers; some programs are small and written by one developer. Programming doesn't only involve sitting at a computer writing code. Programming often also includes exploratory activities such as analysing an existing system, interviewing users, and doing research. Programming also sometimes includes the writing of documentation or help files that allow users to learn the application or find out what to do if errors occur. Programmers also deal with clients: programmers need to talk to clients to find out what kind of program is required, and sometimes programmers present their project work to clients in a formal presentation. You'll learn about all these extra activities in other courses. In this course, we will focus on the writing of code.
Java was originally designed as a language that would be embedded in appliances that would talk to one another. For example, you maybe have heard stories about a "smart kitchen": You take a bag of frozen peas out of the fridge and place it on the counter. The fridge notes the bag of peas missing and it updates an electronic shopping list so you'll know to buy another bag of peas. The counter feels the weight of something so it reads the bar code and recognizes a bag of frozen peas. It immediately warms up so that the peas can be defrosted. The microwave remembers that you like to nuke your peas in a bit of water so it sets the timer and waits for you to put the pot of peas inside so it can turn itself on. All of these devices mentioned - the fridge, the counter, the microwave, the electronic shopping list - need to be able to communicate with each other. In 1991 a team of developers (called the "Green Team" and led by James Gosling) at Sun developed Java as part of a special project that resulted in a device controller called the "*7" (Star Seven). The *7 needed a robust, platform-independent language but the developers were not satisfied with the performance of existing languages. Team member James Gosling developed Java to solve the problem.
In order to be able to make appliances work well, the original language was developed to be small and compact, secure and reliable, and portable. Why?
Today these features of Java make it a great tool for writing applications that must be run on different platforms or operating systems. A perfect example of this (and the one that everyone thinks of when you say "Java"!) is programs that run over a network such as the Internet. In Java, web-based programs are called applets.
Java is an object-oriented language. We'll learn what exactly this means in later sections, but for now it suffices to say that object-oriented programming, or OOP, is a style of programming that focuses on the objects or entities in a system. Objects keep track of their own data and can invoke behaviors. Objects can also interact with other objects. For example, in a college course registration system, some of the objects could be a course, a student, an invoice, a transaction, and registration form. A student object would contain information about the student's name and contact information, and a course object would contain information such as the course title and course code. A transaction object will tell the invoice object what information should appear on the invoice when printed. Java comes with a lot of objects that are already defined, such as an object that represents a data file you can use to store information. Programmers also use Java to develop objects of their own, objects that don't already exist, like the Course and Student objects.
Java is a very portable language: a Java program can run on any machine that has a JVM (Java Virtual Machine). Most of today's browsers and computers come with JVM's already installed. If they don't, they can be freely downloaded off the Internet. Java's security and reliability is also important when it comes to internet programs. For example, Java will not allow an applet to open files on your computer unless you grant permission to do so. Finally, the size of a Java program makes it easier to download. When you visit a page with an applet, that applet is automatically downloaded to your computer and run using your computer's resources. If an applet were too large, it would take too long to download.
There are a few different flavours of Java, and some terminology that's important. This will help you understand not only what you'll be installing when the time comes, but also what to update when new versions are available.
Java API. API = Application Program Interface.
The Java API contains pre-defined classes and interfaces. These are building blocks used to write programs in Java.
The API is always growing and being improved, so you should keep up with any changes
and update when it's necessary for your projects. API Documentation
is the set of documentation (usually it's web-based) that describes the different classes
and what they do. The Java 14 API is at https://docs.oracle.com/en/java/javase/14/docs/api/index.html
and it's a good idea to learn how to use it so you can learn more about the classes
you'll be introduced to.
There are "editions" of Java that you'll be exposed to during your program:
We'll be using Java SE in this course. In term 3, you'll use Java EE. If you take any courses on mobile development in 3rd year, you'll use Java ME.
The Java SE contains 2 parts:
To write Java programs you use an editor or an IDE (Integrated Development Environment). Editors are generally very simple, and good for first-time programmers. IDEs are more complex and include debugging tools, project management, memory management, design features, testing tools, and often many other things. In Java 1 you'll be using a simple editor, and in Java 2 you'll be using an IDE.
Source Code is the actual code that you type into an editor or IDE. Source code is generally just plain text, so you could actually use any editor or even a word processor to write it, although most developers prefer an editor or IDE that's geared towards Java programming because of the extra features that those tools have. Even the most basic editor will include syntax highlighting, which will assign different colours and formatting to different words and symbols in your source code to show how they fit into the Java language.
Once you've written some source code, you the compile that code. This will check your code for syntax errors, or errors in the spelling/grammar of the programming language. If you have any syntax errors, you'll need to fix them and then recompile your code.
Once you are able to successfully compile your code, a Bytecode file is created. This is the file that can now be run or executed by the interpreter. An interpreter reads in a line of bytecode and then executes those instructions. Then it reads the next line and executes those instructions. It continues until it runs out of bytecode (in which case your program is finished) or if it encounters a run-time error or exception (which basically means your program has crashed due to some unexpected circumstance).
You'll learn more about the finer details of source code, compiling, interpreting, and bytecode in the next lesson.