JAVA PROGRAMMING-AN INTRODUCTION, HISTORY, AND THE FUNDAMENTALS FOR CREATING YOUR FIRST PROGRAM CHAPTER 3


CHAPTER 3



Introduction to JAVA Programming Basics



When   it   comes   to   learning   JAVA   programming   language,   or   any programming  language for that matter, there are five basic concepts you must understand before you get started. These five basic concepts include:

1.    Variables
2.    Data Structures
3.    Control Structures
4.    Syntax
5.    Tools


Each of these five concepts will be thoroughly explained in this book on a beginner’s level, to ensure that they are understood.



Variables

Variables are actually the cornerstone of any and all JAVA programs you will run into, and so they are the cornerstone of the JAVA programming language in and of itself. By definition, a variable in computer programming is simply the location of storage as well as the associated name that symbolizes what an unknown or known piece of information or quantity may be. In other words, a particular value. Simply put, a variable is a method of storing some kind of information for use at a later time, and is retrievable by referring to a name or

word which will describe the said information.
For example, let’s say you choose to navigate to a certain website, and the very first thing this website does is ask you what your name is. This is normally done in order to instate some form of human familiarity – upon your next visit, that website  will call you by name. The person who built the website  would create a small text box on the screen that would ask you for your name and that small text box would represent a variable. The person who built the page may decide to call that small text box something like “Visitor Name”, and that would be the symbolic word or name for the small text box variable.
So then after you type your name into the small text box, your name is then stored  as information  in a variable  called  “Visitor  Name”.   This information would be made readily available to the person who had built the page, or the programmer. Then this person would have the ability to revisit the page and ask “What value does the variable “Visitor Name” contain?”, and the program would answer the programmer with the value of whatever you may have typed into that small text box that you saw when you first visited the page.
This concept is used constantly over and over again throughout JAVA programming and it is also super powerful in its programming.   This particular concept is what makes Twitter and Facebook work; it is what allows you to pay your bills using your online banking or banking app, and it is also what makes it possible to place a bid on sites like eBay.   Variables enable the programming world to keep spinning ‘round, as it were.
Okay, now it is time to get a little bit more specific. There are different types of  variables  when  it  comes  to  programming  using  the  JAVA  programming language. If a programmer were to choose to store your name in a variable, your name would be stored as a type of variable  called a String.   Or, perhaps the programmer also wanted to store your age - that would be stored as a type of variable known as an Integer.   Finally, maybe the programmer wanted to store your yearly income – your income would then be stored as a type of variable referred to as a Double. Just to recap, there are three different types of variables being covered here:

String

Integer

Double


So, what exactly constitutes a String variable, an Integer variable and a
Double variable? When using JAVA, the programming language needs to know

what sort of information you will be going to store within a particular variable. The programming language needs to know this because JAVA is what is known as a strongly typed language.   Basically, in order for a language to be weakly typed, that means that the types of all of the variables are inferred, or known at the time of compilation. A strongly typed language, however, does not allow for the use of one type as another type, meaning that it utilizes different types of variables. This is where string, integer, and double variables are put to use.

String Variables

Typing in JAVA programming lets the programming language know for sure that the information  that is being  stored  within  a variable  will be concretely defined. When a string is referred to in JAVA, we are looking at the data as if it were simply a sentence comprised of words in the English language. A String only specifically represents letters placed in a specific order. As in the English language, string variables constitute a series of letters placed in a particular order which gives that series of letters a very specific meaning.
In the way that string variables are made more understandable by comparing it to everyday language, adding two strings together works very much the same way.  If you  have  two  sting  variables  and  they  stored,  for example,  the  data “Visitor” and “Name”, if they were added together you would get the String: “VisitorName”.

Integer Variables

In JAVA, an integer variable means that you have a number that does not include decimal places.  This means a whole number such as 23 or -784. In Java, when it is specified that a variable is an integer, it is simply not allowable to store anything but a whole number.
For example, if you want to add two numbers together, the number 35 and
the number 5. Java actually behaves really differently, it depends upon the exact type of variable being used to storing this data. Then adding 35 and 5 together will result in the integer 40. Instead of just compounding the two, as a string would (when 35 and 5 are added together in a string, you would get 355), the integers are added together in simple math.

The Double Variable

The double variable in JAVA will either use very big numbers or very little

numbers. The minimum values as well as the maximums are respectively both
17 and then 307 zeros.
A double variable can be used to also contain point values that are known as‘floating’.  A  floating  point  value  is  basically  any  numerical  value  with  a decimal point.
The bottom line is that having a type will help you to start to understand what sort of things you are able to do with the information contained within the variable. Types of variables are really powerful and make sense of what is and what is not allowed within a certain variable group.

How data structures are used in the JAVA programming language

