Attachment
Attachment
Notes
Introduction to JAVA :
Features of JAVA:
Object Oriented
Platform Independent
Unlike many other programming languages including C and C++, when Java is
compiled, it is not compiled into platform specific machine, rather into
platform-independent byte code. This byte code is distributed over the web and
interpreted by the Virtual Machine (JVM) on whichever platform it is being run
on.
Simple
Java is designed to be easy to learn. If you understand the basic concept of OOP
Java, it would be easy to master.
Secure
Architecture-neutral
Portable
Robust
Multithreaded
Interpreted
Java byte code is translated on the fly to native machine instructions and is not
stored anywhere. The development process is more rapid and analytical since
the linking is an incremental and light-weight process.
High Performance
Distributed
Dynamic
JAVA TOKENS
In Java, the program contains classes and methods. Further, the methods contain
the expressions and statements required to perform a specific operation. These
statements and expressions are made up of tokens. In other words, we can say
that the expression and statement is a set of tokens. The tokens are the small
building blocks of a Java program that are meaningful to the Java compiler.
Further, these two components contain variables, constants, and operators.
Keywords
Identifiers
Literals
Operators
Separators
Comments
Operators: In programming, operators are the special symbol that tells the
compiler to perform a special operation. Java provides different types of
operators that can be classified according to the functionality they provide.
There are eight types of operators in java , are as follows:
Arithmetic Operators
Assignment Operators
Relational Operators
Unary Operators
Logical Operators
Ternary Operators
Bitwise Operators
Shift Operators
1. separator <= ; | , | . | ( | ) | { | } | [ | ]
2. Square Brackets []: It is used to define array elements. A pair of square
brackets represents the single-dimensional array, two pairs of square
brackets represent the two-dimensional array.
3. Parentheses (): It is used to call the functions and parsing the parameters.
Comments: allow us to specify information about the program inside our Java
code. Java compiler recognizes these comments as tokens but excludes it form
further processing. The Java compiler treats comments as whitespaces. Java
provides the following two types of comments:
Operators:
Arithmetic operators
Assignment operators ( not useful for MSBTE )
Relational operators
Logical operators
Identity operators
Membership operators ( will discuss in list and tuples topic )
Arithmetic Operators:
Logical Operators:
1. IF
2. IF...ELSE
3. Nested IF
IF Statement :
IF statement is used to execute or check only one statement. If that block is true
then it execute the ode otherwise terminated from the block .
If ( condition ) :
Statements...
......................
It contains a body of code which runs only when the condition given in the if
statement is true. If the condition is false, then the optional else statement runs
which contains some code for the else condition.
if expression
Statement
else
Statement
Any number of these statements can be nested inside one another. Indentation is
the only way to figure out the level of nesting. They can get confusing, so they
must be avoided unless necessary.
If ( condition ):
If ( condition ):
Statement .......
while loop
It is a control flow statement that allows code to be executed repeatedly based
on a given Boolean condition. The while loop can be thought of as a repeating if
statement.
while (test_expression)
{
// statements
update_expression;
}
i <= 10
i++;
For loop :
Java for loop provides a concise way of writing the loop structure. The for statement
consumes the initialization, condition and increment/decrement in one line thereby providing
a shorter, easy to debug structure of looping.
int i=1;
i <= 10
i++;