The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.

Coding for Absolute Beginners Master the Basics of Computer Programming with Python, Java, SQL, C, C++, C, HTML, and CSS (Warner, Andrew)

Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by jordanha0808, 2022-07-04 03:11:36

Coding for Absolute Beginners Master the Basics of Computer Programming with Python, Java, SQL, C, C++, C, HTML, and CSS (Warner, Andrew) (z-lib.org)

Coding for Absolute Beginners Master the Basics of Computer Programming with Python, Java, SQL, C, C++, C, HTML, and CSS (Warner, Andrew)

CODING

FOR

ABSOLUTE BEGINNERS

Master the Basics of Computer Programming with Python, Java,
SQL, C, C++, C#, HTML, and CSS

ANDREW WARNER

Copyright © 2021 by Andrew Warner.
All rights reserved.

No part of this book may be reproduced in any form on by any electronic or mechanical means,
including information storage and retrieval systems, without permission in writing from the publisher,
except by a reviewer who may quote brief passages in a review.

Book and cover design : Raphael A.
Printed in the United States of America
ISBN-13 : 9798543586372
First Edition : July 2021

For information on translations, please e-mail [email protected], or visit http://www.aqpub.com

DEDICATION

MY PARENTS

For raising me to believe that anything is possible

AND MY WIFE

For making everything possible

CONTENTS

PREFACE
CHAPTER ONE: WHAT IS PROGRAMMING?

Problem Solving with Computer Programming
Basics of Programming
The Programming Environment
CHAPTER TWO: JAVA
Overview and Basic Syntax
Java Identifiers and Modifiers
Object, Classes, and Constructors
Basic Data Types and Variables
Operators, Control Statements and Decision Making
Characters, Strings, Arrays, and Regular Expressions
Files and I/O
Object Oriented Java
Abstract Class and Abstract Methods
CHAPTER THREE: SQL AND DATABASE
What is a Database?
Structured Query Language (SQL)
Advanced SQL
Constraints and Useful resources
CHAPTER FOUR: C
Introduction and Simple Programs
Starting with C Programming
Methods and Variable declaration
Data Types and Variables

Loops and Functions
Methods to Pass an Argument to a Function
Arrays, Strings, and Linked Lists
Pointers and Structures
Structures
C Programming files
Essential Tips to Make C Programming Easy
CHAPTER FIVE: C++
Basic Syntax
Variables and Data Types
Modifier Types and Storage Classes
Flow Control
Loops and Functions
Arrays, Strings, Pointers, and References
Object Oriented C++
Friend Function, Data Structures, and Encapsulation
File Handling
C++ Language Features and Support
CHAPTER SIX: C#
Overview and Basic syntax
Datatypes and Variables
Operators
Functions and Methods
Arrays, Strings, and Structures
Classes and Objects
Inheritance and Polymorphism
Constructors
Exception Handling

Multithreading
File I/O
Advantages of learning C#
CHAPTER SEVEN: PYTHON
Overview and Basic syntax
Features
Variable Types, Basic Operators, and Data Types
Flow Control
Functions and Modules
Object Oriented Python
Regular Expressions
Advanced Python
Tips for Learning Python
CHAPTER EIGHT: HTML
Introduction and Overview
Basic Tags and Attributes
Tables, Images, and Frames
Designing
Meta Tags
HTML Style Sheets
Layout and Responsiveness
HTML Templates
Helpful Tips for Using HTML
CHAPTER NINE: CSS
What is CSS?
Types of CSS
Basic Syntax and Inclusion in HTML
Importing CSS file

Colors and Backgrounds
Formatting and Design
Margins and Padding
Font and Text
Text
Links, Tables and Margins
Lists, Icons, and Dropdowns
Layers and Visibility
Layout and Animations
How to Effectively Use CSS
CHAPTER TEN: PROGRAMMING ESSENTIALS
Selecting the Programming Language
Tips for Efficient Programming
Strengthen Your Basic Skills
CONCLUSION

PREFACE

Coding for Absolute Beginners is a complete and authentic guide for students
who are determined to learn the best programming approaches, techniques,
and methodologies. As the software industry is updated with the latest coding
languages and tools every day, it is mandatory to adopt new skills and
technologies to survive in the competitive market. Reading has always been a
vital resource for students and learners as they can improve their performance
and output by implementing the latest techniques and programming
methodologies.

This book is a successful programming manual covering all of the major
programming languages, syntax, and best practices that are suitable for both
beginners and professionals. Before entering into the programming world,
there are several important factors that need to be looked at in order to
develop sharp problem solving and analytical skills. Therefore, this book
targets novice programmers and has been updated with solutions and answers
to almost every question you might have about Java, SQL, C, C++, C#,
Python, HTML, and CSS.

I always emphasize the acquisition of basic knowledge and skills. This book
will not make you a programmer in just one hour or overnight, but it will
build a solid foundation for your programming career. After reading this
book, your basic knowledge of programming will increase, as will your
proficiency in any programming language.

Many people have helped me in many ways in writing this book with their
important feedback and encouragement and correcting various mistakes. I am
eternally grateful to all of them. Especially, Mr. Steve, my then CS thesis
supervisor at Harvard University. He knew more than a year ago that I was
writing a programming book. After sending him the draft of my book in

December (2020), his reply was- "I just have gone through your book. I have
been thinking about writing a book like this for the last five or six years- you
have done it- I do not need to do it anymore. thank you."

On a personal level, I have to thank my wife Rachel and son Aaron for their
never-ending patience and support.

I hope that Coding for Absolute Beginners be your best friend in your
programming journey and help you become proficient in computer
programming.

May the source be with you. </>

CHAPTER ONE

WHAT IS PROGRAMMING?

Generally, programming is referred to as a set of instructions that the
computer utilizes to complete certain tasks. This is also known as coding.
Before delving into an in-depth discussion, you must be well aware of how
programming works and how the set of instructions are processed by the
computer. When you are able to follow the correct approach of writing
computer programs, it can become quite easy to implement functions,
operators, and syntax for any language. Moreover, programming is a way to
communicate with computers through binary language for which
programmers need to understand high level and low-level languages
including syntax as well.

