0% found this document useful (0 votes)
56 views27 pages

Java Basics Study Guide: We Lcome

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 27

Bellows College

NEWSLETTER

JAVA BASICS STUDY GUIDE

CAYTON, ARIAN CARL A.


DIEGO, JUDE
TAPIZ, ARACEL L.
BSCS-1B
WELCOME
9308A-CS112 (2:00-3:00)
SEPTEMBER 12,2019
Ur res qui volorrori ommodis
arum il ma sunt am harupta
tectotat quos rehentempos re-
reperem vello ditis as ea dio vel
maios renim conse eum, sae core
as nobis arum eate-mol uptaspici
con consed es-cit, voluptaquam
licidel inum que con nis modit
lautatem untionsequis aut
volessimus eseremq uatibea non
pel-lam facepel laccumquid ut
assi odis et et audanis cietur
aditati umquost que land-est, alit
dic tem quo od qui beaquos
sitionemped mag-
TABLE OF
CONTENTS

• Basic terms
• Program
• Programming Language
High-level, Low-level and
• Machine language
• Editor, Compiler, Interpreter,
JAM ES GOSLING •
Debugger, IDE
The Java Platform
• Language characteristics
• Evolution
Java execution environment (from
source code to executable)

The Java language


Variables and variable declarations
Data types
Primitive data types
Literal values
Primitive data type
Expressions
Identifiers: indicate the basic rules and
Conventions
Comments
Keywords
Operators group operators by category
Flow control structures illustrate the basic
Syntax by using code snippets
What is a PROGRAM?

As a verb, program or programming is a term used to describe the process of


a programmer developing a software program by PROGRAMMING.

As a noun, an application, application software, or program is software on


the computer that performs a specific function or task. For example, Microsoft
word is a word processing application that allows users to create and write
documents, and a browser.

When a program is created, it


is compiled into a language that the
computer can understand. Once
compiled, the program does not need
any other programs to run as long it as
the computer has the
required operating
system and platform.
Programming
Language
4.

A programming language is a computer language programmers use to develop


software programs, scripts, or other sets of instructions for computers to execute.

Although many languages share similarities, each has its own syntax. Once a
programmer learns the languages rules, syntax, and structure, they write the source
code in a text editor or IDE. Then, the programmer often compiles the code
into machine language that can be understood by the computer. Scripting languages,
which do not require a compiler, use an interpreter to execute the script.

Today, there are hundreds of different programming languages. The following


section contains an index of the different programming and scripting languages
currently listed on our site. Clicking on any of the following languages displays an
explanation and examples of that language.
A-C D-K L-Q R-Z

ActionScript D LeLisp R
ALGOL DarkBASIC Lisp Racket
Ada Dart LiveScript Reia
AIML * Datalog LOGO RPG
Altair BASIC dBASE Lua Ruby
Assembly Dylan MACLISP Rust
AutoHotkey EuLisp Matlab Scala
Babel Elixir Metro Scheme
BASIC F MUMPS Scratch
Batch file F# Nim SGML *
BCPL FORTRAN Objective-C Simula
BeanShell FoxPro OCaml Smalltalk
Brooks Franz Lisp Pascal SPL
C Go Perl SQL *
C# GW Basic PHP Stanford LISP
C++ Haskell Pick Swift
CL HDML * PureBasic Tcl
Clojure HTML * Python Turbo Pascal
COBOL InterLisp Prolog True BASIC
CoffeeScript ksh QBasic VHDL
Common Lisp Java Visual Basic
CPL JavaScript Visual FoxPro
CSS * JCL WML *
Curl Julia WHTML *
Curry Kotlin XLISP
XML *
YAML *
ZetaLisp
What are the top programming
languages?
There are many different ways this question could be
answered. However, we feel that the best method is to rely on the
data from GitHub, a service that hosts over 96 million different
software projects. In the below chart, GitHub shows the top 10
programming languages from 2014 to 2018.

In the chart above, you can see the top 10 languages


are: JavaScript, Java, Python, PHP, C++, C#, TypeScript, Shell, C, and Ruby.
High Level Languages are
written in a form that is close to our
human language, enabling to
programmer to just focus on the
problem being solved.

No particular knowledge of the


hardware is needed as high level
languages create programs that are
portable and not tied to a particular
computer or microchip.

These programmer friendly languages


