Introduction to Java

Step-by-step guide for beginners to learn Java programming

Alex Jackson

Thank you very much

First of all, I want on Thank you very much God after the give myself the knowledge and inspiration on place This Insightful Reservations together. Me too want on Thank you very much me Parents, me brothers and sisters and me company Sylvia after the her Support.

Summary

Chapter One: The History of Java

-       The birth of computer

- Development of computer programming Languages

- Origin of Java technology

Chapter Two: The Java Environment

- Use Java Tongue

- The early Java Set up

-       Test the software Furnished

-       Java required instruments

Chapter Three: The Basics of Java Code

- Properties of object orientation Programming

- First Simple Java program

- parts of Java program

Chapter Four: User Input

- scanner class

-       next line method

-       Pressure method

Chapter Five: Declaration of Variables

- The base variable types

- By declaring a variable types

Chapter Six: operator

- arithmetic operator

- increase decrease operator

-       Logical operator

- A little wise operator

Chapter Seven: Flow Control

- if-then-else

-       Cycles

Chapter Eight: Access Modifiers

- default

- Private

- Publicity

- Protect

Chapter 9: Classes and Objects

- class

- example

- Local

- Relationships

Chapter Ten: Builder

- This

- great

Exercises + free bonus!

- repetition

- Work out exercises

-       Practical exercises answers

-       Free video series

© Copyright 2022 by Alex Jaxson - All rights reserved.

This document is oriented to something by I agree and reliable information in regards on the topic and issue being addressed. It is not legal to reproduce, duplicate or transmit any part of this document in electronic or paper form. Registration of this publication is strictly prohibited. The information provided here is believed to be true and consistent. In no event shall the publisher be legally responsible or liable for any repairs, damages or financial loss resulting directly or indirectly from the information contained herein. All copyrights not belonging to the publisher belong to the respective author. The information contained herein is presented for informational purposes only and as such is universal. The information is presented without contract or warranty assurance. The trademarks used are without approval and publication out the brand name is without permit or support out the brand name Owner. All brands and Trademarks within This Reservations I am after the to explain purposes alone and I am the owned by the owners themselves, not affiliated with them document.

introduction

Goodbye! Thank you for downloading this e-book. This way, you have taken a big step in investing in your programming skills! This e-book provides useful information about the Java language for beginners. I'm Alex and I also started as an amateur software programmer who struggled to understand basic Java terminology and programming conventions. This e-book then serves as an introduction to understanding the Java language and guides you towards your goal of becoming a professional computer programmer. I will teach you how to install the necessary Java tools and build simple programs step by step.

At first glance, Java may seem like a difficult language to understand.

Once you start, you'll start to get familiar with the Java locale and quickly realize that it can be quite easy to learn! Regardless of your programming language experience, this guide will guide you in a way that is easy to follow and easy to learn. The more you expand your knowledge, the more you will appreciate the benefits of being a Java programmer.

Java has always been considered one of the most popular programming languages in the world. If you decide to focus on studying the Java environment, you are in for a fast-growing career. This technology is integrated and widely used in bleed the World Wide Cobweb, development cell phone, cell phone Application, construction sites and more. Because of its simplicity, readability and flexibility, Java is one of the most sought-after programming skills in the information technology recruitment market . Currently, a Java Developer/Programmer earns an estimated annual salary of $85,000 in the United States of America AMERICAN DOLLAR.

This e-book is sure to serve as a starting point if you decide to pursue a career in Java programming. Among other things, I will give you a discussion of the features of this software environment, the different components, terminology, basic programming styles and sample programs. You will find that Java programming is quite fun as it uses plain English language when coding. So let's get started!

PS Don't forget to download your FREE bonus video course at the end of this book. Enjoy it!

Chapter One: History of Java

This chapter gives you a brief overview of the origins of Java software, beginning with the existence of computers. It also gives you a brief overview of the development of various computer programming languages.

The birth of the computer

Not so long ago, maybe two decades ago, there were still typewriters to create the documents we need at home, at school or at work. Remember your mother's recipes on the cards, your college work, your resume for a job application, and more. Then comes the birth of computer systems that made everything much easier! It was a total revolution when these amazing machines were introduced. Now, with just a click or push of a button, you can print photos to decorate your home, a YouTube video of your high school prom, or a visually stunning marketing presentation for work.

A computer system consists of all the essential components of a computer and how they are integrated with each other to make the device work efficiently and effectively. These components can be classified as hardware or software. Computer hardware refers to the physical part, such as the central processing unit (CPU), mouse, keyboard and monitor, among others. Software, on the other hand, refers to the various programs that tell the computer what to do. Both hardware and software components work side by side to achieve the results desired by the user.

Because this e-book is written to provide a step-by-step guide to Java programming, we will focus on the software aspect of the computer system. In addition, it brought about the emergence of the World Wide Web or simply known as the Internet Street Further innovations in computer Programming. That growth Requests out it on the internet Motorway as It He arrives on Share and communicate information Has it forced programmers to explore the potential of JAVA programming Language.

Evolution of computer programming languages

1954-1957

Developed FORTRAN (considered the first modern computer programming language, but certainly not intuitive) with an IBM team.

1959

Grace Hopper of Remington Rand developed COBOL (Letter B stands for Business which is the main feature of COBOL which includes processing customer, employee data and more)

1972

AT&T Bell Labs' Dennis Ritchie developed the C programming language.

1986

AT&T Bell Labs' Bjarne Stroustrup developed C++, which supports object-oriented programming (OOP).

1995

It wash Exactly On Can 23 ° That Sun microsystems exempt the First of all official Version of the Java programming language is considered an improvement of C++. This generic software allows you to create, search, and write databases in Windows applications and Look over hand holder devices, in between Miscellaneous. Alone after Five years ago, Java already had 2.5 million developers Worldwide.

2000

The College Board announced in November that by 2003 the Advanced Placement exams in Computer Science would be based on Java.

2002

Microsoft introduced C#, a new named language that inherited most of its programming capabilities from Java. Sys-Con Media reported in June of the same year that there was a growing demand for Java programmers (it exceeded the demand for C++ programmers by 50%).

2007

Google started developing applications on Android mobile devices using the Java language.

2010

Oracle Corporation added Java technology to the Oracle family with its January purchase of Sun Microsystems