In order to solve a problem with a computer, users are required to present the
solution for the problem through a set of instructions which can be utilized to
execute the program. As a program is a collection of instructions that are
required to solve a problem, appropriate statements and functionality must be
added in order to achieve the desired outcome. For example, if you are given
the task to develop a program to add two integers (numbers), the set of
statements that will perform the addition operation will be known as the
program. The algorithm for adding two integers will be expressed through the
statements of a particular computer language like C++, C, C# or Java. If the
program is not able to execute properly, there might be a problem with your
algorithm or syntax because the compiler or editor will be unable to execute
the program if there are any type of errors or syntax mistakes.

Programming can be better learned through practice and writing code rather

than learning long methodologies or complex techniques. Although it might
seem like a fun activity at the start, it can also turn out to be time-consuming
and frustrating if you are not following the correct approach. Furthermore,
this book will make it easier for beginners to choose the most suitable
programming languages and enter the world of computer programming
without much hassle.

Problem Solving with Computer Programming

In essence, a computer program is supposed to solve a specific problem by
following a set of instructions. People can write a program by following
multiple techniques and approaches. In order to solve a problem, you need to
determine the code flow and fulfill the requirements step by step to achieve
the desired output. In some cases, your computer program may not work even
after hours of struggle because of inappropriate syntax or flow for which you
need to focus on the sequence of instructions and computer programming
language requirements.

Using this example of preparing a wooden table, you would need to write
down the instructions as follows:

1. Get the most suitable pieces of wood required to make the table.
2. Get the essential tools and equipment that will be used during

the procedure.
3. Join the pieces and build your table.
4. Polish the end product to make it look attractive.

When giving such instructions to the computer, you need to be more specific
and precise because a computer cannot perform operations on its own. As it
is created to follow instructions, your computer program should always
follow an incremental approach in order to achieve the desired outcome.

On the topic of the natural language of a computer, they are unable to
understand human language and therefore, we need to communicate with the
system through another language called binary code. Binary code is made up
of a series of 1s and 0s and is the natural communicating language of
computers. In order to help the computer understand human language, we

use translators and editors for writing programs. Translators have the
capability to convert the source code into the machine’s language.

There are multiple types of translators known as Interpreters, Compilers, and
Assemblers. Interpreters are generally used to interpret languages which are
then processed line by line to run the final program. Moreover, any syntax
errors or mistakes are also outlined by the interpreter so the programmer can
clear out the mistakes and execute the program.

With the help of compilers, the source code is converted to binary code
through a compilation process and is then executed to deliver the output. If
there are no errors or mistakes in the source code, all of the lines are
translated and executed at once by the compiler. Moreover, computer
programs are also known as Apps (application or application software) and
are tailored to the environment or platform they are designed to run on. Apps
are differentiated in the categories of desktop applications and mobile
applications as well.

Basics of Programming

Introduction to Computer Programming

Every computer program is a combination of procedures, processes, and
algorithms that complete the source code. As this process combination can
also be considered a representation of a software, the process is referred to as
a series of actions to achieve an output whereas the procedure can be
considered as a series of actions performed in a specific order. Algorithms are
the main driving force of any program, also known as an ordered set of steps
to solve a certain program or problem.

There are different high level and low-level languages that can be used to
write a computer program. Nowadays, programs and software are generally
made by using popular languages which include C, C++, Java, Python,
HTML, PHP, Ruby, and Perl. These languages are used to produce computer
programs that are currently being used in various fields and industries
including the medical, engineering, communication, household, and
entertainment industries. Furthermore, computer programs are also being

used to create graphics, web applications, and desktop applications as well.

Elements and Basics of Computer Programming

Usually, computer languages are a combination of several elements that
allow programmers to achieve an expected output. These elements include
the basic syntax, programming environment, data types, keywords, variables,
decision making, basic operators, and functions. Moreover, in order to
perform certain operations within a program, you need to apply other
operations and use elements including loops, strings, characters, File I/O, and
arrays as well.

There are five different basic elements of programming that are also
considered as the building blocks of any program. The elements are known as
Input, Output, Arithmetic, Conditional, and Looping. Starting with the first
element, Input is the process of getting commands and data into the
computer, whereas the Output element has the functionality to deliver the
results. If there are any sort of calculations or operations, the Arithmetic
element is used along with the Conditional statement to test whether the
condition is true or false.

Environment, Data Types, and Basic Syntax

Environment

In order to run or execute a program, you must install or setup the required
tool and environment for the language you are using. Moreover, beginners
can also use a text editor to create computer programs if they find it difficult
to install and configure the programming environments on their own. To
execute the programs into binary format, it is mandatory that you use a
compiler because the computer cannot understand a program directly if given
in the text format.

Moreover, the conversion of text into binary format is done by the Compiler
through which programmers can run and execute the program as well.
Programming languages including C, C++, C#, and Java need the
compilation in binary format whereas other languages such as PHP, Perl, and
Python can be compiled directly as well.

Basic Syntax

To make it easier for beginners, we will be starting from the grassroots level
and write a “Hello World” program in C++. This sample program as written
below will make it easier for you to understand and begin writing your first
program.

1 #include <iostream>
2 using namespace std;
3
4 int main()
5{
6 cout << "Hello World!";
7 return 0;
8}

The output for this respective Hello World program is as follows:

Hello World!

Each program that is being written in C++ starts with #include <iostream>
and main () which is also known as the main function. The program is then
continued with functions, characters, loops, strings, or arrays depending on
the requirements. In the program written above, main () is used as a function
whereas cout is the standard output stream that is implemented to print
“Hello World!”. At last, return 0; is written as the exit status of the program
which is also necessary for program execution.

If you are unable to execute the program, there might be some possible
syntax errors or typing mistakes that are not being processed by the compiler.
As it stops the program from compiling, small typing errors such as the
omission of a single comma, semi-colon, or dot are most likely to be the
cause. So, if you are not properly following the syntax as defined for the
programming language, your program might not compile or execute in this
case.

