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

Java Notes

Uploaded by

tejavitap
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Java Notes

Uploaded by

tejavitap
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

------------------------java -------------------

Comments In java are three types


1.single line comments ---- by //
2.multiline comments ------ by /* */ is only see inside a code only
3.documentry comments ------by /** */ Is mostly used instead multiline
comments because it shows to both user and developer in the form of document in
HTML

PACKAGES:
package is namespace that organizes set of class and interfaces. packages are
help to avoid name conflicts(godavalu)
java have some default packages java.Until , java.io ,java.lang --it contain
some class

data types :
This are two types 1.primitive and 2.non-primitive(also called reference)
1.primitive:
IT stores a single value and do not provide a special capability
you known java is object oriented program(OOPs) and s for system . but not .
java is not pure oops because primitive . it not pure oops.
Again it are types :
int Boolean float double char short byte long
in these byte and Boolean have 8 bits (1 byte)
short and char have 16 bits (2 bytes) -------------- this is imp
question is why char has 2 bytes in java but other language has only one byte .
ANSWER .other languages have ASCII - American standard code for international
interchange . it means it have only English characters and some special characters
and 0- 9 numbers . but in java follows Unicode system . it stores more than many
languages .
int and long have 32 bits ( 3 bytes ) ------
float and double have 64 bits (4 bytes)-----mostly double is used
because it stores more floating point than float

2.NON-primitive data types:


They are used to store a complex types of data
it have Strings , class , objects , arrays , interface

it has certain memory address because it wont store variable value into
a memory
*IMP point is basically static keyword not used for constants and in java
constants are denoted by final keyword .

-----------Memory allotment in java -----

**IMP points : Objects are stored memory in heap memory


methods call , local variables and primitive are stored in
stack memory : -- each method has creates a each stack frame memory . when the
method is completed stack frame is removed
let me explain in simple terms . it is based in LIFO(last in,
first one)--example : a stack of plates in kitchen if you take a plate which plate
you take absolutely you take first one and which one you take away . this also
first one . that at this will be happened
when you use a static keyword it all store in a method area . it all are in a
one block . whereas , in heap memory each object has each block
identifiers :
Identifiers are names used to represent a variables , functions , methods
etc.
ex: int age;
names containers only [a- z] ,[A - Z], [0-9] and underscore(_) and $
only and not begin with numbers
variables:
variables are used to store a data;
ex: int age = 17;

simply when you not give data we called it has identifier and when you assign data
is called as variable

OPERATERS :
operators are special symbols used to perform a operations to a variables
and variables . There are
1.arthmatic operations: it is used to perform mathematical operations between
variables .
+ , - , / , * , %
2.unary operations: it i
++ --increment . ex: if x = 4 ; then x++ is means x = x + 1; first 4
and second 1 is added ; then answer is 5

ex: if x = 4 ; then ++x is means first one is added


then 4 is added ; then answer is 5

-- ----decrement . ex : if x = 6 ; then x-- is means temp = x ; x = x -1 ;


result temp ; first 6 and second 1 is minus ; then answer is 5
ex : if x = 6 ; then --x is means x = x -1 ; first i
one minus then decrease 6 ; then answer is 5

--------- both answers must be equal-----------

unary minus (-) : it is convert + to - vice verse

not operant(!):
it convert true to false vice verse
bitwise operant(~): it convert 1 to 0 and vice verse in binary system
. simply we use the formula is x = -( x + 1 ) . **IMP is unary operant is more
faster than others

3. Assignment operation : it is used to assign a value to a variable

= , -= , += /= ,%= , //= ,

4.logical operations : it is used to perform a logical gates


AND(&&) : it is used by the condition is true when both value
are true
OR(||) : it is used by the condition is true when only one
value is true
NOT(!) : AND(&&) : it converts true value into false and vice
verse
5.relation operations: it is used to check whether both values are equal or not
==,!= ,<,>,<=,=>,
6.Terminary operations : it is short cut of if conditions (conditional
statements). it has a structure variable = condition ? true : false.

7.bitwise operations :

it is perform in binary level . but we have some formulas for this.


~ is already knew
<< has x = x * (2^n)
>> has x = x / (2^n)
***IMP are what is Expression in java? :::: An expression in java is a
combination of operators and operands that is used to perform mathematical or
logical calculations. In simple words, it is a combination of variables, constants,
and operators.

VARIABLES :
variables are names that holds a data . it crucial in execution of program

variables are three types


1.local variables :
A variable can be defined within a block or method or
constructer . it has must be assign a value to a this and java cant assign default
value. it stored in stack memory