2010

eWeek ranked Java #1 in June's "10 Best Programming Languages to Keep You Busy" ( www.eweek.com/c/a/Application-Development/Top-10-Programming-Languagesto-Keep-You - Busy - 719257) .

2013

Further out 1.1 billion writing table computer and 250 millions cell phone, cell phone phones to have using the Java platform since August 2013 ( www.mobiledevicemanager.com/mobile-devicestatistics/250-million-android-devices-in-use and http://java.com/en/about). Also, Blu-ray devices appeared with more interactive capabilities thanks to the new one Technology. Java wash pretty consider the more Popular Language out various programming groups and communities, such as B. TIOBE Programming Community Index ( www.tiobe.com/index.php/ content/paper info/tpci) and PYPL That is for the Popularity of Programming Language Index ( http://sites.google.com/site/pydatalog/pypl/PyPL-PopularityY-of-Programming-Language ), including Miscellaneous.

Advent of Java technology

When IT professionals realized in the early 1990s that there was a tremendous need to make people's lives easier by introducing intelligence into everyday devices , Sun Microsystems worked with a team of researchers to create the "Green Project" to create to start.

It is a kind of secret assignment aimed at developing software for portable devices that run on embedded processor chips. The program was intended to be flexible enough to accommodate the ever-evolving device processor chips, which were becoming smaller, cheaper, and yet more powerful. The team originally planned to use C++, but its portability problem wash block her way on Success. Like this, you decision on develop a completely new computer programming Language.

It was 1991 when the Java language was originally developed by Sun Microsystem in collaboration with James Gosling, Chris Warth, Patrick Naughton, Mike Sheridan and Ed Frank. Oak was the original name of the new programming language, it was the tree right outside James Gosling's (the team's project leader ) window. But Oak wood wash pretty being Second hand how the first name after the Miscellaneous Programming Language. Therefore, it was officially renamed Java in 1995, signifying the coffee that software developers enjoy during their breaks. However, if the demand for such devices does not meet Sun Microsystem's expectations, the programming team will have to find another channel to extend Java. Finally, in May 1995, Java was released for the first time at the SunWorld conference, immediately followed by Netscape ( the world's leading browser at the time ), which announced that it would integrate the programming language. in her Development. With Embedded in Java cobweb pages, sites turned

from banal to interactive. The web not only broadcasts information to its audience, it is also capable of accepting user input.

In this chapter, you learned the history of computer programming languages, focusing on the development of Java technology. In the next chapter, Java will be described as used in different programming environments, with clear instructions on how to properly install it on your computer.

Chapter Two: The Java Environment

Receive a approach Look On Java programming, This Chapter want start his discussion to use and distribute the software in different environments. It will also offer a step-by-step guide Instruction On how on to install, Not alone the Java program Yes indeed but Also other tools you may need Computer.

With the inexorable growth of the World Wide Web, developers have found ways to embed Java programs into any web page. Below is a summary of how the software language is used in different environments:

Applet - A type of networked Java program embedded in a web page and automatically executed by another Java-compatible browser when sent over the Internet. This is usually a small program that can display data from the server, process user input, or even perform simple functions such as a calculator. These functions are executed locally on the client's computer instead of connecting to the server, meaning that when the link is clicked, an applet is automatically downloaded and run in the browser.

Servlet - A type of small Java program that supports one browser but runs on another computer or cobweb server on expand his functionality. That introduction out the servlet updated the client/server Compound.

JavaServer Page (JSP) - A web page that consists of fragments of a Java program (as opposed to an applet, which contains the complete program).

Java Micro Edition (ME) application - a Java program that runs on a resource device with limited storage capacity, e.g. B. a mobile phone or a set-top box for TV.

Java Standard Edition (SE) Application: A Java program that runs on a standard computer such as a desktop or laptop.

JavaFX - A Java program integrated into multimedia platforms such as Flash players.

The initial configuration of Java

Before you sit down in front of your computer and start programming, you need to make sure that you and your computer can write Java code. It is highly recommended that you visit the following websites and follow the instructions to download the required software, which is usually free:

Follow the steps below to download and install Java software:

go on the website http://java.com out type This in the address bar out your web browser . _ This takes you to the screen under:

click On the FREE JAVA DOWNLOAD Button. It want take his on This Screen:

Click the ACCEPT AND START FREE DOWNLOAD button . If your java Download is finish, his to have on conclude everyone your browsers and Reload them to enable Java Installation.

Run the downloaded file and you will get the following screenshot . Just click the

INSTALL .

www.oracle.com/technetwork/java/javase/downloads - Download and install the required Java SE documentation (also known as Javadoc pages or Java SE API docs).

Following:

go on the website www.oracle.com/technetwork/java/javase/downloads , It take you to the screen under:

Click on it possibility

On the next page, you will be asked to select the Java SE Development Kit version want on Download. Make safe his know Exactly What industry system You have on your computer or laptop before you start Currently downloading.

After the Look over the execution out your industry System, his achievement go on the SYSTEMS or

PC INFO - Settings of your computer/laptop.

Open up the dropped off program on finish the installation out your Java SE Development Kit. Make sure you read and follow the steps careful.

http://eclipse.org/downloads - Download and install the required Eclipse program.

go on the website http://eclipse.org/downloads out type This in the address bar of your web browser. This takes you to the screen under:

Choose the applicable execution out darkness based On your from computers Operating system. If you have a 64-bit Windows operating system (OS), you will get the following screen:

After downloading, open the app and you will get the screen under:

Alone Choose DARKNESS IDE AFTER THE JAVA DEVELOPER possibility and then Click on the INSTALL button . Make sure you accept ECLIPSE FOUNDATION SOFTWARE USER AGREEMENT .

After downloading the programs, you need to test the installed software. You can follow these steps to test Eclipse:

Start Eclipse. You should be able to see an ECLIPSE JAVA MARS icon on your desktop. You will then be asked to CHOOSE A WORKSPACE . Just leave the contents of the box and then click the OK button .

Create a new Java project by going to the top menu: FILE > NEW > JAVA PROJECT

a new class called Displayer inside the Java project.

Edit the new Displayer.java file by entering the following lines of code in the edit panel.

public class Exhibitor {

public static void main(String args[]) { System.out.println("Hello Java!");

}

}