are called ‘high level’ as they are far
removed from the machine
code instructions understood by the
computer.

Examples include: C++, Java, Pascal, Python, Visual Basic.

Advantages

• Easier to modify as it uses English like


statements
• Easier/faster to write code as it uses
English like statements
• Easier to debug during
development due to English like statements
• Portable code – not designed to run on
just one type of machine

Low level languages are used to write programs that relate to the specific architecture and hardware of
a particular type of computer. They are closer to the native language of a computer (binary), making them harder for
programmers to understand.
Examples of low level language:
Assembly Language
Machine Code
Assembly Language
Few programmers write programs in low level assembly language, but it is still used for developing code for specialist
hardware, such as device dvers.
It is easy distinguishable from a high level language as it contains few recognisable human words but plenty
of mnemonic code.

Advantages
Can make use of special hardware or special machine-dependent instructions (e.g. on the specific chip)
Translated program requires less memory
Write code that can be executed faster
Total control over the code
Can work directly on memory locations
Our Translators page explains how low-level languages are translated into machine code.
Machine Code
Programmers rarely write in machine code (binary) as it is difficult to understand.
The term EDITOR is commonly used to refer to a text editor, which is a software program that allows
users to create or manipulate plain text computer files. They are often used in the field of computer
programming.

Notepad and WordPad - Microsoft Windows included text editors.

TextEdit - Apple computer text editor.

Emacs - Text editor for all platforms that is a very powerful text editor

once you've learned all its commands and options.

Vi and Vim - Other great editors primarily used with Linux but also

available with multiple platforms.

Word - Word processor for Windows and Apple computers.

Writer - Text editor and word processor.

Ed - An ubiquitous file editor on Unix-like systems.

Microsoft Edit - MS-DOS text editor.

NEdit-A graphical text editor.

Pico - A console-based text editor.

Notepad++ - Our favorite free text editor, Notepad++ is a powerful

alternative to Windows Notepad.

TextPad - Our favorite shareware text editor.

EDITORS
COMPILER
A compiler is a special program that processes statements written in a particular programming language
and turns them into machine language or "code" that a computer's processor uses. Typically, a programmer writes
language statements in a language such as Pascal or C one line at a time using an editor. The file that is created
contains what are called the source statements. The programmer then runs the appropriate language compiler,
specifying the name of the file that contains the source statements.

When executing (running), the compiler first parses (or analyzes) all of the language statements
syntactically one after the other and then, in one or more successive stages or "passes", builds the output code,
making sure that statements that refer to other statements are referred to correctly in the final code. Traditionally,
the output of the compilation has been called object code or sometimes an object module. (Note that the term
"object" here is not related to object-oriented programming.) The object code is machine code that the processor
can execute one instruction at a time.

Examples of Compiler
C/C++ Microsoft Visual C++ (cl.exe)
Borland C (bcc.exe, bcc32.exe)
GNU Compiler (linux: gcc/g++, windows: mingw-
gcc.exe, mingw-g++.exe)
Open Watcom (wcc.exe, wcc32.exe)

Small Device C Compiler (sdcc.exe)


INTERPRETER

An interpreter is a computer program that


is used to directly execute program instructions
written using one of the many high-level
programming languages. The interpreter
transforms the high-level program into an intermediate language that it then executes, or it could parse the high-
level source code and then performs the commands directly, which is done line by line or statement by statement
er DEBUGGER

Even the
most experienced
software
programmers
usually don't get it
right on their first
try. Certain errors,
often called bugs,
can occur in
programs, causing
them to not

function as the programmer expected.


Sometimes these errors are easy to fix, while
some bugs are very difficult to trace. This is
especially true for large programs that consist
of several thousand lines of code.

Fortunately, there are programs called debuggers that help software developers find and eliminate bugs while
they are writing programs. A debugger tells the programmer what types of errors it finds and often marks the
exact lines of code where the bugs are found. Debuggers also allow programmers to run a program step by step
so that they can determine exactly when and why a program crash. Advanced debuggers provide detailed
information about threads and memory being used by the program during each step of execution.

A debugger is a computer program used by programmers to test and debug a target program. Debuggers may
use instruction-set simulators, rather than running a program directly on the processor to achieve a higher level
of control over its execution. This allows debuggers to stop or halt the program according to specific conditions.
However, use of simulators decreases execution speed.

