Prerequisites for programming - Java Series - 1
Concepts to help you to understand about programming
This blog covers the basic computer concepts you need to know before you begin your programming journey. To keep it as simple as it is, I'll be also making a thread on Twitter, which consists of the basic concepts covered in this blog.
In this article, we are going to cover these topics...
Fetch and Execute Cycle
Machine Language (Binary)
The Java Virtual Machine
Building blocks of Programs
OOPS Introduction
Summary
Fetch and Execute Cycle:
Well, we all know how to use computers. But most of us don't know how computers work actually. Basic knowledge of the working of computers can help us to understand a few programming concepts easily and fastly (like Arrays, Functions, Recursion, Trees, etc basically data structures).
A computer is made up of several components, and from all those CPU work is the main part of it. CPU contains a number of registers in it. To run a program on our computer, these CPU registers come into action to execute our program. Each register executes a single instruction.
These registers won't follow our human readable language, it has their own language called " Machine Language". The computer gonna execute programs if and only if the instructions are written in its machine language.
When a computer executes a program, the program will be stored on RAM (Random Access Memory, for a temporary store of data). This RAM consists of several locations which help to store the data in it. These locations are called "Addresses". To access specific data from memory, we use address.
The CPU executes the program only in a sequence of instructions that have been written in machine language in the main memory. It does this by repeatedly reading or fetching an instruction from memory and then carrying out, or executing, that instruction. This process is called the "Fetch and Execute Cycle". The CPU use one of its registers called the program counter to keep track of instruction that is executing and those that are waiting to get executed. The program counter maintains a track or sequence in which the instructions get executed.
At the beginning of the fetch and execute cycle, the CPU checks the program counter to see which instruction it should fetch first.
Machine Language:
Machine language instructions are expressed as binary numbers ( 0 and 1). A machine can understand only the sequence of zeros and ones. Each particular instruction includes a unique sequence or pattern of binary (0s and 1s). To keep it simple, we assume
0 - for transistor off
1 - for transistors on
This on and off of transistor gives an idea that what is the pattern of the sequence of binary.
This much information that how computer work is sufficient.
The Java Virtual Machine:
A machine language consists of very simple instructions that are written in Binary. Most of the famous programming languages are high-level programming languages, which means that these languages cannot be run on a computer directly. First, it needs to be translated into machine language, and then it would be executed. For this translation, compilers come to help us. These compilers help us to translate these programs to convert high-level to machine-level. We can easily understand and read these high-level languages but it's difficult to read, write and understand machine-level.
There is an alternative for compilers, called 'Interpreter". It works slowly as compared with compilers.
The designers of Java programming chose to use a combination of Compilation and Interpretation. Programs written in Java are compiled into machine language, but it is a machine language for computers that don't exist. The virtual computer is known as a "Java Virtual Machine", the machine language for Java Virtual machine is called " Java Bytecode".
One of the main selling points of Java is that it can actually be used on any computer. All that needs is an interpreter for Java Bytecode. Once a computer has a Java Bytecode interpreter, it can run any java bytecode program. This is one of the essential features of Java.
"The same compiled program can be run on many different types of computers".
Building blocks of Programs:
In programming, we work with two aspects - Data and Instructions. To handle the data simply we use variables and types in programming. What is a variable? Simple - It is just a block in which you store your data. This block is one of the blocks from memory, in which all other blocks and data can be stored. This variable includes a unique address, which can be used for fetching and execution in programming. There are certain rules for naming these variables, which will be covered in the next blog.
Type includes what type of data it holds in a variable called type. It is used to sort out a large number of variables with the value actually it can able to hold. Such as integers, float (decimal), large integers, strings, booleans, etc.
In a program, we write instructions in the flow of top to bottom, and also the JVM follows this pattern in terms of executing the program, Most of programming languages take top to bottom approach.
Sub routine:
Sub routine is a separate chunk or block of code in a whole program.
Introducing OOPS:
OOPS ( Object Oriented Programming) is a separate set of concepts in programming which helps you to design a program. It seems weird to you but, OOPS helps us to hide information, inherit some data, polymorph, and many other operations to help us to create useful and authentic software or a program. We will be just discussing only the fundamentals which help you to understand the syntax of Java.
Class: A class is a kind of template or a prototype, by which the objects can be initialized and member functions can be ( if you are confused, please don't worry, and please try to connect the dots when I explain these again in the upcoming detailed blogs. it is just an introduction. It's okay if you don't understand these topics at a single time).
Objects: A java object is a member of a class. Each object has an identity, a behavior, and a state. The state of an object is stored in fields ( variables) and functions to display the object's behavior.
Instance: It is an initializer block in Java. It is a variable that is specific to a certain object in a program. The value of an instance variable can be changed easily by any method in a class. But it is not accessible from outside of the class.
Access Modifier: In java, to provide security to the data from other blocks of the same program, we include access modifiers. These are public, private, and protected. These are used to provide security to our data. It can be initialized using these keywords - public, private, and protected.
Summary:
I believe, as a beginner, these are the must-know concepts to know before you start your programming journey with Java Language. I totally agree with you if you get confused in reading these concepts. Because I had experienced this phase of my journey in programming. But believe me, if you connect all the dots with upcoming blogs in this Java series, you are going to resolve all your queries and confusion.
Follow this link to summarize what I discussed above.
Thank you for reading and make sure to follow and subscribe to my blog to as not to miss my upcoming blogs.