Data Types

Data types are an important part of various programming languages and are
used when creating computer applications. As it classifies every object or
variable that is being written in the program, data types tell the compiler how

to use the provided data in order to perform certain operations. Generally,
commonly used data types include integer, real, Boolean, characters,
alphanumeric strings, and floating-point numbers.

Briefed details of data types are given as follows:

Date: 01/04/2015
Integer: 1,52,13424
Boolean: True/False
String: ab, aabb
Void: No data
Long: 5325433253
Floating point number: 5.2341
Short: 0

Syntax

As stated previously, a program is defined as a collection of elements and
attributes that perform certain operations to deliver a specific output. With the
C++ programming language, there is a predefined basic syntax that needs to
be followed when writing programs. Let us briefly look at an overview of
how the basic syntax of the programming language works.

1. Class: Class is a defined data type and has its own member functions and
data members. For example: consider the class of a school, the data members
will be teachers, students, admin staff, etc.

2. Object: An Object is an instance of a class that has their own behavior and
states. For example, a car has different colors, models, specifications, etc.

3. Methods: Method is referred to as the behavior and is responsible for the
execution and manipulation of different actions within the class.

Programming Variables, Keywords, Operators, and Decisions

Variables are an essential part of a computer program as they provide
computer memory locations required to store values and data in a computer
program. In order to save a value, you will have to create variables and assign
them a proper name, store values into the variables, and retrieve the given

values back from the variables.

To get started with declaring variables, we will have to write the program as
follows:

#include <iostream.h>
int main() {

int a;
}

The above written program creates a variable named “a” and is specified by
an int keyword. This means the variable can only store an int type value and
you are not allowed to define “a” again to store another type of value in the
variable.

To store a value into the variable, just declare the number that you want to
place in “a” after the declaration of a variable in the program.

Keywords

There are different keywords for every programming language that are used
for various purposes. Although each language provides a complete set of
reserved keywords, there is a common rule that needs to be followed while
using the keywords. Same as float, int, long, and string, other keywords that
are mostly used in every programming language are as follows:

Else
Switch
Goto
Static
Case
Break
Enum
For
If
Union
Double
Private

Operators

Operators are the key aspect of any programming language and are required
to perform certain operations or logical computations. As they are generally
used for mathematical calculations, we can solve complex equations by using
various expressions in the program.

There are two kinds of operators that are generally used in programming
languages:

1. Arithmetic Operators: Operators that are used to conduct mathematical and
arithmetic operations. For example: +,-,/,--,++,*.

Binary Operators: Operators that work with other operands such
as +,-,/,*.
Unary Operators: Operators that are used to work with a single
operand. For example: ++,--.

2. Relational Operators: These are the most commonly used operators that
tell us whether one operand is equal to another or not. For example: ==, <==,
<==, >==.

Here is a table detailing basic operators and their functionality within the
program:

Operator Functionality

+ Addition of two operands

- Subtraction of two operands

/ Division

* Multiplication

== Check whether the two operands are equal or not

>= Check if the left operand is greater than or equal in
value as compared to the right operand

<== Check if the left operand is less than or equal in value
to the right operand

Logical Operators are also an essential part of all programming languages.
They are used to obtain certain decisions in various scenarios. These
operators are AND, OR, and NOT. They are used to prove true or false
statements as well.

Decisions

Decision making is a process in which the programmer has to select one
option based on the two or more given conditions. You will have to test
whether the condition is true or false and present the correct output.

For different programming languages, the decision-making statements are
briefed as follows:

‘If’ statement
‘Else’ statement
Switch
‘Else if’ statement
Conditional Operator

Programming Characters, Arrays, and Strings

In programming languages, Char type is used to store characters and letters.
They are also responsible for storing values and delivering output whenever
the character is called within the program. You are only allowed to store a
single-digit number or alphabet inside the single quotes such as &, @, * or +.

The example code for defining characters is as follows:

Char ch1 = ‘a’.

Arrays

An Array is a data structure that has the capability to store a sequential
number of elements of the same type and is generally of a fixed size. As it is
comprised of contiguous memory locations, it is also known as the set of
elements stored under the same name. If you are writing a program to store
10 integers in sequence, creating an array of 10 will be the best possible

solution.

This is how an array of a fixed number of values is declared:

int data[10];

The two popular types of array are known as:

1. One-dimensional arrays.

2. Multi-dimensional arrays.

Accessing arrays

After you are done with the declaration, you can easily access the elements
through indices. Arrays have 0 in the first index and the if the size of an array
is n, you will have to use the condition n-1 to access the last element.

To initialize the array, you can follow the pattern as follows:

int arr[5] = {1, 2, 3, 4, 5};

Arrays allow the programmers to store data into individual variables without
defining every variable specifically. Similar to other data types, arrays are
declared by using [ and ] brackets, and once the array has been declared, you
can assign the values. There are different ways to create, assign, and declare
arrays in a program.

Declaration

In order to declare arrays, you must remember that array size must be an
integer greater than 0. An array can be declared as follows:

Type arrayName [ arraySize ];

Initialization

To initialize an array, you can use the statement mentioned below:

Int Arr[5] = { 23,45,53,64,73}

Strings

String is a data type that is used in programming languages to represent an
array of characters. To declare and initialize a string, you need to follow the
same structure as the arrays. There are different techniques and ways to write

strings for every programming language but the functionality is the same in
each case. A string can also contain spaces in a phrase such as “ I have been
waiting since 5 pm.”

The example of a string is as follows:

char c[] = "abcdef";

Functions and File I/O

Functions

A function is known as a block of code which performs a specific task within
the program. There are two types of functions in programming called
Standard Library Functions and User Defined Functions.

The standard library functions are assigned the duty of handling major tasks
such as I/O processing, computations, and data handling whereas the user
defined functions are created by the programmers themselves to perform
specific tasks. Functions are more like a reusable code that can perform
certain actions and provide better modularity for the program as well.

To define a function in C programming, you need to declare a Return Type,
Function Name, Parameter List, and Function Body.

For example:

