JAVA NOTES
JAVA NOTES
android-kotlin
ios-swift
microsoft-c&.net>>>>RUST>>>>c,c++,java.
OS,Processor,hdd/ssd,ram+cpu
#java has garbage collector(if something that is within the storage area is
not required will be removed)
[Editors]
Ms-word,notepad,editplus,sublimetext,vs-code,jdk(it consist of
several tools like jvm,jre,classloades,compailers,interpretors.
(Editors+jdk) Eclipse,Netbeans,intellij
JDK
|---------------------------------|
JVM JRE
*CL
*Compailer
*Interpretor
*Libraries
*Memory area
#Structure of java
Class demo
declaration stmt-----|*variable
*constructor
*method
initialization-------|*static
*non-static
#Print statements
class Demo{
system.out.println("hello world")
system.out.print("HIIIII...)
system.out.print()
#Tokens
Conventions
i)classi
*PascalCase
*snake_case
*camelCase
*Number-integer,decimal
*Character-'a','b','c','2','@','?','/'.
*Arithmaic- +,-,*,/.
*Logical
*assignment
*relational
*compund assignment
5)Separators- . , { [ ( ) ] } /
*single line
*multi line
*documentation
#Datatypes
| |
-Decimal----->*float *double
-Character--->*char
-String------>*String
-Boolean----->*boolean
_____________________________________________________________________________________
__________________
_____________________________________________________________________________________
___________________
#Number system
*binary-()2 -(0,1)
*decimal-()10-(0-9)
*octal-()8-(0-7)
*hexadecimal-()16-(0-9,a-f)
1byte=8bits
2'(n-1)=2'8-1=128 min
2'(n-1)-1=2'7-1= max
#Variables.
creating a variable
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:
2)To read or fetch the data from the variable we need yo use the name of
the variable
age=20;----->initialization statement
age = age+1
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:
#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
*Each symbols performs some specific functionality just like key words.
*Purpose of operator
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
eg:
Int to Long
` Long to Int(shows mismatch error)
System.out.println(res);
· Associativity(direction of execution)
-simple addition
-string concatination
String concatinaton
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
>
<
>=
<=
==
!=
Logical Operator
(&&-AND ||-OR)-BINARY !-NOT-UNARY
Type:
Returntype:boolean
----------------------------------------------
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
Syntax:
!(OPERAND_1>OPERAND_2)
TRUTH TABLE
AX
10
01
Example:
int a=10;
int b=20;
Sopln(!(a>b));
output:
true..
Keywords:
Increment Operator:
DENOTED BY [++]
Typecasting Operator:
PRIMITIVE TYPECASTING:
WIDENING:
byte(1)<short(2)<int(4)<long(8)<float(4)<double(8)
Narrowing:
*initialization
*condition
*updation
do while:
do
{
..............
............
int i=1;
do
sopln(i);
}while(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
while dowhile
int n=1234;
int ld=n%10;
int n=1234
int n2=n/10
sopln("h
For loop:
for(initialization;condition;updation)
......................................
......................................
eg:
for(char ch='a';ch<='z';ch++)
Sopln(ch):
}
a a<=z a a
b b<z b b
c c<=z c c
z z<=z z z
1 1<=5 * 1
2 2<=5 * 2
3 3<=5 * 3
4 4<=5 * 4
5 5<=5 * 5
----------------------------------------------------------------------------------------------
Methods:
synta x:
[return statement:]
................
Modifiers:
*keywords
*access modifiers-public,protected,default,private.
Buzz number:
Rules of return:
*if return type is anything other than void return statement is mandatory
1.Write a java program for calculating the area of a circle using method.
Built-in class:
Scanner class