0% found this document useful (0 votes)
3 views6 pages

Translated Java Notes

The document provides an introduction to Java programming, covering fundamental concepts such as data types, variables, operators, control statements, classes, objects, and methods. It details primitive and non-primitive data types, various operators, and control flow mechanisms like loops and decision-making statements. Additionally, it explains the significance of classes and objects in object-oriented programming, as well as the role of reference variables and methods in Java.

Uploaded by

k9854602
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)
3 views6 pages

Translated Java Notes

The document provides an introduction to Java programming, covering fundamental concepts such as data types, variables, operators, control statements, classes, objects, and methods. It details primitive and non-primitive data types, various operators, and control flow mechanisms like loops and decision-making statements. Additionally, it explains the significance of classes and objects in object-oriented programming, as well as the role of reference variables and methods in Java.

Uploaded by

k9854602
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

Unit - I

Introducing ■■■■ ■■■■■■ (Data Types) : Java’s Primitive Types, Literals,


Java ■■■■■■■■■ (Variables)
■■■■■■ (Operators): operators, Type , Operator Precedence, The Bitwise operators.
Conversion in Assignments: Cast, Expressions.
■■■■■■■■ ■■■ (Control Statements): Input characters from the Keyboard, if statement, Nested ifs, if-else-if ,Ladder, Switch Stat
Introduction to ■■■■■ (Classes), ■■■■■■■■■■ (Objects) and ■■■■■■ (Methods), Class Fundamentals, Reference ■■■■■■
Constructors, Parameterized Constructors, The new operator.
Arrays, Multidimensional Arrays, Alternative Array Declaration Syntax, Assigning Array References, Using the Length Member,
Introducing ■■■■ ■■■■■■ (Data Types) : Java’s Primitive Types, Literals,
Data types in Java are of different sizes and values that can be stored in the variable that is made as per convenience and circumsta
Primitive Data Type: Boolean, char, int, short, byte, long, float, and double.
Non-Primitive Data Type or Object Data type: String, Array, etc.
Primitive ■■■■ ■■■■■■ (Data Types)
1. Boolean Data Type
The boolean data type represents a logical value that can be either true or false.
Syntax:
Boolean variable name;
2. Byte Data Type
The byte data type is an 8-bit signed two’s complement integer. The byte data type is useful for saving memory in large arrays.
Syntax:
byte variable name;
3. short Data Type
The short data type is a 16-bit signed two’s complement integer.
Syntax:
short variable name;
4. int Data Type
It is a 32-bit signed two’s complement integer.
Syntax:
int variable name;
5. long Data Type
It is used when an int is not large enough to hold a value, offering a much broader range.
Syntax:
long variable name;
6. float Data Type
The size of the float data type is 4 bytes (32 bits).
Syntax:
float variable name;
7. double Data Type
The size of the double data type is 8 bytes or 64 bits.
Syntax:
double variable name;
8. char Data Type
The char data type is a single 16-bit Unicode character with the size of 2 bytes (16 bits).
Syntax:
char Variablename;
Non-Primitive ■■■■ ■■■■■■ (Data Types)
The Non-Primitive (Reference) ■■■■ ■■■■■■ (Data Types) will contain a memory address of variable values because the referen
Strings: Strings are defined as an array of characters. The difference between a character array and a string in Java is, that the strin
Syntax: Declaring a string
String variable name = “ sequence_of_string”;
Class :
A Class is a user-defined blueprint or prototype from which objects are created. It represents the set of properties or methods that ar
3. Object
An Object is a basic unit of Object-Oriented Programming and represents real-life entities.
4. Interface
Like a class, an interface can have methods and variables.
5. Array
An Array is a group of like-typed variables that are referred to by a common name.
Java ■■■■■■■■■ (Variables)
Definition:
Variable is a name of Memory location that can store data. They are the containers for storing the data values. Every variable has a:
Data Type – The kind of data that it can hold. For example, int, string, float, char, etc.
Variable Name – To identify the variable uniquely within the scope.
Value – The data assigned to the variable.
There are three types of ■■■■■■■■■ (Variables):
Local
Instance
Static
Local Variable: A variable declared inside the body of the method is called local variable. We can use this variable only within that m
(Local Variable. ■■ ■■■■■■■ ■■■■■■■ 'static' ■■■■■■ ■■ ■■■ ■■■■■■■■ ■■■■ ■■■■ ■■ ■■■■ ■■, ■■■■ ■■■
Instance Variable: A variable declared inside the class but outside the body of the method, is called an instance variable. It is not dec
(Instance variables ■■ Class ■■■ declared ■■■ ■■■■ ■■■ ■■ ■■■■ ■■ ■■■■, ■■■■■, ■■ ■■■■■■■■■■■ ■■ body
Static variable: A variable that is declared as static is called a static variable. It cannot be local. You can create a single copy of the s
-------------------------------------
Java ■■■■■■ (Operators):
Java operators are special symbols that perform operations on variables or values. They can be classified into several categories ba
Example: Here, we are using + and – operators..
Types of ■■■■■■ (Operators) in Java
Arithmetic ■■■■■■ (Operators)
Unary ■■■■■■ (Operators)
Assignment Operator
Relational ■■■■■■ (Operators)
Logical ■■■■■■ (Operators)
Ternary Operator
Bitwise ■■■■■■ (Operators)
Shift ■■■■■■ (Operators)
instance of operator
1. Arithmetic ■■■■■■ (Operators)
Arithmetic ■■■■■■ (Operators) are used to perform simple arithmetic operations on primitive and non-primitive data types.
* Multiplication
/ Division
% Modulo
+ Addition
– Subtraction
2. Unary ■■■■■■ (Operators)
Unary ■■■■■■ (Operators) need only one operand. They are used to increment, decrement, or negate a value.
- Negates the value.
+ Indicates a positive value (automatically converts byte, char, or short to int).
++ Increments by 1.
Post-Increment: Uses value first, then increments.
Pre-Increment: Increments first, then uses value.
-- Decrements by 1.
Post-Decrement: Uses value first, then decrements.
Pre-Decrement: Decrements first, then uses value.
! Inverts a boolean value.
3. Assignment Operator
‘=’ Assignment operator is used to assign a value to any variable. It has right-to-left associativity. The general format of the assignme
Variable = value;
4. Relational ■■■■■■ (Operators) :
Relational ■■■■■■ (Operators) are used to check for relations like equality, greater than, and less than.
variable relation_operator value
Relational operators compare values and return boolean results:
== : Equal to.
!= : Not equal to.
< : Less than.
<= : Less than or equal to.
> : Greater than.
>= : Greater than or equal to.
5. Logical ■■■■■■ (Operators)
Logical ■■■■■■ (Operators) are used to perform “logical AND” and “logical OR” operations, similar to AND gate and OR gate in di
Conditional operators are:
&&: Logical AND: returns true when both conditions are true.
|| : Logical OR: returns true if at least one condition is true.
! : Logical NOT: returns true when a condition is false and vice-versa
6. Ternary operator
The Ternary Operator is a shorthand version of the if-else statement. It has three operands and hence the name Ternary. The gener
condition ? if true : if false
The above statement means that if the condition evaluates to true, then execute the statements after the ‘?’ else execute the stateme
7. Bitwise ■■■■■■ (Operators)
Bitwise ■■■■■■ (Operators) are used to perform the manipulation of individual bits of a number and with any of the integer types.
& (Bitwise AND) – returns bit-by-bit AND of input values.
| (Bitwise OR) – returns bit-by-bit OR of input values.
^ (Bitwise XOR) – returns bit-by-bit XOR of input values.
~ (Bitwise Complement) – inverts all bits (one’s complement).
8. Shift ■■■■■■ (Operators)
Shift ■■■■■■ (Operators) are used to shift the bits of a number left or right, thereby multiplying or dividing the number by two, resp
number shift_op number_of_places_to_shift;
<< (Left shift) – Shifts bits left, filling 0s (multiplies by a power of two).
>> (right shift) – Shifts bits right, filling 0s (divides by a power of two), with the leftmost bit depending on the sign.
>>> (Unsigned right shift) – Shifts bits right, filling 0s, with the leftmost bit always 0.
9. instanceof operator
The instance of operator is used for type checking. It can be used to test if an object is an instance of a class, a subclass, or an inter
object instance of class/subclass/interface
-------------------------------------------------------------------------------------
Precedence and Associativity of Java ■■■■■■ (Operators)
Precedence and associative rules are used when dealing with hybrid equations involving more than one type of operator. In such ca
---------------------------------------------------------------------------------------
Conversion in Assignments: Cast, Expressions.
Type conversion in Java :
Java provides various data types just like any other dynamic languages such as boolean, char, int, unsigned int, signed int, float, dou
There are two types of Type conversions in java:
Widening or Automatic Type Conversion
Widening conversion takes place when two data types are automatically converted. This happens when:
The two data types are compatible.
When we assign a value of a smaller data type to a bigger data type.
2. Narrowing or Explicit Conversion
If we want to assign a value of a larger data type to a smaller data type we perform explicit type casting or narrowing. This is useful
------------------------------------------------------
Java Expressions:
An expression is a group of variables, operators, and method, which are constructed according to the syntax of the language.
So, an expression is a combination of one or more operands, zero or more operators, and zero or more pairs of parentheses.
For example, int score; score = 90; Here, score = 90 is an expression that returns an int .
■■■■■■■■ ■■■ (Control Statements): Input characters from the Keyboard, if statement, Nested ifs, if-else-if ,Ladder, Switch Stat
■■■■■■■■ ■■■ (Control Statements):
Java compiler executes the code from top to bottom. The statements in the code are executed according to the order in which they a
Java provides three types of control flow statements.
Decision Making statements
if statements
switch statement
Loop statements
do while loop
while loop
for loop
for-each loop
Jump statements
break statement
continue statement
Decision Making statements
Decision-making statements decide which statement to execute and when. Decision-making statements evaluate the Boolean expre
1) If Statement:
The condition of the If statement gives a Boolean value, either true or false.
In Java, there are four types of if-statements given below.
Simple if statement: It evaluates a Boolean expression and enables the program to enter a block of code if the expression evaluates
If-else statement: The else block is executed if the condition of the if-block is evaluated as false.
If-else-if ladder: it is the chain of if-else statements that create a decision tree where the program may enter in the block of code whe
Nested if-statement: In nested if-statements, the if statement can contain a if or if-else statement inside another if or else-if statemen
Switch Statement:
Switch statements are similar to if-else-if statements. The switch statement contains multiple blocks of code called cases and a singl
Points to be noted about switch statement:
The case variables can be int, short, byte, char, or enumeration.
Default statement is executed when any of the case doesn't match the value of expression. It is optional.
Break statement terminates the switch block when the condition is satisfied.
It is optional, if not used, next case is executed.
While using switch statements, we must notice that the case expression will be of the same type as the variable. However, it will also
Loop Statements:
Loop statements are used to execute the set of instructions in a repeated order. The execution of the set of instructions depends upo
We have three types of loops that execute similarly. However, there are differences in their syntax and condition checking time.
for loop
while loop
do-while loop
For Loop :
For loop is similar to C and C++. It enables us to initialize the loop variable, check the condition, and increment/decrement in a single
Syntax:
for(initialization, condition, increment/decrement)
{
//block of statements
}
While loop:
While loop is also used to iterate over the number of statements multiple times. It is also known as the entry-controlled loop since the
Do while Loop :
The do-while loop checks the condition at the end of the loop after executing the loop statements. It is also known as the exit-control
Jump statements: Jumping statements are used to transfer the control of the program to the specific statements. In other words, jum
Break Statement:
The break statement is used to break the current flow of the program and transfer the control to the next statement outside a loop or
Continue Statement:
The continue statement doesn't break the loop, whereas, it skips the specific part of the loop and jumps to the next iteration of the lo
----------------------------------------------------------------------------------------------
Introduction to ■■■■■ (Classes), ■■■■■■■■■■ (Objects) and ■■■■■■ (Methods), Class Fundamentals, Reference ■■■■■■
Class:
A class in Java is a set of objects which shares common characteristics/ behaviour and common properties/ attributes. It is a user-de
Object:
An object is a real-word entity that has state and behaviour. In other words, an object is a tangible thing that can be touch and feel, li
Characteristics of an Object:
State: It represents the data (value) of an object.
Behaviour: It represents the behaviour (functionality) of an object such as deposit, withdraw, etc.
Identity: An object's identity is typically implemented via a unique ID.
Object Definitions:
An object is a real-world entity.
An object is a runtime entity.
The object is an entity which has state and behavior.
The object is an instance of a class.
Reference variable:
A reference variable is one that refers to the address of another variable. It represents the name of another variable, location, or valu
Benefits and Usage of Reference ■■■■■■■■■ (Variables)
Reference variables offer several benefits and play a crucial role in Java programming:
Object Manipulation:
Reference variables allow programmers to work with objects, access their properties, and invoke their methods.
Memory Efficiency:
Reference variables only store the memory address of an object rather than the entire object itself.
Object Passing:
Reference variables are often used when passing objects as arguments to methods or returning objects from methods.
Dynamic Behaviour:
Reference variables enable dynamic behaviour in Java programs.
Object Lifetime Control:
Using reference variables, developers can control the lifetime of objects dynamically.
■■■■■■ (Methods) in Java:
A method in Java is a block of code that, when called, performs specific actions mentioned in it. For instance, if you have written inst

You might also like