#include <iostream.h>
void functionName()
int main()
{

functionName();
}

File I/O

To store and manage computer files such as images, word documents, plain
text, or excel sheets, we take support from the File Input/Output operation
modes. With File Input, the approach is used to write any data into the file
whereas the File Output method is used to display results from a file.
Generally, a file can be opened in different modes such as Read-Only mode,
Write-Only mode or Read and Write mode.

There are specific functions for every programming language to open, read,
or create a new file. To open the file, the recommended function is fopen()
and for closing the file, you can use the fclose() function.

The Programming Environment

What is the programming environment?

The development environment is a combination of programming tools and a
set of processes that are used collectively to run the program. depending on
the language in which you are writing the program, you can select the best
suitable environment and complete your projects by following the provided
instructions. Because programming is how we achieve different solutions and
outputs, we can express our ideas in multiple ways through programming
tools and the environment.

Furthermore, compilers execute the algorithms in a step-by-step approach
and perform other activities such as selection for decision-making, sequential
processing, and iteration.

Integrated Development Environment

An Integrated Development Environment is referred to as a software where
the tools and processes are connected to bring a convenient interface into the
programming environment. Known as an application, the Integrated
Development Environment (IDE) also facilitates application development
and provides a graphical user interface (GUI)-based working approach to the
developers. Modern IDEs can also be used to generate structure diagrams,
flowcharts, and give a modular approach towards programming.

In order to select an IDE, you can overview your language requirements and
programming style as well. This can make it easier for you to finish complex
applications and bring in better results.

Tools and Technologies

There are thousands of software development tools, IDEs, and technologies
that can be used to create perfect applications, programs, and software. We
have listed and briefed some of the most effective, easy to use, and state of

the art tools for programmers to develop any kind of web, desktop, and
mobile application.

Here are some of the best tools for beginner programmers:

NetBeans

NetBeans is an open-source integrated development environment that can be
used as a tool to develop desktop, web, and mobile applications. Allowing for
an easy and efficient project management process, the tool allows developers
to write bug-free code and provides a smart code editing facility as well.
Furthermore, the IDE is best suited for PHP, C++, and C programming
languages.

Cloud9

When it comes to online integrated software development environment,
Cloud9 is surely one of the best tools to be considered. The supporting
languages include PHP, C, C++, Python, Perl, Node.js, and JavaScript.
Developers can choose an extensive set of default runners to execute an app
and code faster with the provided suggestions.

Visual Studio

Visual Studio is a supreme Integrated Development Environment designed
and developed by Microsoft. Supporting a wide range of platforms,
developers can now build, secure, share, and manage software components
without any hassle. Furthermore, the Automated and Azure deployments
allow you to improve code quality along with the support of a centralized
vision control system.

Technologies

Learning programming languages and technologies can be the best way to
adapt to the latest programming approaches and techniques. Starting with
major programming technologies such as JavaScript, Python, Java, and C++
can make it quite simple for beginners to develop a better understanding of
computer programming. Furthermore, each technology has its own
perspectives and methodologies for which you have to learn the concepts and
approaches in depth.

For open-source developers, Java is considered as the best programming
language due to the Java Virtual Machine (JVM) paradigm. This allows the
software to run on any system. Beginners can also start practicing
programming from C++ because it gives access to very low-level system
components and simple methodologies.

Methodologies

Programming Methodology is the process of analyzing complex problems
and planning the software development process in order to achieve the best
possible solutions. Also known as modular programming, the software
development process is categorized as follows:

1. Requirement gathering

As this is the first stage in the Software Development Life Cycle process, it is
performed by experts and professionals who can easily conduct a feasibility
study for the project. The outcomes and technical approaches are discussed
so that the project can be completed without any issues.

2. Requirement Engineering

The next step is to gather the relevant data and define requirements that are
needed to get the project done. Usually, we have to create a Software
Requirement Specification (SRS) document that is comprised of all of the
essential design and development data. The system analyst has to be clear
about client requirements and needs to give a detailed briefing to the
developers so that they can write the code accordingly. Usually, the clients
are not able to clearly define their requirements and give guidelines in
general.

3. Designing

After we are done with the requirements engineering, the next step is to
design the architecture as specified in the Software Requirements
Specification (SRS) document. At this point, you are required to outline the
design modularity, time constraints, and product specifications as well.

4. Development

This is the stage from which the developers will start working on the project
by following the instructions and guidelines from the project manager. For
each project specifically, a programming language is selected after extensive
research and development so that the actual requirements and functionality of
the client can be completely satisfied.

5. Testing

This stage involves the checking and inspection of the software by
overviewing the client requirements. By using various test cases, the product
is checked for errors, mistakes, and areas that need improvements to make
sure that each requirement is completely satisfied and operational.

6. Deployment

Deployment is the last stage of the SDLC process. As the product has now
passed through the design, development, and testing procedures, it is ready to
be delivered back to the client. depending on the business strategy, the
product can also be released in the market or as per the instructions given by
the client.

Front End Technologies

Front-End development is generally referred to as the development of user
interfaces by the implementation of design, structure, and animation for web
applications. The core technologies that are used for front-end development
include HTML, CSS, and JavaScript whereas professional developers might
also use the latest technologies such as AJAX, AMP, or Angular.

Hyper Text Markup Language (HTML) and Cascading Style Sheets (CSS)
are the basic building blocks for creating websites and are also used to
enhance the responsiveness of web pages. HTML, JavaScript, and CSS are
the three primary technologies for front end development.

Document Editors

To create software documents, presentations, charts, graphs, or animations,
there are several document editing tools available. Starting with the most
popular tool, you can install Microsoft Office and edit any type of document
without any hassle. The package includes Microsoft Word, Microsoft Excel,

Microsoft PowerPoint, Outlook, OneNote, One Drive Access, and other
modules as well.
Furthermore, Google Docs is yet another helpful document editing tool which
can be used online to access, update, and create documents. The tool lets you
create sheets, docs, slides, and forms for which you can select from a wide
range of templates.

CHAPTER TWO

JAVA

Overview and Basic Syntax