2. instance variable : it is non static variable defined in class but


outside any method , constructer or block. instance variables are created when a
object is created only
it is defined within a class . it has java provide default value
to that variable if not assign a value . like for String = null ; int = 0 ; etc..
,,
it is exit as object exist.it stored data in heap memory

3.static variable :
it is declared in within a class and access by using its
className.variable in anywhere in a program. because it stores a data separately in
method area.

ERROR ARE TWO TYPES 1. complier error And 2.runtime error


1.complier error :
Occurs when
incorrect syntax ,not declared class name , not assign value to
local variables , missing return , type convention
2.RINTIME error: occurs when divide by zero , null pointers

****in java total keywords are 50 . and goto and const are used for future use****

---ACCESS MODIFIERS OR ACCESS PACIFIERS OR ACCESSIBILTY MODIFIERS-------


DEFINATION: it defines a scope/visibility of a members of a class (methods ,
constructer , variables)
there are four access modifiers are their which are, public , private , protected ,
default(no modifier)(private-package).

1.public: it used anywhere in the program like same class or other class and
same package or other package
2.private:it can be used in only same class only and even don't use in subclass
also(inheritance)
3.defalut : it can be used in anywhere in the same package and also subclasses
also but in the same package
4.protected : it can be used in anywhere in the same package and subclasses
(even the subclass is in other package)

WRAPER CLASSES :
in java that provide a way to convert primitive data types into objects and this
wrapper classes are in the java.lang package
and in collections like arraylist and hasmaps like that means do you array .
it stores a objects not primitive types. so that , wrapper classes used to converts
primitive types into objects and in wrapper classes have type conversions
string to int by using Interger.parseint()
**in primitive types cant hold null values but it is possible in wrapper
class
how to use is
first we have primitive type === int x = 5
convert that into like this === Integer varible_name =
Interger.parseint(5);

wrapper classes have not a (parameter less ) is not working --default constructer
is not working in wrapper classes working in normal classes

it has 4 types
1.boxing: --wrapper means to wrap a data let me explain if you buy a phone for
gifting to your friend . you absolutely wrap a gift cover to that then gift it.
like that wrapper class wrap a primitive data in wrapper class

if you store a primitive data in wrapper class , like this


ex: int x = 20;

lets create a object = > Integer ex = Interger.valueof(x) ----- it is boxing

2.Auto- Boxing:
if you directly assign like this
Integer ex = x; ---it is called Auto-Boxing >> java internally change it

3.unboxing:
it is opposite of boxing : you can take a primitive data to a wrapper class
is called unboxing---let see some examples
ex: int y = x.intvalue() --like this --it is called unboxing

4.Auto-unboxing :
if you directly taken value
ex : int y = x;
in arrays like this :
lets create a object
ex: arraylist<Integer> p1 = new arraylist():

then add data to arraylist like this


p1.add(24); --- auto - boxing
p.add(25); ----

p.add(Integer.valueof(22)); ----boxing

if you take data like this in a array


int z = p1.get(0); ---unboxing

----INPUT TAKING FROM USER ------


we have two ways to take input from user
1.scanner class
2.bufferedReader class
for now we learn only scanner class
SCANNER CLASS:
it is used to read user input from keyboard(console) from other sources
like file ---its definition of this

how to use is -- Scanner varibleName = new Scanner(System.in);


creates a object that stores a user input in it and it is not faster as
the bufferedReader class and bufferedRead class read more data then scanner.
System.in -- it is way of taking input (raw way (just bytes)) -- it like a
microphone it sends to java by what user type

Scanner is used to read all data by line wise and divides into tokens . tokens
are small elements have some meaning to a complier . for example : how are you =>
'how' 'are' 'you'

parse means a problem or something breakdown into small parts -- taking a piece of
data and breakdown into useful format
***System is class in java that provide a access to important thing like input
and output
***out is tool inside a system that helps to send messages to console
----in java also we use not always but know it is also exist which is
PrintStream class >> this also print to console window
>>> by using syntax >>> PrintStream stream = new
PrintStream(System.out);

format print types -- by using "printf" - f means format


ex : %d -- integer
%s -- string
%f -- float
%n -- new line
if you use %D it gives result with capitale letters
ex: is int age = 15;
name = teja;

System.out.printf("Hello %d you are %d old",name,age)----//output is


Hello teja you are 15 old

-------------------DISION MAKINGS IN JAVA ----------------------------


1.if-statement:
it is most common discussion making program in java . it check whether
a condition is true then the block of code is execute and otherwise not
syntax used is :
if(condition){
//statement
print("true")
}

You might also like