When a program crashes, debuggers show the position of the error in the target program. Most debuggers also
are capable of running programs in a step-by-step mode, besides stopping on specific points. They also can
often modify the state of programs while they are running.
Integrated Development Environment (IDE)
An Integrated Development Environment (IDE) is an application that facilitates application development. In
general, an IDE is a graphical user interface (GUI)-based workbench designed to aid a developer in building
software applications with an integrated environment combined with all the required tools at hand.
Most common features, such as debugging, version control and data structure browsing, help a developer
quickly execute actions without switching to other applications. Thus, it helps maximize productivity by providing
similar user interfaces (UI) for related components and reduces the time taken to learn the language. An IDE
supports single or multiple languages.
TOP 10 best IDE software programs.
Microsoft Visual Studio. ...
NetBeans. ...
PyCharm. ...
IntelliJ IDEA. ...
Eclipse. ...
Code::Blocks. ...
Aptana Studio 3. ...
Komodo.
RubyMine
Xcode

EDITOR INTERPRETER

DEBUGGER
COMPILER

IDE
LANGUAGE
1) Java is SIMPLE CHARACTERISTICS

The Java programming language is easy to learn and use. Java code is easy to read and write.

2) Java is SECURE

The Java platform is designed with security features built into the language and runtime system such as static
type-checking at compile time and runtime checking (security manager), which let you creating applications that
can’t be invaded from outside. You never hear about viruses attacking Java applications. Java program cannot harm
other system thus making it secure.

3) Java is ROBUST

Java encourages error-free programming by being strictly typed and performing run-time checks. Java guides
programmer toward reliable programming habits for creating highly reliable applications.

4) Java is HIGH-PERFORMANCE

Java code is compiled into bytecode which is highly optimized by the Java compiler, so that the Java virtual
machine (JVM) can execute Java applications at full speed. In addition, compute-intensive code can be re-written in
native code and interfaced with Java platform via Java Native Interface (JNI) thus improve the performance.

5) Java is an OBJECT-ORIENTED PROGRAMMING LANGUAGE(OOP)

Like C++ java provides most of the object-oriented features. Java is pure OOP. Language, while C++ is semi
object oriented. It has all OOP features such as abstraction, encapsulation, inheritance and polymorphism. Java
provides the basic object technology of C++ with some enhancements and some deletions.Java is DYNAMIC

Java does not link invoked modules until runtime.


6) Java is PORTABLE
Java implements additional portability standards. For example, int s are always 32-bit, 2's-complemented
integers. User interfaces are built through an abstract window system that is readily implemented in Solaris and
other operating environments.
7) Java is DISTRIBUTED
Java contains extensive TCP/IP networking facilities. Library routines support protocols such as HyperText
Transfer Protocol (HTTP) and file transfer protocol (FTP).
8) Java is MULTITHREADED
The Java platform is designed with multithreading capabilities built into the language. That means you can
build applications with many concurrent threads of activity, resulting in highly interactive and responsive
applications.
9) Java is ARCHITECTURE NUETRAL
Java source code is compiled into architecture-independent object code. The object code is interpreted by a
Java Virtual Machine (JVM) on the target architecture. Software that is designed without regard to the target
platform. Software is often written to maximize the performance of a specific hardware platform, but such software
must be modified to make it run on other hardware.
Abstraction is a general concept that denotes the progress of modeling “real things” into programming language.
For example, when you write a class named Dog, you abstract a real dog into a type (class) in Java, When you
declare a field named breed in
the Dog class, you also abstract
the real attribute of the dog in
terms of a class’ variable, When
you implement a method
named bark() in the Dog class,
you also abstract the real
behavior, barking, of a dog in
terms of a method in a class.

Encapsulation is a technique
Creating an interface is also the process
that packages related data
of encapsulation.
and behaviors into a single
unit. This interface groups
the essential behaviors of human-being in a single unit. encapsulation is a technique for protecting data from
misuse by the outside world, which is referred as ‘information hiding’ or ‘data hiding’. For example:

Inheritance is the ability of a class inherits data and behaviors from another class. Note that only public and
protected members of the superclass are inherited by the subclass. The subclass can freely add new members to
extend
features of
This class models a real car (abstraction)
the which has 4 wheels and can carry up to 4
superclass. persons. It has basic behaviors of a standard
car (encapsulation) such as start, stop, gear,
turn and brake.