Java is a high-level programming language which was released by Sun
Microsystems in 1995. There are unlimited websites and applications built
using Java technology because it is reliable, easy to use, and faster compared
to other programming languages. Being an object-oriented programming
language, developers can code, compile, execute, and test programs much
faster. Furthermore, the applications developed using Java are adaptable to
multiple environments and are more secure as well.

The language is made to run on different platforms including Windows,
UNIX, and Mac OS for which multiple configurations are provided. Being
absolutely platform independent, J ava is compiled into platform specific
machines and the byte code is then distributed and interpreted through Java
Virtual Machine (JVM). Moreover, Java byte code enables high performance
and is designed for a distributed internet environment as well.
Moving on to the basic syntax, Java programming is generally based on
Objects, Classes, Methods, Variables, Modifiers, Constructors, and Regular
expressions. To better understand the simple java program, you can undergo
the brief details of each aspect as follows:

Keywords Functionality
Class Used to declare a class
Void Return type
Public Access modifier to make the function visible
Static Used to create an object in static method
Main() Main () method is placed at the start of the
program
System.out.println() Prints statements on the console

Before you begin with Java programming, make sure that you remember that
Java is a case sensitive language and you need to declare the class names
with the first letter in upper case. Method names should start with a
lowercase letter and the name of the program file should be exactly the same
as the class name to avoid any problems when executing the program.
The concepts in Java programming language include Classes, Objects,
Polymorphism, Inheritance, Abstraction, Encapsulation, Instance, Method,
and Method passing.
Your first Java program might look like this:

class HelloWorld
{

public static void main(string[] args)

{

System.out.println ("Your first Java Program!")

}
}

Java Identifiers and Modifiers

Java Identifiers should begin with a letter from A to Z or a to z because the
identifiers are case sensitive as well. You must remember that a keyword can
never be used as an identifier and identifiers can have any combination of
characters after the first character. For example, month, $price, or _place.
There are two types of modifiers in the Java programming language. One is
known as Access modifiers whereas the other is called Non-access modifiers.
Modifiers are generally used to modify methods or classes.

Object, Classes, and Constructors

Classes and Objects

Objects are a part of classes and are also known as instances of classes. A
class represents a set of properties that are common to all of the objects and is
a defined prototype from which the objects are created. To declare a class, we
will have to include Modifiers, Class Name, Superclass, Interfaces, and
Body.
Furthermore, everything in Java is associated with objects and classes that are
combined with methods and attributes as well. Take an example of a mobile
phone in real life, it has attributes such as color, memory, display, and
weight.
To create a class in Java, you need to follow the syntax as mentioned below:

Public class NewClass {
Int a = 1;

}

To create object called “newObj”:

Public class NewClass {
Int a = 1;

Public static void main (String[] args ) {
MyClass NewObj = new NewClass();
System.out.println(newObj.x);

}
}

Creating an object requires declaration, instantiation, and initialization.
Declaration is the process of declaring a variable name along with an object
type whereas Instantiation is used to create an object with a new keyword.
The program is then continued by a call to the constructor in order to
initialize the new object.

Basic Data Types and Variables

In a Java program, the data is stored in variables and the program at first
declares the variables, reads data onto the variables, and then executes the
provided operations. Once the process is completed, the variables are then
written once again at a new location. Variables provide a reserved memory
location to store values and the memory is allocated by the operating system.

Data Types

There are two different data types in Java programming language known as
Primitive Data Types and Object Data Types. Primitive data types are
classified into 8 categories: Byte, Short, Int, Long, Float, Double, Boolean,
and Char. Object data types are created by using the constructors of the
classes and they are also responsible for accessing objects. The default value
of every available reference variable is set to null and it can also be used to
refer to an object of the declared type.

Variables

There are three types of variables used in the Java programming language:

1. Local variables
2. Instance variables
3. Class/Static variables

Local variables

Local variables are generally declared on constructors and methods. As they
are created with a constructor, access modifiers cannot be used along with
local variables. There is no default value for local variables.

Instance variables

Instance variables are declared within a class and it is created whenever an
object is created. They are supposed to hold values that are referred to by
more than one constructor or method. Access modifiers can also be given to
instance variables.

Operators, Control Statements and Decision
Making

Operators

The basic operators that are available in the Java programming language are
explained as follows:

Arithmetic Operators: Arithmetic operators can be used to
perform mathematical calculations and equation solving within
the program. This includes Addition, Subtraction, Multiplication,
Division, Modulus, and Increment and Decrement functions.
Unary Operators: Postfix: expr++ and Prefix ++expr –expr
expressions.
Logical Operators: (A && B) for false, (A || B) for true and !(A
&& B) for true.
Bitwise Operators: To perform bit-by-bit operation.
Assignment: =, +=, |=, ^=.

Control Statements

The control statements for the Java language are similar to that of other major
programming languages such as C or C++. The conditions are briefed in
detail as follows:
If Else: The if statement is used to check whether the given condition is true
or false. There are different types of if statements in the Java programming
language which are called an if statement, if-else statement, if-else-if ladder,
and nested if statement.
Here is a simple Java program to demonstrate the if statement:

1 public class Marks {

2 public static void main(String[] args) {
3
4 int Marks=50;
5
6 if(age<50){
7
8 System.out.print("Your marks are less than 50");
9
10 }
}
}

Output for the above program is: Your marks are less than 50.
If-else: The statement is used to test the condition and if the results are true,
the If block is executed and in case of false, the else statement is executed.
Switch: The Switch statement is used to execute a single statement from
multiple conditions. The statement can work with data types including short,
int, long, byte, String, and Long.

Syntax for Switch Statement is given as follows:

switch(expression){
case value1:
//code to be executed;
break; //
case value2:
//code to be executed;
break;
default:
code to be executed if all cases are not matched;
}

Loops

There are three kinds of loops in programming languages that are used in
general.

For loop
While Loop
Do-while Loop

For Loop

For Loop is used to perform iteration in a part of the program. If the number
of iterations is fixed, you are advised to use For Loop in your program.

While Loop

