0% found this document useful (0 votes)
4 views16 pages

Attachment

The document provides an introduction to Java, highlighting its features such as being object-oriented, platform-independent, secure, and robust. It explains Java tokens, including keywords, identifiers, literals, operators, separators, and comments, which are essential components of Java programming. Additionally, it covers control flow statements like if statements and loops (while and for) that are fundamental in programming logic.

Uploaded by

adityapandji1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views16 pages

Attachment

The document provides an introduction to Java, highlighting its features such as being object-oriented, platform-independent, secure, and robust. It explains Java tokens, including keywords, identifiers, literals, operators, separators, and comments, which are essential components of Java programming. Additionally, it covers control flow statements like if statements and loops (while and for) that are fundamental in programming logic.

Uploaded by

adityapandji1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

JAVA Chapter 1

Notes

Introduction to JAVA :

Java is a high-level programming language originally developed by Sun


Microsystems and released in 1995. Java runs on a variety of platforms,
such as Windows, Mac OS, and the various versions of UNIX.

Features of JAVA:

Object Oriented

In Java, everything is an Object. Java can be easily extended since it is based on


the Object model.

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

MSBTE NEXT ICON COURSE YOUTUBE CHANNEL – UR ENGINEERING FRIEND


With Java's secure feature it enables to develop virus-free, tamper-free systems.
Authentication techniques are based on public-key encryption.

Architecture-neutral

Java compiler generates an architecture-neutral object file format, which makes


the compiled code executable on many processors, with the presence of Java
runtime system.

Portable

Being architecture-neutral and having no implementation dependent aspects of


the specification makes Java portable. The compiler in Java is written in ANSI
C with a clean portability boundary, which is a POSIX subset.

Robust

Java makes an effort to eliminate error-prone situations by emphasizing mainly


on compile time error checking and runtime checking.

Multithreaded

With Java's multithreaded feature it is possible to write programs that can


perform many tasks simultaneously. This design feature allows the developers
to construct interactive applications that can run smoothly.

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

MSBTE NEXT ICON COURSE YOUTUBE CHANNEL – UR ENGINEERING FRIEND


With the use of Just-In-Time compilers, Java enables high performance.

Distributed

Java is designed for the distributed environment of the internet.

Dynamic

Java is considered to be more dynamic than C or C++ since it is designed to


adapt to an evolving environment. Java programs can carry an extensive amount
of run-time information that can be used to verify and resolve accesses to
objects at run-time.

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.

MSBTE NEXT ICON COURSE YOUTUBE CHANNEL – UR ENGINEERING FRIEND


Java token includes the following:

 Keywords
 Identifiers
 Literals
 Operators
 Separators
 Comments

Keywords: These are the pre-defined reserved words of any programming


language. Each keyword has a special meaning. It is always written in lower
case. Java provides the following keywords:

MSBTE NEXT ICON COURSE YOUTUBE CHANNEL – UR ENGINEERING FRIEND


Identifier: Identifiers are used to name a variable, constant, function, class, and
array. It usually defined by the user. It uses letters, underscores, or a dollar sign
as the first character. The label is also known as a special kind of identifier that
is used in the goto statement. Remember that the identifier name must be
different from the reserved keywords. There are some rules to declare identifiers
are:

 The first letter of an identifier must be a letter, underscore or a dollar


sign. It cannot start with digits but may contain digits.
 The whitespace cannot be included in the identifier.
 Identifiers are case sensitive.

Literals: In programming literal is a notation that represents a fixed value


(constant) in the source code. It can be categorized as an integer literal, string
literal, Boolean literal, etc. It is defined by the programmer. Once it has been
defined cannot be changed. Java provides five types of literals are as follows:

MSBTE NEXT ICON COURSE YOUTUBE CHANNEL – UR ENGINEERING FRIEND


 Integer
 Floating Point
 Character
 String
 Boolean

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

Separators: The separators in Java is also known as punctuators. There are


nine separators in Java, are as follows:

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.

MSBTE NEXT ICON COURSE YOUTUBE CHANNEL – UR ENGINEERING FRIEND


