Java Section-I
Java Section-I
1. Variable
2. Data types
3. Methods
4. Control Statements
5. Loops
6. Types of Variables
7. Constructor
8. Keywords & Identifiers
===================================================================================
=========================================================================
1. Variables:
Variables:-
Variables are nothing but piece of memory used to store information. One variable
can store 1 information at a time.
**Note: -
According to all programming language dealing with information directly is not a
good practice to overcome this variables are introduced.
===================================================================================
==========================================================================
2. Data types
Data Types:-
Data type are used to represent type of data or information which we are going to
use in our java program.
1. (Numeric + Non-decimal):-
Ex: 80,85,10,23,56,74..etc
-----------------------------------------------------------------------------------
---------------------------------------------------------------
Data Type | Size | Description
-----------------------------------------------------------------------------------
---------------------------------------------------------------
1. byte | 1 byte | Stores whole numbers from
-128 to 127
-----------------------------------------------------------------------------------
---------------------------------------------------------------
2. short | 2 bytes | Stores whole numbers from -
32,768 to 32,767
-----------------------------------------------------------------------------------
---------------------------------------------------------------
3. int | 4 bytes | Stores whole numbers from -
2,147,483,648 to 2,147,483,647
-----------------------------------------------------------------------------------
---------------------------------------------------------------
4. long | 8 bytes | Stores whole numbers from -
9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
-----------------------------------------------------------------------------------
---------------------------------------------------------------
2. (Numeric + decimal):-
Ex: 22.5,22.8,6.4....
-----------------------------------------------
Data Type | Size |
-----------------------------------------------
5. float | 4 byte |
-----------------------------------------------
6. double | 8 bytes |
-----------------------------------------------
3.Character:-
-----------------------------------------------
Data Type | Size |
-----------------------------------------------
7. char | 2 byte |
-----------------------------------------------
4.Conditional:-
-----------------------------------------------
Data Type | Size |
-----------------------------------------------
8. boolean | 1 bit |
-----------------------------------------------
2. Non-primitive datatype:-
===================================================================================
========================================================================
2. Methods:-
A method is a block of code which only runs when it is called.
Methods are used to perform certain actions, and they are also known as
functions.
1. Main method****:
In any Java program, the main() method is the starting point from where compiler
starts program execution.
Without main method we can't run any java program.
2. Regular method
**Note:-
At the time of program execution, priority is scheduled for main method only.
At the time of program execution, main method is executed automatically, whereas
regular methods are not executed automatically.
To execute regular methods,We need to call regular methods from the main method
Regular methods can be called multiple times.
===================================================================================
==========================================================================
4. Control Statements:
1. if
2. if else
3. else if
4. nested if
5. switch
1. if:
if(conditon)
{
}
-------------------------------------------------------
2. if else:
if (condition)
{
}
else
{
}
-------------------------------------------------------
3. else if:
if (condition)
{
}
else if (condition)
{
}
else if (condition)
{
}
else
{
}
-------------------------------------------------------
4. nested if:
if (condition)
{
if (condition)
{
}
else
{
}
}
else
{
}
-------------------------------------------------------
5. Switch:
switch (key)
{
case value: break;
default:break;
}
===================================================================================
==========================================================================
5. Loops
1. for loop
2. while
3. do while
4. for each loop
1.for loop:
while (condition)
{
SOP (“ ”);
i++;
}
-------------------------------------------------------
3. do while loop:
do
{
SOP(“ ”);
i++;
}
while (condition);
===================================================================================
==========================================================================
6. Types of variable:
1. local variable:
2. global variable:
a. class/static variable:
b. Instance/non-static variable:
===================================================================================
==========================================================================
7. Constructor:
Use of Constructor:
Types of Constructor:
1. Default Constructor
2. User defined Constructor
1. Default Constructor:
If Constructor is not declared in java class, then at the time of
compilation, compiler will provide Constructor for the class and such constructor
is known as default Constructor
If programmer has declared the constructor in the class then compiler will
not provide default Constructor.
The Constructor provided by compiler at the time of compilation is known as
Default Constructor
===================================================================================
==========================================================================