It’s easy for a computer to perform a task because someone told it exactly what to do. If the programmer (that same person) told the computer to go back to a new line every time the cursor of your Word document reaches the right end of the page, then this is what it will do. In other words, computers are good at following instructions… and programming is all about writing them.

A Computer Program – Microsoft Word Example

In our previous example, Microsoft Word is a computer program – a set of instructions the computer follows. Below is an example of what a tiny code snippet (part) of Microsoft Word’s program might look like. Of course, Microsoft Word has many more lines of code of which each set does different tasks such as spell check, color picking, drawing a table, and more.

if (isOnRightEnd) {
 goToNewLine();
}

A Programming Language – Java

The code snippet provided is written in Java, one of the many currently available programming languages. Just as one can communicate with their peers in French, English, or Spanish. A set of instructions can be communicated to the computer in Java, c++, or Python. Most, if not all, programming languages share similar concepts, and understanding these concepts is the most important step to becoming a great programmer.

A cat in English is the same animal as a “chat” in French or a “gato” in Spanish as long as you understand what a cat is, learning to communicate the concept in different languages becomes easy and just a matter of memorizing the sound of it. In programming, one should learn concepts such as variables, types, control, functions, stacks, queues, etc., and writing them in Java or C++ boils down to knowing (by memory or Google search) how to write them.

0’s and 1’s – A Computer’s Love Language

Whether you are using Java, c++, python, or anything else, the computer cannot understand any programming language. Instead, a computer can only understand 0s and 1s referred to as machine language.

If you were to tell someone “I love cats” in English, a computer can only understand it as “01001001 00100000 01101100 01101111 01110110 01100101 00100000 01100011 01100001 01110100 01110011”. The first batch of 8 numbers (01001001) forms the letter “I”, the second batch of 8 numbers forms the letter “L” (00100000), the third batch of 8 numbers forms the letter “O” (01101100), and so on.

So what now?

  1. Writing in 0’s and 1’s for us, humans is a tedious if not impossible task.
  2. A computer can only understand 0’s (electric signal off) and 1’s (electric signal on)

Compiler – Real-Life Hero

A compiler can translate our source code (original human-understandable code) into machine code (0s and 1s). However, in the specific case of Java, the Java compiler translates the source code into bytecode (a low-level language that can still be understood by humans). Then, the Java Virtual Machine (JVM) interprets the bytecode and converts it to machine language (0s and 1s) specific to the intended platform (Windows, iOS, Linux). This process of “middleman” in Java provides the popular “Write Once, Run Everywhere” feature. In other words, you write the Java code and compile it one time, then you can run it on any platform such as Windows, iOS, and Linux since the JVM will produce specific machine code that can be understood by the targeted platform.

In Summary

To recap the knowledge we acquired in this lesson, we provide the following definitions:

  • Computer: a computer is an electronic device that can store, retrieve, and process data by executing commands.
  • Computer program or code: a set of computer instructions that tells the computer what to do.
  • Programmer: a person that writes computer code.
  • Programming language: a language for writing computer instructions such as Java, c++, python, etc.
  • Machine language: a language that the computer understands, it is made of 0s and 1s
  • Source Code: code that is written in human-understandable programming languages such as Java, python, etc.
  • Bytecode: an intermediate code between source code and machine language, also referred to as object code. This code can be converted to machine code with JVM so it can be read by a computer’s hardware processor.
  • Compiler:
  • Java Virtual Machine (JVM): a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode.
  • Platform: a computer or hardware device and its associated operating system (ex: iOS, Windows, Linux)

Other Lessons in Introduction to Programming in Java

No. Lesson Reading Time
1 Introduction to Java 5 mins
2 Setting up the environment in Java 5 mins
3 Java Hello World Program 5 mins
4 Java Output 5 mins
5 Java Escape Characters 5 mins
6 Variables & Types 5 mins
7 Arithmetic Operators in Java 5 mins

Related Subjects

or view all subjects
No realted subjects found.