While Loop has the characteristics to repeat a single or group of statements to
test whether the given condition is true or not. It is used when the number of
iterations is not fixed.

Do While Loop

The Do While Loop is used to iterate a part of a program several times. If the
number of iterations is not fixed, you are required to execute the program at
least once.
There are specific loop control statements that are required to change the
execution into a normal sequence. The two control statements used in Java
programming language include:

Break statement: Terminates the switch or loop to start the next
loop.
Continue statement: Allows the loop to retest its condition and
skip the rest of the body.

Decision Making

The decision-making structure features one or more conditions that need to
be tested under a given scenario. If the condition is true, the next statement
can be executed whereas the program would terminate if the given condition
is false. The diagram below correctly shows how the decision-making
process actually works:

Characters, Strings, Arrays, and Regular
Expressions

Java programming language makes use of Character wrapper class and offers
multiple static methods for manipulating characters. To create a character
object, you need to follow the syntax as follows:
Character ch = new Character (‘a’);

The compiler will automatically create a Character object and if you pass any
primitive char into the method, the compiler will convert the Char into
Character by using various approaches from the language.
As we have discussed the importance and functionality of strings before, Java
platform also provides the support from string class. Programmers can
manipulate strings in multiple ways. The sample code for creating a string in
the Java language is as follows:

public class NewString {
public static void main(String args[]) {

char[] StudentArray = { 'S', 'T', 'U', 'D', 'E', 'N' , 'T'};
String StudentString = new String(StudentArray);
System.out.println( StudentString );

}
}

The output for this program is: Student.

Moreover, we can also concatenate strings by using a simple concatenation
approach in Java programming language as follows:
String1.concat( string2);
To create a string object in Java, programmers can choose either a literal or
keyword approach.

Arrays

Arrays are a vital part of every programming language as they allows
programmers to handle and store data into variables. As they are used to store
a large collection of data, you can also consider an array as a collection of
variables of the same category. To declare an array, you can follow the
simple syntax as briefed below:
datatype[] arrayRefVar;
Creating an array in Java is simple for which you can use the following
syntax:
arrayRefVar = new datatype[arraySize];
This statement will create an array of the given size and assign the reference
of this array to the given variable as well. Usually, the arrays are processed
by using for loop or foreach loop because the elements inside the array are of
the same type and size.
Static methods for sorting, searching, comparing, and filling array elements:

Public static int binarySearch(Obkect[ ] a, Object key)
Public static void fill(int[ ]a, int val)
Public static Boolean equals(long[ ]a, long[ ] a2)
Public static void sort(Object[ ] a)

Regular Expressions

Regular expressions is an API that is used to define string patterns and is also
used for searching, editing, and manipulating text. Java has predefined
java.util.regex package that consists of a Pattern class, Matcher Class, and
PatternSyntaxException object. The Pattern class requires the developers to
start with the compile() methods and return a pattern object as it provides no
public constructors.
For the Matcher class, the matcher object finds and compares the operations
against an input string in order to obtain a Matcher object through the
Matcher() method. The PatternSyntaxException is used to indicate an error or
mistake in the regular expression pattern.

Files and I/O

Java programming language features a built-in package that is responsible for
data input and output operations. The stream is known as java.io and supports
multiple operations and functionality to handle data. There are two general
types of streams in Java which are known as Input Stream and Output
Stream.
Input Stream is used to read data whereas the Output stream is used for
writing data in a file.
Java language features various I/O data handling streams that include the
following:

Byte Streams
Character Streams
Standard Streams
File Input Stream
File Output Stream

Object Oriented Java

Object Oriented Programming is an approach that includes the use of classes
and objects. By using multiple concepts such as inheritance, polymorphism,
Encapsulation and Abstraction, programmers can develop java applications
and programs.

Inheritance

Inheritance is a feature in Java programming language that allows it to inherit
the features and properties of another class. This can be done between the
subclass and superclass. The class whose features are inherited is called the
superclass whereas the class that inherits the properties of another class is
called as the subclass.
To use Inheritance in Java programming language, you can follow the syntax
as mentioned below:
Class derived-class extends base-class
{

//methods
}

Polymorphism

The technique of doing a single task in multiple ways is known as
Polymorphism. In Java programming, we can use method overriding and
method overloading techniques to achieve polymorphism. It is essential to
know that an object can also be accessed through a reference variable and
once it has been reassigned to other objects, the type of reference variable can
be used to determine the method that is to be used to access the object.

For example:
Public interface School{}
Public class Student{}
Public class John extends Student implements School{}
In the above case, John is known to be polymorphic because it has multiple
inheritance and we can apply the reference variable for the same object as
well.

Abstraction

An Abstract Class is one which includes an abstract keyword in its
declaration and it can or might not contain abstract methods. In a case where
a class has an abstract method, it cannot be instantiated and the programmer
will have to inherit it from another class to implement the abstract method.

Encapsulation

Encapsulation in Java programming is the process of wrapping data and
methods together. Generally, the variable of one class will be hidden from
another class and it can only be accessed through the methods that are being
used in their current class. The advantages of encapsulation are that a class
could be made read only or write only and it can also have total control over
the data stored.

Recursion

Recursion is a technique referred to a method which calls itself within the
program. The recurse() method is called from the main method and can also
be called from the same recurse() method as well. This process continues
until the given condition is met and if the case is not satisfied, infinite
recursion occurs.

Here is a simple implementation of recursion in Java:

class Sample {
static void printFun(int test)
{
if (test < 1)
return;

else {
System.out.printf("%d ", test);

// Statement 2
printFun(test - 1);

System.out.printf("%d ", test);
return;
}

}

public static void main(String[] args)
{
int test = 3;
printFun(test);
}
}

Advantages of recursion

There are several complex programs in which writing recursive code can
deliver several benefits. As it provides a simple and clean way to write code,
developers can perform operations of different kinds without any hassle.

Abstract Class and Abstract Methods

Abstract Class

In Java programming, an Abstract class is known as a class which cannot be
initiated and is declared by using the ‘abstract’ keyword.