Run Displayer.java by clicking This button       above e check a give safe That the production Law hi Java! out Look over the Number under.

In the field of computer programming, software developers need existing programs to create new programs. For example, you want to develop a Java program that manages your company's employee data . For this purpose, you can use an existing program as an error checking tool for your Java codes.

Java tools required

Below are the various tools required for Java programming that can be downloaded online for free:

compiler

A compiler turns the Java code you write into something your computer can understand and run. Computers do not understand instructions the way humans do. For example, examine the following program code:

Search for an available rental car:

// This is part of a Java program

// (this is not a complete Java program). CarRentNum = 1;

while (rent number < 100) {

if (customer [car rental number] == 0) { out.println("car " + car rental number

+ "is available.");

output(0);

} Miscellaneous {

Car RentalNum ++;

}

}

out.println("All cars or vehicles are rented");

This basic Java code searches for any car or rental vehicle available to a particular customer, assuming that the company has a total of 99 cars. You cannot run this code by typing it as is. However, by ignoring the strange punctuation and writing format, people can understand what the computer wants from us. Do:

Set the rental car number to 1.

If the number of rental cars is less than 100, check the number of customers who rented the car.

If the number of customers who rented the car is 0, it indicates that the car is available,

and stop

Otherwise,

get ready to look at the next car by adding 1 to your rental car number.

If you arrive at a non-existent rental car number 100, please report that all cars or vehicles are rented.

Computers do not follow the instructions translated into English to do a

specific task. Instead, they understand the cryptic Java bytecode commands. This is where the compiler comes into play. After the Java source code is written, it is translated by the compiler and written into Java bytecode that the computer can run. Check out the bytecode counterpart below for the same Java code:

aload_0 iconst_1

Putfield Company / Car Hire i'm going to 32

upload_0

getfield company / customer [I am loading_0

getfield company / car rentalNum I iaload

than 26

getstatic java /lang/System/out Ljava/io/PrintStream; new java / lang / StringBuilder

thump

ldc "car"

invokespecial java/lang/StringBuilder/<init>(Ljava/lang/String;) V aload_0

getfield company / car rental number I

invokevirtual java/lang/StringBuilder/append(I)Ljava/lang/StringBuilder; ldc" is available."

call virtually

java/lang/StringBuilder/append(Ljava/lang/String;) ljava/lang/StringB call virtual java/lang/StringBuilder/toString() ljava/lang/String; call virtual java /io/PrintStream/println(Ljava/lang/String;) V

iconst_0

invocharistatic java/lang/System/exit (I) V go 32

upload_0

thump

getfield Company / Car RentalNum I iconst_1

i sit by

putfield company / car rentalNum I aload_0

getfield company / car rental I'm pushing 100

se_icmplt 5

getstatic java /lang/System/out Ljava/io/PrintStream; ldc "All cars or vehicles are rented"

invokevirtual java /io/PrintStream/println(Ljava/lang/String;) V return

The source code may be stored in a file called Company.java , and the compiler will probably put the Java bytecode in another file called Company.class. You 'll also need a tool to view a text-like version of a Java bytecode file (you can use Ando Saabas' Java bytecode editor ). If you try to open the Company.class file code with Notepad or even Microsoft Word, you will only see gibberish characters like dots, scribbles and more.

Java Virtual Machine (JVM)

If the compiler is responsible for writing the Java bytecode, the Java Virtual Machine is responsible for decoding it. In fact , each type of computer processor has its own set of executable instructions, which are interpreted slightly differently by each operating system . Let's look at the following two programs for two different processors, but they show the same output on the computer screen: "Hello, world!".

Simple program - Pentium processor

.msg of data :

.ascii "Hello world! \n" len =. - News

.Text

.global _top

_Start:

movl$len,%edx movl $msg,%ecx movl$1,%ebx movl$4,%eax int $0x80

movl $0.% ebx movl $1.% eax int $0x80

Simple program: PowerPC processor

.msg of data :

.Text

_Start:

.string "Hello world! \n" len =. - News

.global _top

0.4 l      

you       3.1

lis             4, msg @ ha addi                   4,4, msg @ l li       5, len

sc

lh       0.1

you       3.1

sc

These two programs should show the same results, but cannot be interchanged because the instructions have no meaning if executed by the wrong processor. You receive notifications or error messages such as "Invalid Win32 application" or "Windows cannot open this file". Therefore, these Java bytecodes create order in this chaotic programming world with the help of the Java Virtual Machine! JVM acts as an interpreter and translates these byte codes so that any computer system can understand them. So you don't have to worry because whether it's your computer or your friend's, both can execute the bytecode. Therefore, Java language solved the problem of portability and versatility through JVM.

Integrated development environment

In the early days of Java programming, multiple windows opened: one to enter code, another to run the program, and perhaps a third to keep track of all the code you wrote. What a messed up situation! With the advent of the integrated development environment (IDE), all the features have been seamlessly combined into one well-organized application.

Below are some of the most popular Java IDEs that can be downloaded for free online (their functionality may vary, but the language remains exactly the same):

Eclipse ( www.eclipse.org )

Eclipse is considered one of the most popular and beautiful interfaces due to its interactive design and navigation features, and it stands out as open source and intuitive software.

