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

CHAPTER 4



Familiarizing Yourself with JAVA Commands


The vast amount of JAVA commands are far too numbered to include every single one in the list here, but this chapter includes a visual of some of the most common and useful commands available to date. The diagrams in this chapter are supplied as an introduction to the name of the most basic commands and also as a visual reference as you make your way through the next chapter, so   you will have numerous ways of checking your work and making more sense of what you have read thus far. These JAVA commands are in no particular order really, with the only exception being the very first command explained in this list, hello world. The Hello World application is by far and wide the most common starting point  for  every  single  newbie  programmer  in  the  world.  There  are  literally millions of different “Hello World!” application codes out there, written by just as many beginner programmers.

An   introduction   to   the   Hello   World   application   code   in   the   JAVA
programming language

There are three primary components that make up the application known as “Hello World!". These components consist of the HelloWorldApp main method, the class definition, and the source code comments. Unless you are already familiar with how to program and utilize commands in JAVA, the further implications of “Hello World!” will be able to be understood only after you have completed reading the rest of the “Hello World!” programming material in this book. Below, the keyword “class” (beneath the first arrow in the first line) launches what is known as the class definition which gives meaning to the class

“name”. It also launches the code for every individual class which appears in between each set of the opening and closing curly braces in the diagram below. For those of you who may not already be familiar with what curly braces are (“{“and “}”), they are a symbol used to execute code in JAVA. In JAVA, every single  application  will  begin  with  a  class  definition,  as  you  will  see  in  the following  chapter.  Also,  when  utilizing  the  JAVA  programming  language,  a “main” method must be used in every application. Lastly, source code comments are only useful to other programmers in order for them to more fully understand the code. The source code comments  are completely  ignored  by the program compiler.


An introduction to Integer variables in the JAVA programming language

When you are writing code with the JAVA programming  language,  every single variable first has to be declared prior to its ability to be used in that code. When working in JAVA, this is referred to as being statically  typed. When a programmer  declares  a variable  that  means  that  the  variable’s  name  and  the variable’s type are both stated very clearly in the code. When the variable’s name and the variable’s type are both clearly stated, this lets your program know that, in that particular code, there is an initial value. It also lets your program know that there is numerical data being held and that there is a particular field named “yournamedobjecthere”  that exists within the program and code. The data type of a variable completely determines the particular operations that are able to be performed on it and also determines the values the variable is able to contain.


An introduction to using an Object in the JAVA programming language

As stated previously in this book, JAVA is a programming language that is very heavily object oriented. When a  programmer is  working in  the  JAVA programming language, then that programmer utilizes objects in order to complete the code task at hand. The programmer will create those objects, modify those objects, move the objects around within the program, change the objects’ variables, call the objects’ methods, and then will also combine those objects with other objects in the code as well. When programming with the JAVA programming language, the programmer will develop classes within the code, the programmer will create objects out of those particular classes within that code, and then the programmer will use those classes in the code with other

classes and other objects within the code.
When a programmer is writing code in a JAVA program, the programmer will define a set of specific classes within the code. As you will learn further in the next chapter of this book, classes are simply just the templates that are used by programmers  in order to create the objects within the programmer’s  code. The objects that the programmer  chooses to create, which are also known as instances, are self-contained aspects of a particular program that also has relative data as well as features. A programmer  will, for the most part, use that class simply to create and define instances within a code and then the programmer will work with those particular instances within that one code. Hence, in chapter
5 you will learn how to be able to create any new object from any class that you have created.
In order to create a brand new object, the programmer must first use a new
operator along with the name of the particular class, and that class is to be used by the programmer and the IDE as a comprehensive template. Keep in mind as you proceed  that parentheses  always  follow the name of the class, no matter what. This will be shown in the next chapter as well. These parentheses are very important, so make doubly sure you do not leave them out or else your code will not execute properly, or may not execute at all. The parentheses following the name of the class can even be left empty. If you leave the parentheses following the name of the class empty, this means that you will have successfully created the  most  basic  object  possible  in  your  code  as  well  as  the  simplest  object possible in your code.
When  you  have  successfully  created  an  object  in  your  code,  you  will probably then decide to utilize that object in writing your program. When you as the programmer decide on how you wish to use your object, you then may have to call one of the object’s methods in order to perform a specific action, you may choose to use a certain value of one of the object’s fields within the lines of code, or you may choose to even change one of the object’s fields altogether.

An introduction to using a class in the JAVA programming language

A  class  is  really  just  a  simple  template or  a  simple  blueprint when  a programmer is creating several different objects. This simple template or simple blueprint will act to define a class’s behaviors as well as a class’s properties. The JAVA programming language class objects show the behaviors as well as the properties as  defined by  the  object’s particular class.  A  class  in  the  JAVA programming language is able to contain methods as well as fields in order to describe how the object is supposed to behave within a line of code and within

an entire program as well.

An  introduction  to  using  String  Data  Type  in  the  JAVA  programming language

Even though the compiler in the JAVA programming language possesses a particularly  special support for the String s, String by itself is not a primitive data type at all since String includes a vast array of characters. In that instance, String is quite simply a reference data type and a class in the JAVA programming language. For the sake of reference, examples of support for the String s include such things as performing what is known as performing String concatenation and also includes the programmer choosing to convert string literals - which is not a primitive type - into String instances, which are a primitive type. When using the JAVA programming language, String actually borrows from the C programming syntax. This means that the JAVA programming language compiler understands String as what is known as char array. Thusly, String is then only an abstract data type in JAVA that is actually made by a primitive data type char array, a data type essentially borrowed from JAVA’s programming counterpart – the C programming language.

The anatomy of an if statement in JAVA

In an ‘if’ statement’s simplest and most basic possible form, it executes a statement  or  block  of  statements  if  a  boolean  expression  proves  to  true.  A Boolean value is only one answer of either 1 or 0, either yes or no, or either true or false. Below is the syntax:

The anatomy of an if-else statement in JAVA

When an ‘if’ statement includes the else clause, it effectively executes a statement if the boolean expression is true or issues a block if the boolean expression is false.

The anatomy of a Loop in the JAVA programming language

In JAVA there are 3 different types of loops. There is the ‘for loop’, the
‘while loop’ and the ‘do-while loop’. The ‘for’ loop (aptly) repeatedly executes a block of statements until the condition that the programmer wrote returns as false.  The  ‘while’  loop  executes  a  block  of  statements  when  the  Boolean

expression turns out to be true and the ‘while’ loop is terminated when that same expression turns out to be false. The ‘do while’ loop is very similar to the ‘while’ loop,  with  the  exception  that  it  processes  the  boolean  condition  only  after executing the block of the statement.

boolean and Boolean defined

First of all a ‘Boolean’ value is a value that has the option of only one of two choices. These choices are either yes or no, either 1 or 0, or either true or false. In the JAVA programming language, Boolean values have a variable type. For example: boolean user = true. Instead of typing ‘string’ or ‘double’ or ‘int’, the programmer simply types ‘boolean’ with a lower case ‘b’.


Post a Comment

Previous Post Next Post