This car can also carry a small amount of goods


such as luggage and home stuffs. That’s good
enough for households.
However, if you open a consumer business, you
definitely need a bigger car that is able to
carry much more goods and carry fewer people.
You may guess it: A truck.

A truck is a car, except that it has bigger


payload, stronger engine and fewer seats. In
Java, we create the Truck class like this.

Polymorphism means “many forms”. In OOP, polymorphism means a type can point to different object at different
time. In other words, the actual object to which a reference type refers, can be determined at runtime. In Java,
polymorphism is based on inheritance and overriding.

In Java, you can implement polymorphism


if you have a super class (or a super
interface) with two or more sub classes.
As you can see, we have Animal as the
super interface, and 3 sub
classes: Dog, Bird and Fish.

Here, the common characteristics and


behaviors of a person are packaged into a
single unit: The Person class. This is the
process of encapsulation.

Here, the keyword extends is used to make a class inherits data and behaviors of
another class. This is called Inheritance. The Truck class inherits all the
characteristics and behaviors of a car.

The Person class is an encapsulation unit.


A Person object exposes its attributes and behaviors to
the outside world.
Evolution OF JAVA
Java Execution environement (from source code to executable)

The JRE (Java Runtime Environment) smoothed over the diversity of operating systems, ensuring that Java
programs can run on virtually any OS without modification. It also provides value-added services. Automatic
memory management is one of the JRE's most important services, ensuring that programmers don't have to
manually control the allocation and reallocation of memory.

In short, the JRE is a sort of meta-OS for Java programs. It's a classic example of abstraction, abstracting
the underlying operating system into a consistent platform for running Java applications.

The Java Runtime Environment is the on-disk program that loads Java applications for the JVM to execute.
A JRE is included by default when you download the Java Development Kit, and each JRE includes the core Java
class libraries, a Java class loader, and a Java Virtual Machine. It's helpful to understand how the JVM, JDK and JRE
interact, especially for working in cloud and devops environments. In these environments, the JRE takes a stronger
role in monitoring and configuration than it would in traditional Java application development.

JRE Components
The JRE is the software environment in which programs compiled for a typical JVM implementation can run.
The runtime system includes:

• Code necessary to run Java programs, dynamically link native methods, manage memory, and handle
exceptions
• Implementation of the JVM

The following figure shows the JRE and its components, including a typical JVM implementation's various modules
and its functional position with respect to the JRE and class libraries.

How the JRE works with the JVM


A Java Virtual Machine is a running software system responsible for executing
live Java programs. The JRE is the on-disk system that takes your Java code, combines it
with the necessary libraries, and starts the JVM to execute it.

The JRE contains libraries and software that your Java programs need to run. As
an example, the Java class loader is part of the Java Run time Environment. This
important piece of software loads compiled Java code into memory and connects the
code to the appropriate Java class libraries.
Installing and using the JRE
While there is a conceptual side
to the JRE, in real-world practice it's just
software installed on a computer,
whose purpose is to run your Java
programs. As a developer, you'll mostly
work with the JDK and JVM, because
those are the platform components you
use to develop and run your Java
programs. As a Java application user,
you would be more involved with the
JRE, which lets you run those programs.

In most cases, your computer will come


with Java installed, and the JRE will be
included with that. If you do ever need
to manually install or upgrade, you
can download the current JRE
version from Oracle.

Once the JRE is installed, you can


interact with it on the command-line by
entering java -version, which will tell
you what version is installed. On POSIX
systems, you can always check the
installed location with which java.

Java memory and the JRE


Java memory consists of three
components: the heap, stack and
metaspace (which was previously called
permgen).

• Metaspace is where Java keeps your program's unchanging info like class definitions.
• Heap space is where Java keeps variable content.
• Stack space is where Java stores function execution and variable references.

Step1: Create HelloWorld.java


Enter the following code in the text editor.
Step2: Compile HelloWorld.java
use javac HelloWorld.java (press enter)
Step3:
After compiling java file, you can see .class file
created (HelloWorld.class). This is bytecode of
our java program which can run on any
platform. We can try running on our JRE using
java command – java
HelloWorld (press
enter)
NOTE:
Keep in mind that Java is a case-sensitive
language, which means that if you named
the program HelloWorld with a capital H and
a capital W, you should not try to start the
program helloworld.


