java
#java is a programing language.
#its a high level language.
android-kotlin
ios-swift
microsoft-c&.net>>>>RUST>>>>c,c++,java.
#java is a object oriented programming language.
Object-creating place to convert real world entity into virtual world
entity(virtual representation of a real world entity)
eg:separate containers in kitchen.
#java is platform independent(eg: instagram is working in all phones
perfectly)
OS,Processor,hdd/ssd,ram+cpu
file in which we write the code is source file. CPU
ARCHETECTURE:34BIT,64BIT...
source code(java)>>Bytecode(class file)[not high level..its inbetween
some kind of code$%+hell-]
Because of bytecode java is platform independent.
all of languages like c,fortran,cobol,vb,pascal is procedural oriented(top to
bottom rule)
#java is secured language(i dont need to give my source code bytecode is
enough to give someone else).
whenever we try to execute source file in different platform we need to
execute the class file.
#java is a multi-threaded language(thread-task)eg:like share comment
while video is playing.
#java has garbage collector(if something that is within the storage area is
not required will be removed)
*its a feature of java(software)..which helps in clearing out the old
memory or waste memory.
#How to write a java program:
1.we need software "Editors"
[Editors]
Ms-word,notepad,editplus,sublimetext,vs-code,jdk(it consist of
several tools like jvm,jre,classloades,compailers,interpretors.
[Ide]-Intergrated development environment
(Editors+jdk) Eclipse,Netbeans,intellij
compiler- 1) check syntax & scemantics(converts over all at one time)
2) generate class file
Interpretor-1) Bytecode-->Binary (converts line by line)
#How to execute java program
1. Javac srcFileName.java-purpose of this command is to compile the
code check the syntax and scemantic and generate the class file
2. java classfilename-purpose of this command is to execute java
class file.
JDK
|---------------------------------|
JVM JRE
Java virtual machine Java runtime
environment
*CL
*Compailer
*Interpretor
*Libraries
*Memory area
#Structure of java
Class demo
declaration stmt-----|*variable
*constructor
*method
initialization-------|*static
*non-static
ENUMs/Class declaration statement
#Print statements
*system.out.println("2024")-prints word by word and if there is no
more char the cursor will move to next new line(ln).
*system.out.print("2024")-cursor wont move to next line.{empty print
statement will give error}
Java program:
class Demo{
public static void main(string[]args)
system.out.println("hello world")
system.out.print("HIIIII...)
system.out.print()
#Tokens
· Smallest unit-smallest building blocks of any language to make the
code meaningfull.
1)Keywords-Reserved words 50+ predefined which has specific
functionality to it,all has to be lowercase
2)Identifiers-Names given to the components of java
Rules for identifiers:
*cant use keywords
*cant start with numbers
*Special characters_$ allowed
Conventions
· Conventions are the practices from long time
i)classi
*PascalCase
*snake_case
*camelCase
3)Literals-the data which is encoded by the programmer in the
code is known as literals
Types of literals
*Number-integer,decimal
*Character-'a','b','c','2','@','?','/'.
-length of a character literal is always one
-character literal must be enclosed within single quotes('')
*String-string literals are used to represent the group of
characters
-length of a string character can range between 0 and
infinity.
-string literals must enclosed within double
quotes("karupusami")..("a","b","1"....)
*Boolean-we only have 2 types of boolean literals true and
false..true and false are also keywords related to boolean type.
4)Operators-operators are used to manipulate the literals. |
CRUD-*Create,*read,*update,*delete/remove
-operators are pre defined symbols just like keywords.
*Arithmaic- +,-,*,/.
*Logical
*assignment
*relational
*compund assignment
*increment and decrement
5)Separators- . , { [ ( ) ] } /
6)Comments are used for book mark
*single line
*multi line
*documentation
#Datatypes
· To represent different type of data we have datatypes
-Data--->raw facts about real world entity.
Two types of data and non primitive data type in java
Primitive datatypes non-primitive datatypes
| |
data stored in single multiple memory blockcell
memory block cell eg: class,array,string
PRIMITIVE DATATYPES- 8 TYPES
-Integer----->*byte *short *int *long
-Decimal----->*float *double
-Character--->*char
-String------>*String
-Boolean----->*boolean
datatype| literal | size |default values| Range
byte 1byte 0 -123 to 127
short integer 2byte 0 -32768 to 32757
int 4byte 0 -2147483648 to 2147483647
long 8byte 0 -9223372036854775808 to
9223372036854775807
_____________________________________________________________________________________
__________________
float decimal 4byte 0.0f/0.0F 1.4E-45 to 3.4028235E38
double 8byte 0.0d/0.DD 4.9E-324 to
1.7976931348623157E308
_____________________________________________________________________________________
___________________
char character 2byte \u0000 to ?-actual value......0 to
65535-unicode value
boolean boolean 1bit false doesnt have max value and
min value
#Number system
*binary-()2 -(0,1)
*decimal-()10-(0-9)
*octal-()8-(0-7)
*hexadecimal-()16-(0-9,a-f)
1byte=8bits
start filling byte frm right to left....00001111 this is how stored in
memory..computer uses this we are using 15
manual range finding of byte.
2'(n-1)=2'8-1=128 min
2'(n-1)-1=2'7-1= max
ascii-65(0 to 255) value-'A' 0-nul------------->char
#Variables.
* Veriables are named block of memory.
creating a variable
*variable acts like a container for the data or literals.
*depending upon the type of data we create the variables.
syntax for variables
datatype identifier.
eg: string name="jana";||variable declaration statement
int age=21;
all the rules of identifier applies here but we follow snake case
Characteristics of variable:
1)all the variables have name..datatypes and identifier
2)To read or fetch the data from the variable we need yo use the name of
the variable
int age;---->variable declaration statement
age=20;----->initialization statement
3)the data stored inside the variable is always temporary.
4)we can update the value assigned to the veriabke.
age = age+1
5)every variable have scope
6)every variable has lifetime
Types of variables:
variables
|-----------------------------|
primitive non-primitive
*static *static
*non-static *non-static
1)primitive variable:
the variables which are used to store primitive type of data are called as
primitive datatype
2)non-primitive variables:
non-primitive variables are also called as referance variables
non-primitive variables are used to store the referance of an object or
address of a memory block
#Local variable
· The variables which are declared in anyother block but class block is
called as local variable
. CASE 2
CASE 1
CASE 5
CASE 3
CASE 4
#Operators
*Operators are predefined symbols.
*Each symbols performs some specific functionality just like key words.
*Purpose of operator
Operators are going to perform operations.
Operators are used to manipulate the data.
*Operators need operands to perform any action or operation.
*After performing the operation operators returns value and type of
value.
Characteristics of Operators:
· Every operators return the value and also the type of value after
performing the operation
Note:
Its the job of the programmer to consume the data which is returned by
the operator.Either by storing it in a variable or by
simply displaying it on output console
we cant convert long to int ..but int to long is possible.
eg:
Int to Long
` Long to Int(shows mismatch error)
· Precedence- gives me the order of operation
when we have a complex expression(more than 1 operators in the
statement)the priority given to the operators is aclled as precedense
this precedence gives order of execution.
eg: int res = 10+5*10-1/5;
System.out.println(res);
output: 60 *Java is a strictly typed
language
because the division operation is returning 0
· Associativity(direction of execution)
when we have a complex expression and all the operators are
having the same precedense then associatiLvty gives as the direction of
execution.
eg: right to left , left to right
Arithmetic operators
*arithmetic operators are used to perform arithmetic operations.
*arithmetic operators are binary in nature.
*Addition operator is polymorphic in nature
-simple addition
-string concatination
String concatinaton
1.if anyone datatype or both are of string type,then string concatination
operation will be performed.
eg: sopln(10+20); //30
sopln(10+"hello"); //10hello
sopln("java"+20); //java20
sopln("result:"+10+20); //result:30
sopln(10+30+"result:"+(20+30)); //40result: 50
Relational Operator
type: binary
returntype: boolean
>
<
>=
<=
==
!=
1)Relationa..l operators are used to check the relationship between the
two operands.
2)Relational operators are binary operators.
3)The return type of relational operator is boolean.
Logical Operator
(&&-AND ||-OR)-BINARY !-NOT-UNARY
Type:
Returntype:boolean
----------------------------------------------
Logical AND operator
If the first condition fails..jvm is not going to check second condition.
int a=10;
int b=20;
System.out.println(a>b&&b>a);
A B X
0 0 0
1 0 0
0 1 0
1 1 1
example 2
Output
false
Logical OR Operator
syntax:
OPERAND_1 || OPERAND_2
TRUTH TABLE
A BX
0 00
1 01
0 11
1 11
output: False.
Note: If first condition is true then jvm will not judge the second condition
Logical NOT Operator:
Syntax:
!(OPERAND_1>OPERAND_2)
TRUTH TABLE
AX
10
01
Example:
int a=10;
int b=20;
Sopln(!(a>b));
output:
true..
Keywords:
*Abstract *enum *public
*Assert *expost *required
*Boolean *extends *return
*break *final *short
*byte *binary *static
*catch *float *super
*char *for *switch
*class *it *synchronised
*continue *implements *this
*constant *impost *throw
*default *insaneof *transistent
*do *new *throws
*double *package *try
*else *protected *void
Increment Operator:
two types- postfix,prefix
DENOTED BY [++]
post-fix(a++)-first use ,then update
pre-fix(++a)-first update,then use
in case of a=a+1 we need to create memory space.
in case of a++ we dont need to create space.
· Its a unary operator
· Increment operator increment is a value by one only
Decrement Operator:
*Does the same by decretion.
Compound Assignment Operator:
Typecasting Operator:
Converting data from one type to another type.
PRIMITIVE TYPECASTING:
WIDENING:
byte(1)<short(2)<int(4)<long(8)<float(4)<double(8)
Narrowing:
NOTE:All the number literals are by default is of int type.
all the decimal lietrals are by default double in type.
Every loop have 3 process
*initialization
*condition
*updation
do while:
do
{
..............
............
}while(condition)- even if this condition is false the statement inside loop
will be executed atleast once
int i=1;
do
sopln(i);
i++; //first use then update
}while(i<=5);
i sopln(i) i++ i<=5
1 1 1 2<=5 t
2 2 2 3<=5 t
3 3 3 4<=5 t
4 4 4 5<=5 t
5 5 5 6<=5 f
· do is a keyword which is used to start a dowhile loop.
· its a exit point loop
while dowhile
*before entering loop condition is satisfied *condition cheaked
after iteration
*minimum number of iteration 0 *atleast one or
minimum one
to find last digit.
int n=1234;
int ld=n%10;
sopln("the last digit is:"+ld);
to remove last digit.
int n=1234
int n2=n/10
sopln("h
write a java program to find the product of individual digits.
spy number-a number in which the sum of individual digits is equal to
product of individual digits.
For loop:
for(initialization;condition;updation)
......................................
......................................
· Entry point loop.
· when we know how many iteration is going to happen.
· 3 process are in single statement outside the loop.
· for is a keyword which is used to start the for looping statement.
· aminimum number o iteration is zero and its enyry point loop
eg:
for(char ch='a';ch<='z';ch++)
Sopln(ch):
}
ch ch<='z' sopln(ch) ch++
a a<=z a a
b b<z b b
c c<=z c c
z z<=z z z
Nested looping statements.
i i<=5 j j<=5 sopln(*) j++ sopln() i++
1 1<=5 * 1
2 2<=5 * 2
3 3<=5 * 3
4 4<=5 * 4
5 5<=5 * 5
----------------------------------------------------------------------------------------------
Methods:
eg: Login Pages.
*Methods acts like a container..to store action oblique task oblique
behaviror
*Method is a block of instructons which is used to perform a specific task
synta x:
[modifier] returntype name [Datatype varib1,datatype varib2]-variables
declared inside is formal arguments.
[return statement:]
................
*Method signature-method name along with formal arguments its called
as method signature.
*Method declaration-method signature along with modifiers and return
type is called as method declaration.
*Method definiton-method declaration along with method body is called as
method definition
*Formal arguments-the variables which are declared in method declaration
statement are called as formal arguments
Modifiers:
*keywords
*modifies behaviours of components of
java-variables,methods,class/intervals/records/enums
*access modifiers-public,protected,default,private.
*non access modifiers-static,abstract,final,native,volatile.
Buzz number:
last digit should be 7 or completel
public state int add()
Rules of return:
*Return statement should be the last statement in the method body
*if return type is anything other than void return statement is mandatory
*if return type is void then return statement is not mandatory
Rules of type casting also applies here.
1.Write a java program for calculating the area of a circle using method.
2.write a java program to convert inr into us dollers using methods.
3.write a java program to covert an angle from degree to radians.
Built-in class:
Scanner class
fully qualified name.java.util.scanner