Here is the syntax for declaring an abstract class Student in Java:
abstract class Student {

//methods and attributes
}
Remember that we cannot create objects of an abstract class. Doing so will
generate a compilation error.

Inheritance of Abstract class

Here is a sample Java program illustrating the inheritance of an abstract class:

abstract class Student {
public void displayInfo() {
System.out.println("I am a Student");
}
}
class Grade extends Student {
}
class Main {

public static void main(String[] args) {
Grade G1 = new Grade();
G1.displayInfo();
}
}

Abstract Method

To create an abstract method in Java, the same keyword ‘abstract’ is used.
The syntax is defined as follows:

Abstract void moveto();

CHAPTER THREE

SQL AND DATABASE

What is a Database?

A database is a collection of data which can be accessed, managed, and
updated. Before entering into a brief discussion of database, it is important
that we understand what Data actually means and how it can be processed.
Data is generally defined as a collection of records and facts with which we
can perform calculations and apply reasoning to.
To protect, save, deliver, and organize data, databases are created and the
system that manages the whole process is called a database management
system (DBMS).

Database Management System (DBMS) concepts

A Database Management System consists of multiple programs that allow
users to access the database and handle data through different processes. As it
is generally designed to control access to the database, there are various
operations and functionalities introduced in the DBMS to make it more

effective, safe, and reliable.
There are 4 different types of DBMS:

1. Relational DBMS

This category of DBMS defines database relations in the form of tables.

2. Object Oriented Relational DBMS

Object Oriented Relational DBMS allows data to be stored in the form of
objects along with their attributes.

3. Network DBMS

The Network DBMS features many-to-many relations and is generally used
for complex database structures.

4. Hierarchical

Hierarchical DBMS follows the parent-child relationship to store data and has
a structure similar to that of a tree with nodes that are used to represent
various fields.

Database Environment and Architecture

The database environment is known as a collective system of components
which are responsible for data handling, management, and use of data. As
databases are generally stored in computers, the hardware and computer
peripherals that are used to manage the whole process also include DBMS
tools such as SQL Server.
The Architecture of a Database or DBMS is usually classified into three
major categories: Centralized, Decentralized, and Hierarchical. Database
systems can be client-server or centralized and can also be designed to be
accessed by parallel computer architectures.
The Three-Tier architecture of a DBMS is defined as follows:

Presentation Tier
Application Tier
Database Tier

Types of Databases

There are different types of databases that are classified as per their
organizational approach and functionality.
Relational Database
A relational database is where the data is defined, organized, and accessed in
multiple ways. Being a tabular database, the table consists of rows and
columns which is managed through Structured Query Language (SQL).

Distributed Database

The distributed database has its data stored at multiple sites which are
interconnected with each other through communication links. This database
is further classified into Homogeneous and Heterogeneous categories. For the
homogeneous distributed database system, the same type of hardware, OS,
and database applications are connected together whereas for the
heterogeneous distributed database system, the system can be different for
each location and connection.

Cloud Database

The Cloud Database environment is designed and built to store data in
private, public, or hybrid cloud. Providing better scalability and greater
storage capacity, users can benefit from high availability. It is the best
suitable option for business applications.

NoSQL Database

NoSQL Database is best suited for large distributed data and it is
conveniently managed through relational databases. Furthermore, they are
effective for big data performance issues which cannot be easily solved by
using relational databases.

Object Oriented Database

Object Oriented Database is supported by the relational database and is based
on objects rather than actions.

End User Database

End User Database is a shared database that is specifically designed and
created for the end user. As it features a summary of the whole database, the
end user certainly needs not to worry about the operations that are being

performed at any database level.

Database Syntax, Data Type and Operators

Standard Query Language (SQL) is used for storing, manipulating, and
retrieving data within a database. SQL allows database administrators to
perform multiple operations that are required to manage a database. The
language allows you to execute queries, retrieve data, insert records, update
records, delete records, create new databases, create new tables, and set
permissions in a database just by writing simple queries.
There are different versions of SQL and all of them support major
functionalities such as SELECT, DELETE, INSERT, WHERE, and
UPDATE.

Structured Query Language (SQL)

SQL is the language that is used for relational database systems such as
MySQL, Sybase, Oracle, and SQL Server. Being a standard database
language, SQL allows users to describe the data, access data, and manipulate
the relational database management systems. Furthermore, users can also
create, view, and drop databases through the Structured Query Language.
The different components that are included in this process are Optimization
Engines, SQL Query Engine, Classic Query Engine, and Query Dispatcher.
To perform specific operations in a relational database management system,
we can use the commands mentioned below:

Command Description

CREATE User can create a new table or an object within
the database.

READ User can read the data stored in the tables.

UPDATE Update the tables to modify records.

DELETE Delete any record from the table.

INSERT Insert a new record into the table

SELECT Select specific records from the tables within the

ALTER database.
DROP Bring changes within a database object.
Delete the entire table from the database.

By using the above operations, we can perform different operations from the
sample table named ‘Students’ given below:

Student Student City Subject Marks Percentage
ID Name

1 William New Mathematics 85 60%

York

2 James California English 79 58%

The SQL statement to fetch records from the above table will have the
following syntax:
SELECT * FROM Students;

1. SQL Queries

In order to perform specific operations with tables in a database, we are
required to use different queries that are explained as follows:

Query Syntax
INSERT INTO
INSERT INTO table_name(column1,
UPDATE column2,…)
VALUES (Value1, Value2,…)
DELETE
ORDER BY UPDATE table_name SET column1 =
value1, column2 = value2,..
WHERE condition

DELETE FROM table_name WHERE
condition;

SELECT column1, ..FROM table_name
ORDER BY column1, ASC/DESC;

MIN() SELECT MIN(column_name)
MAX() FROM table_name
WHERE WHERE condition;

SELECT MAX(column_name)
FROM table_name
WHERE condition;

SELECT column1,..
FROM table_name
WHERE condition;

SQL Joins

Taking the example of relational database with table A and table B, the table
can also be joined through the SQL JOIN query. The Venn diagram clearly
shows how both of the tables are joined together to share data:
We will implement various JOIN clause operations on the example tables
‘Patients’ below:
Table 1:

PatientID CaseNO Date

43221 1 9-2-2011

82357 3 8-12-2015

Table 2: PatientName City
CaseNo Andrew Chicago
1 John LA
3

To join both tables, we can write the SQL JOIN statement as follows:

SELECT Patient.PatientID, Case.CaseNo, Date.
FROM Patients
INNER JOIN Patients ON Case. CaseNo = PatientName.Patient ID;

There are four different types of SQL JOIN queries known as:

INNER JOIN
LEFT OUTER JOIN
RIGHT OUTER JOIN
FULL OUTER JOIN

Inner join

Inner join selects the entire record from Table A and Table B where the Join
condition is satisfied. The syntax for creating inner join in SQL is defined as
follows:

SELECT column name
FROM table1
INNER JOIN table 2
ON table1.column_name = table2.colmn_name;

Left Join

The Left join selects the entire record from Table A combined with the
records from Table B where the join condition is satisfied. Syntax for
creating LEFT JOIN in SQL is defined as follows:

SELECT column name
FROM table1
LEFT JOIN table 2
ON table1.column_name = table2.colmn_name;

Right Join

The Right join select all records from Table B combined with the records
from Table A where the join condition is satisfied. Syntax for creating
RIGHT JOIN in SQL is defined as follows:

SELECT column name
FROM table1
RIGHT JOIN table 2
ON table1.column_name = table2.colmn_name;

Full outer Join

The Full outer Join selects all records from Table A and Table B even if the
join condition is not met. Syntax for creating FULL JOIN in SQL is defined
as follows:

SELECT column name
FROM table1
FULL OUTER JOIN table 2
ON table1.column_name = table2.colmn_name
WHERE condition;

Union Operator

To combine the result of two or mode SELECT statements, the UNION
operator is used for which each of the column must have similar data types.
Moreover, the columns in the SELECT statement should be in the same order
for both tables. The syntax for implementing UNION operator in SQL is
defined as follows:

SELECT column_name FROM table1
UNION
SELECT column name FROM table2;

GROUP BY

The SQL GROUP BY statement can be used to perform listing or numbering
from the database table. Syntax for using GROUP BY statement in SQL is
defined as follows:

SELECT column_name
FROM table_name
WHERE condition
GROUP BY column_name
ORDER BY column_name;

ORDER BY

The ORDER BY statement in SQL is used to sort data in ascending or
descending order. Syntax for implementing ORDER BY clause is defined as
follows:

SELECT column_list
FROM table_name
WHERE condition
[ORDER BY column1, column2,] [ASC | DESC];

Advanced SQL

There are several other vital operations and clauses that can be implemented
to perform complex operations within the database. Here are some of the key
features of advanced SQL explained in detail:

Indexes

SQL Indexes are used by database search engines to optimize the process of
data handling. As they are considered as special lookup tables, an index helps

to speed up WHERE clauses and SELECT queries as well. To create an
Index, we can use the CREATE INDEX statement along with the UNIQUE
constraint to prevent duplicate entries.
Syntax for using CREATE Index:

CREATE INDEX index_name ON table_name;
Syntax for using DROP Index
DROP INDEX index_name;

Truncate Table

The TRUNCATE TABLE command is SQL is implemented to delete
complete data from an existing table.
Basic syntax:
TRUNCATE TABLE table_name;

SQL Primary and Foreign Key

Primary Key

The PRIMARY KEY constraint in SQL is implemented to uniquely identify
each record in a table. Primary keys should always contain unique values and
do not have any NULL values. Moreover, one table can only have one unique
primary key which can be made up of single or multiple columns.
For example, to define PRIMARY KEY on the ID column when the
“Students” table is created, we can use the following SQL statement:

CREATE TABLE Students (

ID in NOT NULL,

FirstName varchar (255),

LastName varchar NOT NULL (255),

Marks int,

PRIMARY KEY (ID)
);

Foreign Key

The FOREIGN KEY constraint in SQL is implemented to link two tables
together for which the FOREIGN KEY in one table refers to the PRIMARY
KEY from the other table.
Syntax for implementing the FOREIGN KEY constraint on “StudentID”
column to create “Student” table:

CREATE TABLE Student (

StudentID in NOT NULL,

StudentMarks int NOT NULL,

ClassID int,

PRIMARY KEY (StudentID),

FOREIGN KEY (ClassID) REFERENCES Students( StudentID)
);

Constraints and Useful resources

Constraints are the specific rules that are implemented on data columns of a
table. Generally, constraints are implemented to limit the type of data that can
be inserted into a table. Most commonly, this includes NOT NULL
Constraint, DEFAULT Constraint, UNIQUE Constraint, PRIMARY Key,
FOREIGN Key, CHECK Constraint, and INDEX.
Furthermore, Integrity constraints can also be used to avail better consistency
and accuracy of data present in the relational database. Usually, PRIMARY
KEY, FOREIGN KEY, and UNIQUE Constraints are a part of Referential
Integrity (RI).
In order to improve the performance of SQL database, there are several
important factors that can be implemented with ease. While writing a column
name, it is advised that SELECT statement is used rather than the * delimiter.
For example:
SELECT * FROM Students

Furthermore, setting the NOCOUNT ON statement will reduce the time
required for SQL Server to update rows for INSERT, DELETE or UPDATE
operations

CHAPTER FOUR

C

C programming language was developed at AT & T’s Bell Laboratories in
the USA in 1972. Generally, there are two major categories of programming
languages known as High Level language and Low-level Language but C is
ranged as a Middle Level language. The purpose of this language is to
provide low level access to memory and has also given syntax to other major
programming languages such as PHP and Java.

Introduction and Simple Programs

Being a structured language, programmers can create partitioned code blocks
and create business applications by implementing different approaches and
programming techniques. Moreover, we can also write new functions and
repeat them throughout the application in the C library.

Starting with C Programming

Writing a C program is simple and easy for beginners. Starting with the basic
program syntax, we can develop C applications and programs as follows:


Click to View FlipBook Version