4. Curly Braces {}: The curly braces denote the starting and ending of a
code block.
5. Comma (,): It is used to separate two values, statements, and parameters.
6. Assignment Operator (=): It is used to assign a variable and constant.
7. Semicolon (;): It is the symbol that can be found at end of the statements.
It separates the two statements.
8. Period (.): It separates the package name form the sub-packages and
class. It also separates a variable or method from a reference variable.

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:

 Line Oriented: It begins with a pair of forwarding slashes (//).


 Block-Oriented: It begins with /* and continues until it founds */.

Operators:

Operators are used to perform operations on variables and values.

Python divides the operators in the following groups:

 Arithmetic operators
 Assignment operators ( not useful for MSBTE )
 Relational operators
 Logical operators
 Identity operators
 Membership operators ( will discuss in list and tuples topic )

MSBTE NEXT ICON COURSE YOUTUBE CHANNEL – UR ENGINEERING FRIEND


 Bitwise operators ( not for MSBTE )

Arithmetic Operators:

MSBTE NEXT ICON COURSE YOUTUBE CHANNEL – UR ENGINEERING FRIEND


Relational Operators:

Logical Operators:

MSBTE NEXT ICON COURSE YOUTUBE CHANNEL – UR ENGINEERING FRIEND


Conditional Statement

Conditional Statement in Python perform different computations or actions


depending on whether a specific Boolean constraint evaluates to true or false.
Conditional statements are handled by IF statements in Python.

Major Types of Conditional Statement in Python

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...

......................

MSBTE NEXT ICON COURSE YOUTUBE CHANNEL – UR ENGINEERING FRIEND


IF Else :

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

MSBTE NEXT ICON COURSE YOUTUBE CHANNEL – UR ENGINEERING FRIEND


Nested IF :

We can have a if...elif...else statement inside another


if...elif...else statement. This is called nesting in computer
programming.

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.

MSBTE NEXT ICON COURSE YOUTUBE CHANNEL – UR ENGINEERING FRIEND


Syntax:

while (test_expression)
{
// statements

update_expression;
}

The various parts of the While loop are:

1. Test Expression: In this expression we have to test the condition. If the


condition evaluates to true then we will execute the body of the loop and
go to update expression. Otherwise, we will exit from the while loop.
Example:

i <= 10

2. Update Expression: After executing the loop body, this expression


increments/decrements the loop variable by some value.
Example:

i++;

How does a While loop executes?

1. Control falls into the while loop.


2. The flow jumps to Condition
3. Condition is tested.
a. If Condition yields true, the flow goes into the Body.
b. If Condition yields false, the flow goes outside the loop
4. The statements inside the body of the loop get executed.
5. Updation takes place.
6. Control flows back to Step 2.
7. The do-while loop has ended and the flow has gone outside.

MSBTE NEXT ICON COURSE YOUTUBE CHANNEL – UR ENGINEERING FRIEND


Flow chart while loop (for Control Flow):

Example 1: This program will try to print “Hello World” 5 times.

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.

MSBTE NEXT ICON COURSE YOUTUBE CHANNEL – UR ENGINEERING FRIEND


Syntax:

for (initialization expr; test expr; update exp


{
// body of the loop
// statements we want to execute
}

The various parts of the For loop are:

1. Initialization Expression: In this expression we have to initialize the


loop counter to some value.
Example:

int i=1;

2. Test Expression: In this expression we have to test the condition. If the


condition evaluates to true then we will execute the body of the loop and
go to update expression. Otherwise, we will exit from the for loop.
Example:

i <= 10

3. Update Expression: After executing the loop body, this expression


increments/decrements the loop variable by some value.
Example:

i++;

How does a For loop executes?

1. Control falls into the for loop. Initialization is done


2. The flow jumps to Condition

MSBTE NEXT ICON COURSE YOUTUBE CHANNEL – UR ENGINEERING FRIEND


3. Condition is tested.
a. If Condition yields true, the flow goes into the Body
b. If Condition yields false, the flow goes outside the loop
4. The statements inside the body of the loop get executed.
5. The flow goes to the Updation
6. Updation takes place and the flow goes to Step 3 again
7. The for loop has ended and the flow has gone outside.

Flow chart for loop (For Control Flow):

MSBTE NEXT ICON COURSE YOUTUBE CHANNEL – UR ENGINEERING FRIEND

You might also like