0% found this document useful (0 votes)
19 views

Java Introduction

Uploaded by

Binod Yadav
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)
19 views

Java Introduction

Uploaded by

Binod Yadav
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/ 6

First Java Program

Thursday, July 13, 2023


7:41 PM

JAVA program:
Program:
Set of instructions.
Class :Class is collection object.
-Java Is case sensitive.
-Keyword: These reserved words.
-These they are having own meaning, you can not use.

Syntax:
class class_name
{// start of class

}//end of class

class Demo
{
//body of class
}
*************************************************************
Symbols:
{ } :---It indicates scope of block
( ):- It indicate method.
[ ] :- It indicated array.
, - to separate variable.(seperator)
. -To access properties inside a class with the help of object.
; -It indicates end of statement.(terminator)
*************************************************************
Naming convention:
1.class name always starts with capital letter.
DemoProgram,Demo_Program,
2.Variables should be written in lowercase
3.method name should be written in camelcase.
firstName()
4.constant always write in upper case.
ID

Method:
void :nothing
return_type method_name (parameters,parameters)
{

Java-14-7 Page 1
{
// body of method

********************************************************
Parameters Explanations:
1.Class: It is keyword which is used to declare a class in java.
2.public: It is keyword which is used to show visibility to all, accessibility by all.
3.static:It is a keyword. There is no need to create an object of a class. The main method is
executed by the JVM no need to create object.
4.void:It indicates return type of method. It means it doesn't return any value.
5.main:method name which represents starting point of the program.
6.String args[]:It is parameter accepted by main method.
7.System.:It is predefined class in java.
8.out:object to call println().
9.println() :This method is used to print the output and moves cursor to next line.
10.print() :This method is used to print the output but cursor will stay on same line.
*************************************************************
Variable:
What is variable?

-Variable is a container which contains/stores value .


-Varible means whose value can varies.
-Varible value is not fixed it can change.
-A variable can strore only one value.
• Variable Declaration:
data_type variable_name ;
int x;
• variable declaration with intialization:
Data_type variable_name =initial_value;
int x=4;

Assignment:
1.Write a program to find area of Rectangle.
2.Write a program to calculate percentage of student.(6 subjects).
3.Write a program to find area cylinder.
4.Write a program to find total salary of employee per annum .
5.write a program to perform multiplication, division of 2 numbers.

Data types in java:


1.primitive data types :int,float,double,char
-basic data types.

Java-14-7 Page 2
-basic data types.
-java is a statically-typed programming languge.
-All variables must be declared before they use.
2.non-primitive data types:Classes,Arrays,String

Data type Default size


boolean 1 bit
char 2 byte
byte 1 byte
short 2 byte
int 4 bytes
long 8 bytes
float 4 byte
double 8 bytes

** float :3.4f
** double:3.4
** long :9097865343l
=================================================================================
======
Operators in Java:
These are the symbols that is used to perform operations.
They are many types:
1.Unary operator:
2.Arithmetic Operator
3.Shift Operator
4.Relational Operator
5.Bitwise operator
6.Logical Operator
7.Ternary operator
8.Assignment Operator.

** Unary Operator:
This operator it used single operand.
Types:
1.Increment--------------increase value by one
a. prefix increment operator:
syntax: ++x;
-increment value in memory then use
b. postfix increment operator:
syntax: x++;
-Use first then increment in memory.

2.Decrement------------decrease value by one.


1.prefix:
Syntax: --x
Java-14-7 Page 3
Syntax: --x
decrease first then use
2.postfix:
Syntax: x--
Use first then decrease.

3) ! :-You can use this operator with boolean data type.


Boolean b=false;
!b=true;
-this operator returns opposite value.

2.Java Arithmetic Operators:


Arithemetic operators are used to perform basic arithmetic operation.
Addition(+);
Substraction(-)
Multiplication(*)
Division(/)
Modulus(%)
Operartor precendence: multiplicative: [* / %]
Additive:[+ -]

3.Shift Operators:
1.left shift: (<<)
- In java left shift operator is used to shift all of the bits in a values to the left side of specified
number of times.
-Embedded system.
-Internally they works on binary values.
-Digital logic.

Decimal--binary--decimal

-Example : (14<<4) :14 left shift by 4


-14 *2 ^4

(15<<3)
-15 *2 ^3

2.right shift:(>>)
It used to move bits to the right side by the number of bits specified.
(10>>2)
-10/2^2

3.Relational Operators:
-These operator are used to compare between operands and returns boolean value as a result.

Java-14-7 Page 4
-These operator are used to compare between operands and returns boolean value as a result.
-Mainly these operator are used in control statement.

>
<
<=
>=
== :Equality
!

4.Logical Operators:
1.AND (&&)
2.OR(||):-----similar +
-AND(&&)-----similar
This operator returns true as *. if either of condition is true .
This
It will operator
returnsreturns
false iftrue
bothif the
onlyconditions
both conditions are true.
are false.
If
True any:1condition is false it will return false.
and False:0
-True(1) and false (0)
condition1
Condition1 conditioncondition ResulResult
TT (1) TT (1) TT(1*1)
T(1)
T F F(0) TF(1*0)
FF TT TF
FF FF FF

3.Logical Not(!):Opposite value


False=true
True=false

4.XOR (^):
This operator returns true if either statements one is true or statement two is true but not
both.
Condition1 condition2 Resul
T T F
T F T
F T T
F F F

Bitwise Operators:
1.Bitwise AND (&):
condition1 condition Resul
1T 1 T 1

Java-14-7 Page 5
1 T 0 F 0
0 F 1 T 0
0 F 0F 0

2.Bitwise OR (|) :
Condition1 condition Resul
T T T
T F T
F T T
F F F

**Difference between logical and bitwise AND:


&& :If first condition is false then it will check not second condition.
If first condition is true then it will check second condition.

&: If first condition is either true or false it will always check for second condition.

Java-14-7 Page 6

You might also like