Series Overview: Parts 1 to 10
This series of articles is designed to teach Java programming to the complete beginner. Absolutely no programming background is assumed. There are 20 parts in the series.
Part 1 – This part, the one you’re reading, introduces the series and briefly describes what you can expect to find in each article.
Part 2 - Java: Data, Variable And Algorithm Explained: we explain the foundation concepts of data and variable and then show how to write an algorithm for solving a sample problem.
Part 3 – Java Example: Algorithm And Program For Area Of Square: we show you how to write a program from an algorithm. As our example, we write a program to calculate the area of a square. We introduce the technical terms class, syntax, declaration, input, output and comments.
Part 4 – Test, Debug, Document, Maintain: we discuss the last three stages of the program development process - testing and debugging, documentation and maintenance.
Part 5 – JDK Java Compiler: How to Acquire One: we tell you how to acquire a Java compiler by downloading the Java Development Kit, more popularly known as the JDK. We also tell you how to prepare your program for compiling and execution.
Part 6 - How To Compile And Run Java Programs: we show you how to compile and run your Java program using the Command Prompt window. For convenience, we tell you how to set the Path variable in Windows.
Part 7 – What Are Data Types? we discuss the concept of data types—a fundamental building block of almost all programming languages. The most common data types are numbers and strings. Each data type defines constants of that type.
Part 8 – My First Java Program: we explain the notion of characters, the basic building blocks from which all programs are created, and we begin our programming journey by writing our first Java program.
Part 9 – Java Program Layout, printf and newline: we discuss the importance of program layout. We also introduce the newline character and show how to use it in producing output.
Part 10 – How To Print in Java Using Escape Sequences: we explore how to print the values of variables using printf. We also explain what an ‘escape sequence’ is and how to use one in printf.
Series Overview: Parts 11 to 20
Part 11 – How To Declare Variables And Write An Assignment Statement In Java: we begin to delve into the nitty gritty of Java programming. We show how to declare variables and how to use the assignment statement.
Part 12 – Java Basics And Java Alphabet: we discuss some basic concepts you need to know in order to write programs in the Java programming language. We explain what are syntax rules and the role of the Java alphabet.
Part 13 – Java Tokens And Comments: all programming languages define the concept of a token. In this article, we explain what Java tokens are. We also show how comments are written in Java.
Part 14 – Java Reserved Words, Identifiers And Naming Conventions: we continue to explain some basic concepts required in Java programming. First, we describe the Java reserved words. We then give the rules to follow in making up user identifiers in Java. We end with some naming conventions used in this series.
Part 15 – Integer Data Types: we begin to look a little deeper into the basic Java data types. We discuss the integer types—byte, short, int and long—and show how to declare variables in Java.
Part 16 – Using A Field Width To Print Integers: we discuss how integers are printed in Java. We show what happens when we print them with and without using a field width.
Part 17 – Integer Arithmetic In Java: Integer Expressions And Precedence Of Operators: we discuss some basic ideas of integer arithmetic in Java. In particular, we show how integer expressions are formed using arithmetic operators. We also explain how expressions are evaluated based on operator precedence.
Part 18 – Floating Point Numbers And Expressions: we introduce the basic floating-point types—float and double—in Java. We show how to write floating-point constants, how to write floating-point expressions and how expressions are evaluated.
Part 19 – Printing double And float Values: we discuss how floating-point values are printed in Java. We show what happens when we print them with and without using a field width.
Part 20 – Java double To int And Other Conversions; Expressions With Mixed Types: we explain what happens when Java attempts to assign a double/float value to an int type, a float value to a double variable and vice versa. We also discuss how expressions containing different numeric types (double and int, say) are evaluated in Java.
Java Programming For Beginners
In the article The computer programming process we briefly described the following stages in the development of a computer program:
(1) Define the problem.
(2) Analyze the problem.
(3) Develop an algorithm (a method) for solving the problem.
(4) Write the computer program which implements the algorithm.
(5) Test and debug (find the errors in) the program.
(6) Document the program. (Explain how the program works and how to use it).
(7) Maintain the program.
We now take a more detailed look at each of these stages. In this article, we describe the first three.
Suppose we want to help a child work out the areas of squares. This defines a problem to be solved. However, a brief analysis reveals that the definition is not complete or specific enough to proceed with developing a program. Talking with the child might reveal that she needs a program which requests her to enter the length of a side of the square; the program then prints the area of the square.
We further analyze the problem to;
(a) ensure that we have the clearest possible understanding of it;
(b) determine general requirements such as the main inputs to the program and the main outputs from the program. For more complex programs, we would, for instance, also need to decide on the kinds of files which may be needed. (Think of a file as a place in the computer used for storing things like documents, pictures, programs, even songs and movies.)
If there are several ways to solve the problem, we should consider the alternatives and choose the best or most appropriate one.
In this example, the input to the program is the length of one side of the square and the output is the area of the square. We only need to know how to calculate the area. If the side is s, then the area, a, is calculated by:
a = s x s
An algorithm is a set of instructions which, if faithfully followed, will produce a solution to a given problem or perform some specified task. When an instruction is followed, we say it is executed. We can speak of an algorithm for finding a word in a dictionary, for changing a punctured tyre or for playing a video game.
For any problem, there will normally be more than one algorithm to solve it. Each algorithm will have its own advantages and disadvantages. When we are searching for a word in the dictionary, one method would be to start at the beginning and look at each word in turn. A second method would be to start at the end and search backwards. Here, an advantage of the first method is that it would find a word faster if it were at the beginning, while the second method would be faster if the word were towards the end.
Another method for searching for the word would be one which used the fact that the words in a dictionary are in alphabetical order—this is the method we all use when looking up a word in a dictionary. In any situation, a programmer would usually have a choice of algorithms, and it is one of her more important jobs to decide which algorithm is the best, and why this is so.
In our example, we must write the instructions in our algorithm in such a way that they can be easily converted into a form which the computer can follow. Computer instructions fall into three main categories:
(1) Input instructions, used for supplying data from the ‘outside world’ to a program; this is usually done via the keyboard or a file.
(2) Processing instructions, used for manipulating data inside the computer. These instructions allow us to add, subtract, multiply and divide; they also allow us to compare two values, and act according to the result of the comparison. Also, we can move data from one location in the computer’s memory to another location.
(3) Output instructions, used for getting information out of the computer to the outside world.
Before we can write the algorithm for solving this problem, we need to explain a little bit about variables. We do this in our next article Java: Data, Variable And Algorithm Explained.
This post is part of the series: Introduction to Java Programming
This is a series which aims to discuss and teach Java programming to the complete beginner. Absolutely no programming background is assumed.
- Introduction to Java Programming - An Overview
- Java - Data, Variable and Algorithm Explained To A Beginner
- Java Example: Algorithm and Program For Area of Square
- Java Programming For Beginners - Test, Debug, Document, Maintain
- JDK Java Compiler: The Java Development Kit
- Java Programming For Beginners - How To Compile And Run Java Programs
- Data Types, Constants And Variables
- Java Programming For Beginners - Characters and printf
- Java Programming For Beginners - Part 9
- Java Programming For Beginners - Part 10
- Java Programming For Beginners - Part 11
- Java Programming For Beginners - Part 12
- Java Programming For Beginners - Part 13
- Java Programming For Beginners - Part 14
- Java Programming For Beginners - Integer Data Types
- Java Programming for Beginners - Part 16
- Java Integer Arithmetic For Beginners
- Java Programming For Beginners - Part 18
- Java Programming For Beginners - Part 19
- Java double to int and Other Conversions