A data structure in computer science is a specific method of organizing and storing information in a computer so that it may be used in the most efficient manner possible. To better explain data structures, let’s use the concept of a list of contacts. Usually, a list of contacts contains numerous contacts which could shrink or grow at any time. For this example, let’s say you need to keep five contacts in order. If you were to attempt to represent those contacts as variables in a program, you would need to know data structure.
In this instance, you have a list of contacts. When using JAVA programming, there is a data structure called a list.  This is what the code looks like:

1.    List contacts = new ArrayList();
Do not worry about the symbols just yet, that will be covered later in chapter 5 of this book.  All you need to know at the moment is that there  is a way  to store  a list into  a data  structure.  In a List  data structure you can easily both add items to your list and also remove items from your list.
contacts.add("John Doe (john.doe@somename.com)");
contacts.add("Jane Doe (jane.doe@somename.com)");

When creating a data structure, it is supremely more efficient to create one variable, as shown above, instead of a different variable that you would need to write out for every single item on your list. Because you only created one variable,  contacts.add(RandomContact) that  means  that  your  code  is  more dynamic and flexible.   In this instance, dynamic refers to the fact that the outcome of the program is able to change depending on which variables are inputted. You ideally want your code to be rendered as dynamic as possible, and you also want your code to have the ability to handle a lot of different situations

without needing to have to keep writing more and more code, over and over, as time goes on. Basically,  data structure is just a way to avoid having to create more variables than is absolutely necessary.

How control structures are used in the JAVA programming language

A control structure is a block of programming that analyzes variables and chooses  a  flow  based  on  given  parameters.  It  is  the  basic  process  where decisions are made in computing. Flow control regulates how a computer will respond when it is given specific conditions as well as specific parameters. This means  that  while  a  particular  program  is  running,  the  code  is  read  by  the computer line by line.   This process is known as “code flow”.   As the code is read from top to bottom, it may reach a point that requires some amount of a decision making process. This decision  could result in the code jumping to a different part of that specific program, and it may require that a certain piece of code is rerun, or it may just skip a lot of code in response.  This process could be equated to a ‘choose your own adventure’ book. You reach page 12 of the book, and  you  have  a  choice  between  selection  A  and  selection  B.    A  computer program works much the same way except the program has a strict set of rules to abide by, given by the programmer. The decision that the program makes effects the flow of code, and that is known as a control structure.

How Syntax is Used within the JAVA Programming Language

The syntax of the programming language of JAVA is really just simply the set of rules which define the combinations of symbols considered to be precisely structured programs in that set language. Syntax is basically a particular layout of symbols. In JAVA, an example of this would be curly brackets { } or round brackets ( ). For example, when you look at an email address you are able to identify the fact that it is an email address because of the syntax. You may also identify this as its structure or simply by ‘the way it looks’. You are able to recognize an email address and differentiate it from a website address because of the different syntax that lies therein. Syntax in JAVA programming language is similar. There are rules in place, and when followed, those rules allow programming language to comprehend the functioning software and also allows you to create functioning software. You will receive errors if you do not abide by the rules of a programming languages’ particular syntax.
When using JAVA, there are four specific steps to the syntax of creating a variable. They are as follows:



1.    The first part to the syntax of creating a variable is the use of the word String, which is the variable’s type.   A String in this particular case allows the storage of regular letters as well as the storage of special characters.


2.    The  second  part  to  the  syntax  of  creating  a  variable  is  using  the variable  name.  A  variable  name  can  be  made  up  of  numbers  and letters,   but   the   only   special   characters   they   are   allowed   are underscores.   The first letter in variable  names  are normally  lower case, which is not necessarily a must, but is kind of a rule of thumb in the JAVA programming world.

3.    The third part to the syntax of creating a variable is implementing the value that the particular variable holds.   In JAVA strings are clearly defined by placing quotes around regular numbers, letters, and special characters.

4.   The fourth and final part to the syntax of creating a variable is implementing the mark of completion.  In JAVA, a semi-colon is used. Although there are a few exceptions, nearly all of the lines of a JAVA code will end in a semi-colon;  much like a period at the end of a sentence.


Explanation of the use of tools in the JAVA programming language

A tool that is used in programming  is a lot like any other tool that we as people use in that it helps you accomplish your goal more efficiently – except that JAVA tools are only useful to JAVA programmers, of course. In JAVA, a tool is a piece of software that enables you to get your program completed more quickly. There is a vast array of tools used in JAVA programming, but for all intents and purposes, this book will focus on the IDE.
An IDE is essentially a piece of software which will basically make coding a lot easier and is the most essential tool of every programmer on the planet. IDEs check the syntax of a code to make sure there are no errors. IDEs also organize your files and give you a specific way to comprehensively view them. IDEs tend to incorporate code completion, which actually fills in code for you, in some common scenarios. IDEs enable easy navigation through code.  There

are many more advantages of using an IDE, though the most useful are noted here, and you will become more familiar with using an IDE once you set yours up following the simple step by step guide outlined in chapter 5 of this book.

Post a Comment

Previous Post Next Post