Variable and Variables Declaration
Variables are the identifier of the memory location, A variable is a container which holds the value while
which used to save data temporarily for later

use in the program. During execution of


the java program is executed. A variable is assigned
a program, values can be stored in a variable, and
with a datatype.
the stored value can be changed. In Java
Variable is a name of memory location. There are
programming, it is necessary to declare the variable
three types of variables in java: local, instance and
before being used.
static. There are two types of data types in java:
primitive and non-primitive.
Variable is name of reserved area allocated in memory. In other words, it is a name of memory location. It is a
combination of "vary + able" that means its value can be
changed.
Types of Variables
1) Local Variable
A variable declared inside the body of the method is called local variable. You
can use this variable only within that method and the
other methods in the class aren't even aware that the
variable exists.
A local variable cannot be defined with "static" keyword.

2) Instance Variable
A variable declared inside the class but outside the b ody
of the method, is called instance variable. It is not
declared as static.
It is called instance variable because its value is instance
specific and is not shared among instances.

3) Static variable
EXAMPLE :
A variable which is declared as static is called static variable. It
cannot be local. You can create a single copy of static variable and share among
all the instances of the class. Memory allocation for static variable happens only
once when the class is loaded in the memory.

Declaration of Instance Variables :


Variables defined within a class are called instance variables because each instance of the class (that is,
each object of the class) contains its own copy of these variables. Thus, the data for one object is separate and
unique from the data for another. An instance variable can be declared public or private or default (no modifier).
When we do not want our variable’s value to be changed out-side our class we should declare them private. public
variables can be accessed and changed from outside of the class.

In this example, we have declared three variables using var keyword: one, two and three. We have
assigned values to variables one and two at the
same time when we declared it, whereas variable
three is declared but does not hold any value yet,
so it's value will be 'undefined'.

Points to Remember :
Variable stores a single data value that
can be changed later.
Variables can be defined
using var keyword. Variables defined
without var keyword become global variables.
Variables must be initialized before using.
Multiple variables can be defined in a single
line. e.g. var one = 1, two = 2, three = "three";
Variables in JavaScript are loosely-typed
variables. It can store value of any data type throughout its life time.

1. Variable stores a single data value that can be changed later.


2. Variables can be defined using var keyword. Variables defined without var keyword become global variables.
3. Variables must be initialized before using.
4. Multiple variables can be defined in a single line. e.g. var one = 1, two = 2, three = "three";
5. Variables in JavaScript are loosely-typed variables. It can store value of any data type through out it's li
6. fe time.
Data Types in Java

Data types specify the different sizes and values that can be stored in the variable. There are two types of data
types in Java:

1. Primitive data types: The primitive data types include boolean, char, byte, short, int, long, float and
double.
2. Non-primitive data types: The non-primitive data types include Classes, Interfaces, and Arrays.

Primative Data Types

Java Primitive Data Types

In Java language, primitive data types are the building blocks of data manipulation. These are the most
basic data types available in Java language.

There are 8 types of primitive data types:

o boolean data type


o byte data type
o char data type
o short data type
o int data type
o long data type
o float data type
o double data type

A Boolean type represents


either true or false value.
A char type represents a single character, such as 'a', 'B', 'c', ...Actually char type is 16-bit integer number (un-
signed).

The others are numeric types.


Boolean Data Type
The Boolean data type is used to store only two possible values: true and false. This data type is used for simple
flags that track true/false conditions.
The Boolean data type specifies one bit of information, but its "size" can't be defined precisely.
Example: Boolean one = false

Byte Data Type


The byte data type is an example of primitive data type. It isan 8-bit signed two's complement integer. Its value-
range lies between -128 to 127 (inclusive). Its minimum value is -128 and maximum value is 127. Its default value
is 0.
The byte data type is used to save memory in large arrays where the memory savings is most required. It saves
space because a byte is 4 times smaller than an integer. It can also be used in place of "int" data type.
Example: byte a = 10, byte b = -20

Short Data Type


