Java Notes
Java Notes
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
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 .
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
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
= , -= , += /= ,%= , //= ,
7.bitwise operations :
VARIABLES :
variables are names that holds a data . it crucial in execution of program
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.
****in java total keywords are 50 . and goto and const are used for future use****
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
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():
p.add(Integer.valueof(22)); ----boxing
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);