NetBean ( https://netbeans.org )

Just like the previous program, this open source IDE is one of the most recommended Java programming environments for beginners. It is also fast and powerful and can support all Java platforms from Standard Edition (SE) to FX.

Blue J ( http://bluej.org/ )

Described as the simplest IDE interface, BlueJ is specially designed to help a novice user understand the basics of Java programming.

DrJava ( www.drjava.org )

DrJava is also designed for amateur programmers who want a simple user interface.

Despite its simplicity, it is still powerful enough for experienced Java programmers.

Java Development Kit (JDK)

The Java Development Kit is a tool that acts as both a compiler and an interpreter.

The latest version of JDK can be downloaded from Oracle's website: www.oracle.com/technetwork/java/javase/downloads/index.html . Make sure you download the correct version for your computer. If you are using a 32-bit operating system, download the appropriate file name with the suffix x86. Otherwise, if it's a 64-bit OS, it downloads with x64.

Now we have learned that Java can be distributed in many ways. This chapter also provides clear instructions on how to install the software and all other tools necessary for the program to work properly. In the next chapter you will learn how to start programming in a Java environment.

Chapter Three: The Basics of Java Code

Before you start writing lines of Java code, this chapter will first describe what object-oriented programming (one of the main features of Java programming) is all about. You will also program your first simple Java program and understand the meaning of each part. Classes, objects and instances are also presented to you.

It should be understood that the core of the Java language methodology is Object Oriented Programming (OOP). Over the years, software developers have tried to find ways to reduce the complexity of coding programs. The first generation of programming languages involved linking binary machine codes, only a few hundred instructions long, to the front of the computer. As programs were developed that required IT professionals to manipulate more complex instructions through symbolic representations, assembly language was developed. As programming methods improved, more high-level languages were introduced. An example is FORTRAN, but the codes were not yet easy to understand.

Structured programming originated in the 1960s and was used in the C and Pascal languages. Among other things, these programs were characterized by local variables, rich control constructs, and autonomous subroutines. Although they were considered power tools, they are still limited when it comes to handling very large projects.

The need to break the barriers of coding extremely large projects paved the way for the advent of object-oriented programming. It is a combination of the best structured programming methods and new organizational concepts. This programming style is characterized by the following:

encapsulation

In its name, encapsulation is a strategy that binds and protects the programming code and the data it manipulates from outside interference. When code and data are linked together, an object is created. This object contains private or public code and data. A private code or private data cannot be accessed by any program that exists outside the object. If it is public, other parts of the program can access it even if they are not inside the object.

polymorphism

This concept is often described as creating a single interface for multiple methods. This means designing a generic interface for a group of related activities. This further reduces program complexity by allowing you to use the same interface to specify a generic action class. An obvious analogy is the steering wheel. No matter what kind of steering wheel, manual or power steering, as long as you know how it works, you can drive any car.

estate

This process involves one object acquiring the properties of another object, which supports the concept of hierarchical classification. To explain it better, imagine a delicious red watermelon that belongs to the watermelon classification. Watermelon is another part of the fruit class, belonging to a larger class called food. The food class has some properties such as edible and nutritious which are further applied to its fruit subclass. The fruit also has some characteristics like juicy and sweet. Now the watermelon also has specific characteristics, like a tropical vine-like plant. Now, by combining all these qualities, you get a red and delicious watermelon.

Object-oriented programming is characterized by the use and organization of classes , objects and instances . These are actually the components that make up a Java program and are interconnected.

Class - Considered the highest group, the class encompasses everything in object-oriented programming.

Object: The specifications set by the classes are applied to objects that are not loaded into the computer's memory. These are also instances of a class that act as ready-to-use projects when needed. Therefore, a class can have any number of objects (it can even have zero objects).

Instance: Can be identical to objects because they describe a single instance.

To understand their relationship to each other, imagine developing a computer program that tracks student enrollment at a school. Each student has a unique characteristic: hairstyle, eye color, skin color, height, weight and many others. In your OOP program, every student is an object . Well, although the students are different from each other, they share the same list of physical characteristics. These attributes or properties must be assembled in a master list, which we call a class .

First simple Java program

Let's try again to code a short example program by following these instructions:

start Darkness. click FILE > NEW > JAVA PROJECT . first name your New project like EXAMPLE .

Create a new EXAMPLE class . Click FILE > NEW > CLASS > Old

EXAMPLE for the class name.

Type the following, fill it out and run it Program:

Code the Java program

In Java, a source file is called an assembly unit, and the name you give a source file is very important. By convention, the name of the main class must match the name of the file containing the program. Note that Java programming is case sensitive, which means the compiler is case sensitive. The filename extension required by the compiler is also .java . Following this programming convention makes it easier to organize and keep track of lines of code. Also, if you change the capitalization or the naming convention, the whole program loses its meaning and stops working. So for this activity we named it Example.java (because the public class defined by the program is also Example ).

Compilation of the Java program

At this point , the Javac compiler runs and creates a file named Example.class that contains the bytecode version of the program. In the previous discussion, the bytecode is executed by the Java Virtual Machine. To actually run the program, use the Java interpreter called java and pass the example class name as the command line argument, as shown below:

Java example

The following output is displayed while the program is running:

Java is essential to the web

During compilation, each class is placed in its own output file, named after the class with the .class extension. It used to be a convention to give the java source file the same name as the class file, so when you use the java interpreter you actually give the name of the class you want to run.

Parts of the Java program

Commentary

Comments are the descriptive parts of the program that explain what the codes are about. These are special pieces of text that improve the readability of the program by helping people understand how the program works. These are basically the words that we humans read but the compiler completely ignores. There are two types of comments, depending on how you write them:

A line or line break comment

start With Two slices, This comment text is short enough on in shape On one Line. It is also written on the End out a line out Code. in the the previous easy Java program Example, the one line comment we have is:

// A Java program starts with a call to main().

Everything from the first slash to the end of the file is ignored by the compiler

Line.

Block or Multiline comment

This type is characterized by multiple comments on one line (ie the text of your comment is Also tall on in shape in one Line). But the Two slices I am replace With a Open up on the start out the comment and end With a closure "*/" (on Save to computer time in write "//" for each line). Again, the compiler ignores everything between the two forward slashes. In the previous simple Java program example we have to have:

/*

* This is plain java program

*

* Name this file example.java

* /

The prologue is a version of a block comment that is placed at the beginning or beginning of your programs. It contains important information about the code so that any programmer can get an idea of what the program is about just by looking at it. Usually the prologue is enclosed in an asterisk box and contains the following information: file name, programmer's name and program description. If we were to change the block comment above, it would look like this:

/ ****************************************************** * ********************

* example.java

* Alessio & khatz

*

Web" on your computer screen

****************************************************** ********************

class heading

Now let's move on to the next line in our first simple Java program: public class Example {

This line of code is called the class header or class declaration and consists of 4 parts: the 3 words and the curly bracket at the beginning (actually the whole program is considered a class). Let's discuss each of them.

The first two words, public and class, are what we call reserved words or keywords . Such Words I am Second hand after the a special Extent how Being defined out the Java Language. You cannot redefine or use his on mean some miscellaneous, I like Manufacture his how names after the your

Program. Below is a list of common keywords in the Java language:

abstract

to claim

boolean

interruption

grip

pencil case

power point

Vehicle

class

cost

Goes on

Originally

Do

Double

Miscellaneous

Count

it stretches

the final

eventually

floating

after the

go to

Even

implemented

import

example of

internal

interface

tall

native

New

parcel

Private

protect

Publicity

To return

short

static

strict

great

Switch over

synchronized

This

throw

start

Meanwhile time

To try

blank

erratic

while

Analysis of each word is class a marker that indicates the beginning of the lesson or the beginning of the program. It also declares that a new class is defined. In our first simple program, Example is the name of the class. On the other hand, public is an access modifier that controls how the class is accessed (in this case, the information is accessible to all other classes). If it is set to private instead of public, only the current class has access to it. Finally, the curly brace at the beginning "{" indicates the beginning of the lesson and has a corresponding curly brace "}" at the end of the entire program.

Also in pairs, parentheses identify code groupings for both the programmer and the computer.

Title of the main method

After the class header comes the main method header. The method is a subroutine of the Java language, which is the line of code where the program begins execution. It's just a to-do list. In our example, the main method has the following form:

public static void main(String args[]) {

Again, public is a login modifier keyword, indicating that anyone can access the main method. It also means that you can access this code outside the class in which it is defined or declared. Static , also another reserved word, means that the method is immediately accessible . The third reserved word is void, which means the main method returns nothing (in some programs it may return a value).

All the information needed to pass to a method is received from the variables specified in parentheses after the method name. These variables are also called parameters and in our example they are just (String args []) . The declared parameter called args represents the arguments accepted by the main method. String is the argument type that stores character strings. The square brackets "[]" symbolize that this is an array of objects of the Strings type. Even if no parameters are required, empty parentheses must be specified.

System.out println

Based on our first simple Java program example, our main method contains the following line:

System.out.println("Java is essential to the web");

System.out.println is programming code that tells the computer to print something. Let's discuss each part. System refers to the computer, and when it becomes System.out , it refers to the monitor, which is the computer system's output device. The next word, println (pronounced "print line"), is a built-in Java method that controls the printing of computer messages. Generally, the line of code that calls this is a println method call . Only call a method when you want to execute it. Remember that the first letter of a method call is always uppercase and the rest lowercase.

The text enclosed in double quotes is the message to be printed on the screen. These double quotes are responsible for grouping the messages. At the end of the line is a semicolon that indicates the end of the method call or programming statement (it's like a period in plain English). All programming statements to be executed in Java end with a semicolon.

This chapter provides a guide to programming using Java programming

Language. You will also get a better idea of what the different parts of a simple program are. in the the following Chapter, his want take Programming on a whore even out Inclusion of what you call users Enrollment.

Before we continue, here are other books our readers loved!

http://amzn.to/1mBhUYM

http://amzn.to/1WOBiy2

http://amzn.to/1QzQPkY

http://amzn.to/21HWFWb

http://amzn.to/1VHtxZ i

http://amzn.to/1R1vnCP

Thanks for checking out my other books. Now let's move on to Chapter 4, where we'll look at user input!

Chapter Four: User Input

This chapter introduces the concept of user input and integrates it into the Java programming language.

Based on the first simple Java program we discussed earlier, you were not asked to provide any kind of input to run the code. The lines of code simply displayed the message on the computer screen. In the real world, programming requires stable communication between the user and the machine. In the Java language, we call this input/output or I/O streams. In this scenario, a two-way communication is created in which the user provides an input to the computer to be processed and then produces an output in return.

Get user input

there is a built in class called scanner in Java Language on easy receive the user Enrollment. What It do is It obtain information out the Enrollment flow, or out the keyboard or a file and store in a variable. However, the Scanner class is not part of the main Java language Like this his to need on tell the compiler where is it on Find It. After the his on use This, his to need include This line out code on the Better out your Program, So soon after the prologue Section:

import java.util.Scanner;

Because of the additional directive, the Scanner class is imported from the java.util package. To call or run this class in your program, you must use the following statement:

Scanner InputVariableName = new Scanner(System.in);

Now the imported Scanner class is called to initialize a variable called InputVariableName (you can change this name to whatever you want, but make sure it's not a Java keyword). This is followed by the assignment operator " = " followed by the programming code new Scanner(System.in); . This expression creates an object and tells the program to store the user input value in InputVariableName . Please note the coding convention when naming variables: the first letter of words is always capitalized.

To use the output stream to show you what you typed into the program, we need to include the following print statement:

System.out.println(InputVariableName.nextLine());

nextLine() method , which instructs the program to return a String value inserted into the current line. It also tells the program to wait until it finishes looking for input, then the program won't continue until you type something and press Enter on your keyboard. Let's further modify the println method by adding an additive operator:

System.out.println("You entered " + InputVariableName.nextLine());

At this point, the output statement contains text information that is printed along with the scanner variable. Messages are combined with the addition "+" operator in parentheses. Now if the user makes an input, like. B. "Johnny", the program will display "You typed Johnny" on the computer screen.

Our revised schedule will actually look like this:

From the above program, the message "What is your name?" will appear to ask you on sign in your First name. About his to have typed your first name and held off sign in (see the text in green is located in the console section), the program want Screen your first name after the Words "You have entered" on the Screen.

The introduction of user input, as described in this chapter, introduced the Java environment as a form of two-way communication between the software programmer and the computer. The user, as the user, provides the information that the computer must process by executing the rules of Java code. The concept of a variable declaration will now be presented in the next chapter.

Chapter Five: Declaration of Variables

Previously, we declared a variable to store text user input. If you want to create more complex programs then his to have on business Values in Variables. This Chapter want Now focus on declaring variables as part of your programming Style.

The variable type to be used is assigned in a declaration statement with the following syntax:

<type> <comma-separated-list-of-variables>; Examples:

entire rows, columns;

Company name string;

Again, a variable is a placeholder, the thing stored in it is a value, and the type of value stored in a variable is its type. Looking at the declaration declarations above, the word on the left (int, string) specifies the type for the variable or variables on the right (rows, columns, companyname). By the way , a Java variable can contain only one value type and its value can change during program execution. So in the examples above the variables row and col can only contain integers, while in the second statement declaration the variable companyName can only contain strings. The following are the basic variable types in the Java language:

model name

description

range of values

Integer

types

int (integer)

- Easier data type for management

-2147483648

Count

on

- no decimal point

2147483647

- not ideal for precision data

grip

- is the default 0

- has the smallest range for number

Data type

- contains a signed 8-bit 2

-128 to 127

entire complement

- The default value is 0

short

- contains 2s signed 16-bit integer

-32768 to 32767

- The default value is 0

tall

- contains a signed 64-bit 2's complement integer

-9223372036854775808

on

- is the default 0

9223372036854775807

Types of decimals

Float       - contains 32-bit IEEE 754 numerical values

- contains decimals Marks

- is the default 0.0f

-3.4x10 ³⁸

on

3.4 x 10 ³⁸

double       - contains 64-bit IEEE 754 numerical values

- contains decimals Marks

- more accurate than floating

- is the default 0.0d

-1.8 x 10,308

on

1.8 x 10 ³⁰⁸

character type

string       - contains a sequence of Alphanumeric characters

- is the default void

char

- accepts a single character as data

- default value is \u0000 (represents an empty space)

thousands of characters and symbols

Logical Type

boolean

- default value is False

True, False

Please note the following declaration statements for each variable type:

int AnyVariable;

or

int AnyVariable = 0;

byte AnyVariable;

or

Byte AnyVariable = 0;

short AnyVariable;

or

short AnyVariable = 0;

long AnyVariable;

or

long AnyVariable = 0L;

Float AnyVariable;

or

Float AnyVariable = 0.0f;

double AnyVariable;

or

double AnyVariable = 0.0d;

string of any variable;

or

String AnyVariable = null;

char any variable;

boolean any variable;

or

Boolean AnyVariable = false;

As you can see, String and Boolean are in uppercase letters. This is because they are data types that are also class names. That's why we use the capital letters S and B in code and conventional text.

Previously, our example Java program accepted a string value from the user. This time we will change the code to prompt the user for an integer data type. Let's say the program shows the user's age after it is entered. Check out the new programming code below:

In the last line of code, we used nextInt() to tell the program to store an integer data type. Other data types we can also crawl are nextByte(), nextShort(), nextLong(), nextFloat() and nextDouble().

When you need to create more complex operations in programs that require the use of multiple input values, it is best to store the user input and declare the variable. In this case, you should already have an idea of what data type this variable should have. By modifying the above program we now have:

Based On the New program Code, the scanner variable InputVariableName wash saved first in MyVariableName and then wash Second hand on Screen the user generated Enrollment on the screen.

Now that you've learned about the different types of variables and how to declare them correctly, you can now create programs with added functionality and complexity.

in the the the next Chapter, Miscellaneous characteristic want be launched the is the application of the Java language operator .

Chapter Six: Operators

This chapter describes the available operators that you can add to lines of code when programming more complex scenarios. Operators are primarily used to inspect, manipulate, and compare data in a Java locale.

Since the beginning of this book, we have used the equal sign (=) or the assignment operator, which works by assigning a compatible value to a variable. Also, arithmetic operators are used to control the value assigned to a variable. Even his achievement recall the mathematically operator his to have learned in School, These are the same operators you need to perform mathematical calculations in Java programming. Acquiring knowledge of how to use operators is an important prerequisite. All you need to understand are the symbols of each operator and what they do.

operator

Next to assignment, it is the simplest form of operators Operator.

addition operator (+)                               - Returns the sum of two subtraction values operator (-)       - Returns the difference of two multiplication values operator (*)                   - Returns the product of two partial values operator (/)                         - Returns the quotient of two remainders operator (%)             - come back the rest out Two Values being

divide

Increment/Decrement operators

This operator Increase or reduce the value out the variable out 1.

Increase (++)       - Increases the value of 1

reduction (-)       - Decrease the value of 1

They can also be used as a prefix or preincrement operator, with "++" preceding the variable. This means that 1 is added to the value of the variable before it is used in any other part of the program (the value is changed immediately when it is used). If "++" is placed after the variable, it becomes a suffix or postincrement operator. This time, 1 is added to the value of the variable after the variable is used anywhere else in the program (the value is returned before it is adjusted).

Example:

MyVariableName = 23;

MyVariableName ++;       - The returned value is fixed 23

++ MyVariableName;       - The returned value is adjusted 24

Logical operators

These operators, also called comparison operators, allow some flow control in the program by comparing two values or setting certain conditions. Depending on the two values being compared, it is possible to return a Boolean value that determines whether or not a given block of code is executed. It is the most basic form of logic in a computer program.

It's the same on (==)       - Check if there are two values even

It's not the same on (!=)       - Check if two values are not even

it is bigger out (>)       - checks Even the value on the Left out the operator is larger out

the value to the right of it

It is less out (<)       - Checks if the value is to the left of The operator is less than the

value to the right of it

It is bigger than o Even (>=)       - Checks if the value is to the left of The operator is larger out

or equal to the value to its right

It is smaller than o Even (<=)       - checks Even the value on the Left out the operator It is less than or

equal to the value to its right

Logical and (&&)       - Checks that both values exist REAL

Logical OR (||)       - Checks if at least one of the values is REAL

Somewhat wise operators

These operators manipulate bit-level variables in a primitive but fast way.

Because they analyze binary numbers, which represent the smallest unit of addressable memory, they process execution as quickly as possible.

and (&)       - A 2 Same length Sentence operator which behaves logically operator

"AND" and multiply both elements by bits

do not (~)       - A single digit operator That clues With the purpose of logical negation and

integrate the binary value of one

OR (|)       - A operator That take 2 pieces models whose, whose the lengths are the same and

with the logical operator "OR" (the results are both

0 or 1)

Xor (^)       - A operator That take 2 pieces models whose lengths are equal (Results I am

must be defined with a similar number)

Now that you've learned how to manipulate operators, you'll be better able to understand and automate more complex Java programs. Another programming feature introduced in the next chapter is flow control, which shows non-consecutive lines of code.

Chapter Seven: Flow Control

This chapter will highlight a non-sequential approach to Java programming. You are familiar with the if-then-else and various loop statements.

In our previous simple programming examples, we aimed to execute a Java class in one direction, from the top line of code to the bottom, or what we call sequential programming. However, there will be cases when you don't need to write code sequentially, especially for these more complicated scenarios. This is achieved through the use of logic and loop statements, which allow you to control the flow of the program to perform more complex functions.

if-then-else

It is the simplest flow control statement that uses logical operators to determine whether a given condition is met or not. Let's add an if-then-else statement to our first simple Java program that will indicate whether or not the user is a minor based on the age they specified. By the way , in this example you are considered a minor if you are under 18 years old.

In this new set of programming code, the condition being tested is whether the value of the supplied MyVariableName user input is less than 18 or less. In this case, the methods in the if block are executed and a message is displayed on the computer screen that the user is a minor (see screenshot above). A block is also called a compound statement. Otherwise,

The Else block is executed - the user is notified that they are no longer a minor (see screenshot below). The else block is actually optional, meaning that if the condition isn't met, the program just continues with the rest of the class without its code. Note that the parentheses around the condition and the parentheses around the statements within the if and else blocks are all required. Also note the indentation of the statements surrounding these symbols.

Cycles

This flow control statement allows methods to be executed over and over as long as certain conditions are met. In the Java programming language, there are three types of loops that can perform repetitive tasks. We will also modify the simple program to count down from 10 to 1 just to demonstrate the syntax of these loops. Again, don't forget the parentheses around conditions, curly brackets and indentations.

While loop : Considered the simplest type of "event-driven" loop, this statement executes methods inside the while block as long as certain conditions are met.

Depending on the set conditions, this cycle may not even be executed.

In the program example above, MyVariableName is initially set to the value 10. Next, the loop checks if the variable is greater than 0, the program displays the value of MyVariableName on each new line, and then decrements it by 1. This works until MyVariableName is equal to 0. If the value of MyVariableName is already equal to or less if 0 is at the beginning of program execution, the while loop is ignored.

Do While Loop: The main difference between this and a while loop is that the methods inside the do while loop are sure to be executed at least once before the condition is checked. Unlike the while loop, the condition of the do loop is given below (this is the main reason why the loop statement is executed at least once)

in the the program example Above, quiet, the variable MyVariableName wash First of all set up to a value of 10. No conditions are checked in the following loop statement. Instead, the Do block should display the value of MyVariableName on each new line and then decrement it by 1 before testing the while condition. This has been discussed above That Ribbon want decision run once even or Not the conditions I am encountered Please Notice the semicolon to the right of the State.

For loop - This statement is declared with specific parameters that control when or how often the methods should be executed. Variables that can be used to control the loop can also be declared within the loop itself. The form of the for-loop statement is:

for statement(initialization; condition; iteration);

The initialization part sets a loop control variable to an initial value. The condition is a Boolean expression that tests the loop's control variable for true or false. If the result of this test is true, the execution of the for loop is repeated over and over. If it is wrong, the cycle stops.

In this last example, you will see that all the parameters were initially set when the for-loop statement was declared. So in the for loop statement MyVariableName is set to the value 10, the condition is whether it is greater than 0

selected and then decrements its value by 1. After all these lines of code are executed or executed, the value of MyVariableName will be displayed on the screen, each value on a separate line

In fact , there are usually many ways to perform a given programming task. However, as a programmer, you should always code your programs in an elegant way by choosing the most suitable cycle. You have the ability to be creative and flexible, but it gets confusing at times.

In this chapter, you understood that Java programming is not just a one-way street where flow control is integrated through various loop statements. The next chapter will give you a clearer picture of what access modifiers are.

Chapter Eight: Access Modifiers

We have already talked about Java variables, classes, fields and methods.

Each time they are declared, you must specify how they will be controlled and how they will be accessed throughout the program. Whether they are restricted or not, their accessibility function is determined by the accessibility modifiers, which are discussed in more detail in this chapter.

Deciding which modifier to use depends on the purpose of the program and what you really want to achieve. The following are the different types of modifiers:

default

This is the type assigned when no access modifier is specified. Because of its absence, any command or function can access a part of the program. However, its availability is limited to only accessing fields belonging to a similar package. A program without a modifier may look effective, but not completely clean. The access layer is generally publicly accessible, but not contained in an interface.

Example:

string version="1.00.1" boolean process_order() {

Give true

}

In this example, the program initially declared a version of the string sequence. Since no specific type of access modifier is defined, any function assignment can be used to access the program component. Therefore, process_order can be changed easily.

Private

This is the type of modifier that honors the program's more restrictive fields. It is not accessible, so it cannot be used by any command or function. If a particular instruction is assumed to be from a source not listed, no credit can be given.

Example:

public class arcadia extends bay { private int name_of_residents private boolean in_city

public Arcadia() {

name_of_residents = joy in_town = false

}

private void skrill() system.out.printIn (quiet);

public void action() system.out.printIn(talk);

}

For this example, the program has defined a public arcadia that is allowed a large functional space. Although Arcadia Bay is public, some of its inland properties are private. Also, because one of its internal components (action) is set as public, it can be recognized by multiple fields.

Publicity

This is the modifier type that allows access from any other field. With a public access level, it is less of a problem for a programmer to visit other parts of his work. All commands, functions, and various program components belonging to the public class are accessible through a recognized instruction set in Java programming

Language. However, the public statement has some disadvantages or limitations. Even if all commands and functions are set to public, classes belonging to another package cannot access them.

Example:

public static void (String arguments) {

}

Protect

This type of access modifier belongs to what we call superclass and is characterized by being less hidden and less secure than the standard type. It also means two things:

is only accessible from fields declared in a certain superclass is only accessible from subclasses of a similar package

This categorization is implemented to improve program structure by restricting access to an irrelevant element. Safe access modifiers also enforce strict protocols, and enforcement is limited (cannot be applied to classes and interfaces). If a field is not associated with any class or interface, it can be declared protected.

Example:

class seven_fields

boolean protected openFields(field1 sp) {

// implementation

}

seven_fields class opening(field1 sp) {

// implementation

}

In this example, the seven_fields class is declared, and since it is under the protected access modifier, its boolean logic open_fields cannot be accessed using a function or command. Unless a new access modifier is declared, that particular part of the file

The program cannot be changed.

You learned from this chapter that whatever you want to achieve when developing a Java program determines the appropriate type of access modifier to use. Each of the four types of access modifiers has its own characteristics and functions that affect how objects are accessed in a particular Java program. In the next chapter we will take a closer look at possible class variables and objects.

Chapter 9: Classes and Objects

You have seen Java classes and objects in earlier chapters of this e-book. At this point, you will gain more knowledge about class variables and available objects that you can use to achieve the desired results of why you are programming in a Java environment.

classes

As a blueprint for a Java program, classes are templates that describe the properties of an element or method. Basically, these are generic elements in Java programming. They also help a programmer understand another programmer's coding system by clarifying its structure. Classes exist in the program as long as they want, meaning they have no duration.

Below is a list of possible class variables:

Class - A class is a variable that must be declared before entering a class, found inside every class and outside every method.

Instance: Instance is a variable that stays inside a particular class but is outside a method. However, it is accessible from any other method once declared.

Local - A local is a variable defined in any method in the program that requires initial declaration and validation. It is omitted after the command or function is executed.

objects

Java objects are elements that have behaviors and states. When elements are defined, they bring their own attributes that add further value to an application component without including extended functionality. These are so-called instances of classes. The methods are executed correctly based on the behavior and states of the objects. Also, a specific object is associated with a unique function or command so that it obeys specific instructions. Unlike a class, an object stops

exists once the program has run.

One of the characteristics of object-oriented programming is the organization of things and concepts. There are three object relationships that define why items should or should not be moved to another specific application component:

Is-a relationship - this means that an object type is more specific than its peers (the number 1 is a Number)

Has a relationship - this means that an object type contains or is linked to another object (given number 1 and number 2: the number 1 has a next number, number 2)

Use-a relationship - This it means That a gender out object want be use another object as a program progresses (given the number 1, the number 2 and the number 3: the number 1 uses a Number 2 to get the sum of number 3)

Knowing how to work with classes and objects when programming is important use the Java Language out you I am consider how the generic elements the software. They also learned how they are organized and their relationships with each other . For the last but not the least chapter, you will get an idea of what all builders are out.

Chapter Ten: Builder

One of the many Java concepts introduced in this chapter is the importance of constructors. Constructors are one of many things, like methods, that allow for the declaration of elements or the creation of new objects.

Constructors act as directives that must match other elements in a predefined function each time they are called. They are also defined or provided by default in the Java programming language. The default constructors can set parameters, but are not designed to perform any specific task or unique action. They can't even support any arguments. An explicit version of a constructor is required to run certain commands and functions.

The main purpose of constructors is to initialize the invocation of another constructor by declaration Special () . On the recognition out a New Builder, a programmer is encouraged to create and set a parameter for introducing a Object.

This

This constructor is used to belong to a specific program component and is most often used as a reference to other constructors in a similar class, but with a different parameter list.

Example:

public class Dolphin {

string name;

dolphin (string input) { dolphin () {

this ( "Kevin/Kim" );

}

public static void int main(String arguments []) { dolphin p1 = new Dolphin("abigail")

dolphin p2 = new Dolphin();

}

}

In the example above, the use of this constructor refers to other named constructors Kevin and Kim under the Publicity class dolphin. That strings to have explain arguments and Two very out parameter I am set up - abigail after the page 1 and Originally builder after the p2 .

great

This constructor is usually identified on the first line of code, since Java compilers will not return a value unless super is declared initially. This keyword invokes a superclass constructor.

Example:

public class super superclass_penta { super superclass_penta [] {}

}

class tonic extends superclass_penta tonic() {

large [];

}

In this example, super is used as the constructor that defines superclass_penta. It is placed in the tonic class . Although a class is already known to have been previously defined, the power of a special constructor is possible.

This Chapter Has explain on his Two builders That his achievement use in Java programming - This and great _ It is necessary That his know as on use these constructors for program execution correct.

Here's a quick rundown of what we covered in case you need an update on a specific step:

You know how Java technology was took place

You learned how on to install and set up Java software and Miscellaneous necessary program instruments

You have learned how to create a simple Java program

You have learned how to add a user input function to your Java program

You have learned to correctly declare and manipulate variables

You learned how on alter the complexity out your Java program by operator

You learned how on carry out not consecutively Programming use to flow control instructions

You learned to distinguish Java access and use it appropriately modifiers

They learned to work with classes and objects

You Also learned how on correct use builders in your Java program

Practice exercises

Exercise #1 :

Write a program that displays each command line argument and the total number of arguments.

NOTE: Use an array variable called length to determine the length of the array.

Exercise #2 :

Write a program that rounds a sequence of ten random numbers from 0 to 100. Each individual round and then display the result on the screen. Note the following:

Create a class and a main() method for the calculation. Use the for loop statement .

Use Math.random() to generate the ten random numbers. To get a number between 0 and 100, just multiply the random number by 100.

Round the number using the Math.round() method . Rounding is necessary because the random() method always returns a value less than 1.0.

Display the rounded number on the screen.

Exercise no. 3:

Write a program that creates a new parent class in a main family class . The goal is also to use the text line "What a wonderful day!" on the screen.

Practice questions answers

Answer to exercise #1 :

public class MainPractice {

public static void main(String[] args) {

for (int i = 0; i < args.length; i++) { System.out.println(args[i]);

}

System.out.print("Total words:" + args.length);

}

}

Answer to exercise #2:

public class MathRandomRound {

public static void main(String[] argh) { for (int i = 0; i < 10; i++) {

double number = Math.random() * 100; System.out.print("The number " + number); System.out.println("round to " + Math.round(number));

}

}

}

Answer to exercise #3:

parent class {

}

public class Family {

public static void main(String[] args) {

System.out.println("How wonderful Day! "); parent parent = new Parent();

}

}

Before you go!

I hope you enjoyed learning the basics of Java programming through this eBook and found it useful to read. I made sure that my goal was achieved by writing this: to provide value for money without sacrificing education about what Java is. I think you will be pretty sure now that you will create your own Java program by following the guidelines I have included in this e-book.

I also strongly encourage you to learn other programming languages so that you can pass on your knowledge to others and become a top programmer. Since you have taken this course, you will be surprised that learning other languages is easier than expected because JavaScript has paved your way amazingly. I recommend python or JavaScript like the best languages to learn later.

Now I will really appreciate your reviews and feedback. If you really enjoyed this book, feel free to share it so that other people can benefit from this information too.