The short data type is a 16-bit signed two's complement integer. Its value-range lies between -32,768 to 32,767
(inclusive). Its minimum value is -32,768 and maximum value is 32,767. Its default value is 0.
The short data type can also be used to save memory just like byte data type. A short data type is 2 times smaller
than an integer.
Example: short s = 10000, short r = -5000
Int Data Type
The int data type is a 32-bit signed two's complement integer. Its value-range lies between - 2,147,483,648 (-2^31)
to 2,147,483,647 (2^31 -1) (inclusive). Its minimum value is - 2,147,483,648and maximum value is 2,147,483,647.
Its default value is 0.
The int data type is generally used as a default data type for integral values unless if there is no problem about
memory.
Example: int a = 100000, int b = -200000

Long Data Type


The long data type is a 64-bit two's complement integer. Its value-range lies between -
9,223,372,036,854,775,808(-2^63) to 9,223,372,036,854,775,807(2^63 -1)(inclusive). Its minimum value is -
9,223,372,036,854,775,808and maximum value is 9,223,372,036,854,775,807. Its default value is 0. The long data
type is used when you need a range of values more than those provided by int.
Example: long a = 100000L, long b = -200000L

Float Data Type


The float data type is a single-precision 32-bit IEEE 754 floating point.Its value range is unlimited. It is
recommended to use a float (instead of double) if you need to save memory in large arrays of floating point
numbers. The float data type should never be used for precise values, such as currency. Its default value is 0.0F.
Example: float f1 = 234.5f

Double Data Type


The double data type is a double-precision 64-bit IEEE 754 floating point. Its value range is unlimited. The double
data type is generally used for decimal values just like float. The double data type also should never be used for
precise values, such as currency. Its default value is 0.0d.
Example: double d1 = 12.3

Char Data Type


The char data type is a single 16-bit Unicode character. Its value-range lies between '\u0000' (or 0) to '\uffff' (or
65,535 inclusive). The char data type is used to store characters.
Example: char letterA = 'A'

An identifier is the representation within the language of items created by the user, as opposed to
language keywords or commands. Some identifiers stand for dictionary objects, which are the objects you create-
such as tables, views, indexes, columns, and constraints- that are stored in a database. They are called dictionary
objects because Derby stores information about them in the system tables, sometimes known as a data dictionary.
SQL also defines ways to alias these objects within certain statements.
Comments Within SQL Statements

Comments can make your application easier for you to read and maintain. For example, you can include
a comment in a statement that describes the purpose of the statement within your application. With the exception
of hints, comments within SQL statements do not affect the statement execution. Please refer to "Hints " on using
this particular form of comment.

A comment can appear between any keywords, parameters, or punctuation marks in a statement. You can
include a comment in a statement in two ways:
ADMIN CURSOR FOUND MOUNT
• Begin the comment with a slash and an
asterisk (/*). Proceed with the text of the AFTER CYCLE FUNCTION NEXT
comment. This text can span multiple lines. ALLOCATE DATABASE GO NEW
End the comment with an asterisk and a ANALYZE DATAFILE GOTO NOARCHIVELOG
slash (*/). The opening and terminating ARCHIVE DBA GROUPS NOCACHE
characters need not be separated from the
ARCHIVELOG DEC INCLUDING NOCYCLE
text by a space or a line break.
• Begin the comment with -- (two hyphens). AUTHORIZATION DECLARE INDICATOR NOMAXVALUE
Proceed with the text of the comment. This AVG DISABLE INITRANS NOMINVALUE
text cannot extend to a new line. End the BACKUP DISMOUNT INSTANCE NONE
comment with a line break.
BEGIN DOUBLE INT NOORDER
BECOME DUMP KEY NORESETLOGS
Some of the tools used to enter SQL have additional
restrictions. For example, if you are using SQL*Plus, BEFORE EACH LANGUAGE NORMAL
by default you cannot have a blank line inside a BLOCK ENABLE LAYER NOSORT
multiline comment. For more information, please BODY END LINK NUMERIC
refer to the documentation for the tool you use as an
CACHE ESCAPE LISTS OFF
interface to the database.
CANCEL EVENTS LOGFILE OLD
The following words also have a special meaning to CASCADE EXCEPT MANAGE ONLY
Oracle but are not reserved words and so can be CHANGE EXCEPTIONS MANUAL OPEN
redefined. However, some might eventually become CHARACTER EXEC MAX OPTIMAL
reserved words.
CHECKPOINT EXPLAIN MAXDATAFILES OWN
CLOSE EXECUTE MAXINSTANCES PACKAGE
Definition - What does Keyword mean?
COBOL EXTENT MAXLOGFILES PARALLEL
In Java, a keyword is a word with a predefined COMMIT EXTERNALLY MAXLOGHISTORY PCTINCREASE
meaning in Java programming language syntax.
COMPILE FETCH MAXLOGMEMBERS PCTUSED
Reserved for Java, keywords may not be used as
identifiers for naming variables, classes, methods or CONSTRAINT FLUSH MAXTRANS PLAN
other entities. CONSTRAINTS FREELIST MAXVALUE PLI
CONTENTS FREELISTS MIN PRECISION
There are 50 reserved keywords in the Java CONTINUE FORCE MINEXTENTS PRIMARY
programming language. Because these keywords
CONTROLFILE FOREIGN MINVALUE PRIVATE
have predefined functions, they are usually
highlighted with different colors in most integrated COUNT FORTRAN MODULE PROCEDURE
development environments (IDE) used by Java
programmers.

Common Java keywords include abstract, assert, boolean, break, byte, case, catch, char, class, const, continue,
default, do, for, while, switch, this and int. The keywords const and goto are reserved but not currently used by
the Java language. False, null and true are reserved
keywords for literal values

Java operators are symbols that are used to perform mathematical or logical manipulations. Java is rich with
built-in operators. Operators are tokens that perform some calculations when they are applied to variables.

There are many types of operators available in Java such as:


• Arithmetic Operators
Operator Meaning Work

+ Addition To add two operands.

- Subtraction To subtract two operands.

* Multiplication To multiply two operands.

/ Division To divide two operands.

% Modulus To get the area of the division of two operands.

• Unary Arithmetic Operators

val = a++; Store the value of "a" in "val" then increments.

val = a--; Store the value of "a" in "val" then decrements.

val = ++a; Increments "a" then store the new value of "a" in "val".

val = --a; Decrements "a" then store the new value of "a" in "val".

• Relational Operators

Operator Meaning

== Is equal to

!= Is not equal to

> Greater than

< Less than

>= Greater than or equal to

<= Less than or equal to


• Logical Operators

Operator Meaning Work

&& Logical If both operands are true then only "logical AND operator" evaluate true.
AND

|| Logical The logical OR operator is only evaluated as true when one of its operands
OR evaluates true. If either or both expressions evaluate to true, then the result is
true.

! Logical Logical NOT is a Unary Operator, it operates on single operands. It reverses the
Not value of operands, if the value is true, then it gives false, and if it is false, then it
gives true.

• Bitwise
Operators

Operator Meaning Work

& Binary AND There are two types of AND operators in Java: the logical && and the
Operator binary &. Binary & operator work very much the same as
logical && operators works, except it works with two bits instead of
two expressions. The "Binary AND operator" returns 1 if both
operands are equal to 1.

| Binary OR Like "AND operators ", Java has two different "OR" operators: the
Operator logical || and the binary |. Binary | Operator work similar to
logical || operators works, except it, works with two bits instead of
two expressions. The "Binary OR operator" returns 1 if one of its
operands evaluates as 1. if either or both operands evaluate to 1, the
result is 1.

^ Binary XOR It stands for "exclusive OR" and means "one or the other", but not
Operator both. The "Binary XOR operator" returns 1 if and only if exactly one
of its operands is 1. If both operands are 1, or both are 0, then the
result is 0.

~ Binary
Complement
Operator

<< Binary Left


Shift
Operator
>> Binary Right
Shift
Operator

>>> Shift right


zero fill
operator

Assignment Operators
• The Java Assignment Operators are used when you want to assign a value to the expression. The
assignment operator denoted by the single equal sign.

• In a Java assignment statement, any expression can be on the right side and the left side must be a variable
name. For example, this does not mean that "a" is equal to "b", instead, it means assigning the value of
'b' to 'a'. It is as follows:
• Syntax:
• variable = expression;
• Example:
• int a = 6;
• float b = 6.8F;

• Conditional Operator

• The Java Conditional Operator selects one of two expressions for evaluation, which is based on the value
of the first operands. It is also called ternary operator because it takes three arguments.
• The conditional operator is used to handling simple situations in a line.
• Syntax:

• expression1 ? expression2:expression3;

• The above syntax means that if the value given in Expression1 is true, then Expression2 will be evaluated;
otherwise, expression3 will be evaluated.
• Example:

• val == 0 ? you are right:you are not right;

• Instance of Operator

• The Java Instance of Operator is used to determining whether this object belongs to this particular (class
or subclass or interface) or not.
• This operator gives the boolean values such as true or false. If it relates to a specific class, then it returns
true as output. Otherwise, it returns false as output.
• Syntax:

• object-reference instanceof type;


• Program to Show Downcasting with instanceof Operator

• Example:

• class Company {}

• public class Employee extends Company {

• public void check() {

• System.out.println("Success.");

• }

• public static void view(Company c) {

• if (c instanceof Employee) {

• Employee b1 = (Employee) c;

• b1.check();

• }

• }

• public static void main(String[] args) {

• Company c = new Employee();

• Employee.view(c);

• }

• }

• Output:

• Success.
• Member Selection or Dot Operator
Widget w = new Widget();
System.out.println(w.price);
System.out.println(w.getPrice());
Creating an object in Java and accessing its features.
Widget w0; Widget* w1 = new widget;
cout << w0.price << endl; cout << w1->price << endl;
cout << w0.getPrice() << endl; cout << w1->getPrice() << endl;
(a) (b)
Creating an object in C++ and accessing its features. Java can only create an object in one way, but C++ has two
ways of creating objects:

• The object is created as an automatic object and its features are accessed using the dot operator
• The object is created as a dynamic object on the heap and its features are accessed with the arrow
operator

In C++, when we need to access a member through a pointer, the dot operator by itself is not sufficient. Earlier in
this chapter we saw examples involving simple data types that required us to dereference a pointer to access the
contents of the referenced memory address. We can take the same approach when accessing members:
dereference the pointer first and then access the member with the dot operator:

Widget* w1 = new widget;


cout << (*w1).price << endl;
cout << (*w1).getPrice() << endl;

• Alternative syntax for accessing features through a pointer. The arrow operator is a convenience or
"shortcut" operator that combines the dereference and member selection operations into a single
operator. The dot operator has a higher precedence than the indirection operator, which means that the
parentheses are required. Although this syntax works, the arrow operator provides a cleaner, more easily
used syntax and is more common.

Control Flow Statements

The statements inside your source files are


generally executed from top to bottom, in
the order that they appear. Control flow
statements, however, break up the flow of
execution by employing decision making,
looping, and branching, enabling your

program to conditionally execute


particular blocks of code. This
section describes the decision-
making statements (if-then, if-
then-else, switch), the looping
statements (for, while, do-while),
and the branching statements
(break, continue, return) supported
by the Java programming language.
REFERENCES
https://www.javaworld.com/article/3304858/what-is-the-jre-introduction-to-the-
java-runtime-environment.html
https://www.kettlemag.co.uk/the-history-of-the-java-programming-language/
https://www.w3resource.com/java-tutorial/java-class-methods-instance-
variables.php
https://www.javatpoint.com/java-variables
https://www.w3resource.com/java-tutorial/download-and-Install-JDK-Eclipse-
IDE.php
https://www.tutorialsteacher.com/javascript/javascript-variable
https://www.javatpoint.com/java-data-types
https://www.thoughtco.com/expression-2034097
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/flow.html
https://www.howto-guides.com/2019/03/declaring-variables-in-java.html
https://www.techopedia.com/definition/597/debugger
https://searchsoftwarequality.techtarget.com/definition/program
https://techterms.com/definition/program
https://www.webopedia.com/TERM/P/programming_language.html
https://www.computerhope.com/jargon/p/programming-language.htm
https://www.techopedia.com/definition/3925/high-level-language-hll
https://www.computerscience.gcse.guru/theory/high-low-level-languages
https://www.computerhope.com/jargon/l/lowlangu.htm
https://techterms.com/definition/low-level_language
https://www.geeksforgeeks.org/editors-types-system-programming/
https://whatis.techtarget.com/definition/compiler
https://www.techopedia.com/definition/3912/compiler
https://www.programiz.com/article/difference-compiler-interpreter
https://www.techopedia.com/definition/7793/interpreter
https://www.techopedia.com/definition/597/debugger
https://searchsoftwarequality.techtarget.com/definition/integrated-
development-environment
https://docs.oracle.com/cd/E19798-01/821-1841/bnbuk/index.html
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/opsummary.html
https://www.w3schools.in/java-tutorial/operators/
http://www.corejavaguru.com/java/basic/controlstatements
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/flow.html

You might also like