Header Ads

test

IMPORTANT CONCEPT OF JAVA PART-3

 Importans points

------------------




Interfaces-

-------------

1-The interface is highlighting set of functionalities but implementations are hiding.

2.For the interfaces also compiler will generates .class files after compilation.


3-Inside the source file it is possible to declare any number of interfaces. And we are declaring the interfaces by using interface keyword.

Syntax:- Interface interface-name

interface It1

{ *****

}




Note: - If we are declaring or not each and every interface method by default public abstract.



4-Interface constrains abstract methods and by default these methods are “public abstract “.

5-Interface contains abstract method for these methods provide the implementation in the implementation classes.


6- Implementation class is nothing but the class which implements particular interface.


7-While providing implementation of interface methods that implementation methods must be public methods otherwise compiler generate error message “attempting to assign weaker access privileges”.

interface


8-Interface contains abstract method for these methods provide the implementation in the implementation class.


9- If the implementation class is unable to provide the implementation of all abstract methods then declare implementation class with abstract modifier & complete the remaining abstract method implementation in next created child classes.


10-If the child class also unable to provide implementation then declare the child class with abstract modifier & take one more child class to complete the implementations.



11- In java it is possible to take any number of child classes but at final complete the implementation of all abstract methods



String

----------

1-String is used to represent group of characters or character array enclosed with in the double quotes.


2-String & StringBuffer both classes are final classes present in java.lang package.


3-We are able to create String object in two ways.

1) Without using new operator String str="sweta"

2) By using new operator   String str=new String("sds");




We are able to create StringBuffer object only one approach by using new operator.

StringBuffer sb = new StringBuffer(“hello");



Note-

--------


1-When we create String object without using new operator the objects are created in SCP (String constant pool) area.

2-Whenever we are creating String object by using new operator the object created in heap area.


----When we create object without using new operator then just before object creation it is always checking previous objects.

---------- If the previous object is available with the same content then it won’t create new object that reference variable pointing to existing object.

---------- If the previous objects are not available then JVM will create new object



-----When we create object in Heap area instead of checking previous objects it directly creates objects.


--SCP area does not allow duplicate objects.

---Heap memory allows duplicate objects.



== operator :-

1. It is comparing reference type and it returns Boolean value as a return value.

2.If two reference variables are pointing to same object then it returns true otherwise false.


toString()

-------

1- toString( ) method present in object class it returns a string representation of object(class-name@hashcode).

2- String is child class of Object and it is overriding toString() to return content of the String object.

3-StringBuffer is child class of Object and it is overriding toString() to return content of the StringBuffer object.


----String is immutability class it means once we are creating String objects it is not possible to perform modifications on existing object. (String object is fixed object)

-----StringBuffer is a mutability class it means once we are creating StringBuffer objects on that existing object it is possible to perform modification



Concat( ) :-

--- Concat() method is combining two String objects and it is returning new String object.


 equals() method:-

----------------------

1- equals( ) method present in object used for reference comparison & return Boolean value.

-----If two reference variables are pointing to same object returns true otherwise false.

2--String is child class of object and it is overriding equals( ) methods used for content comparison.

3----If two objects content is same then returns true otherwise false.

------ StringBuffer class is child class of object and it is not overriding equals() method hence it is using parent class(Object) equals() method used for reference comparison.

---------- If two reference variables are pointing to same object returns true otherwise false



 CompareTo() & compareToIgnoreCase():-

-----------------------------------------------------------

1- By using compareTo() we are comparing two strings character by character, such type of checking is called lexicographically checking or dictionary checking.

---- compareTo() is return type is integer and it returns three values

-- if the two strings are equal then it return zero.

-- If the first string first character Unicode value is bigger than second string first character Unicode value then it return +ve value.

--If the first string first character Unicode value is smaller than second string first character Unicode value then it return +ve value.


---compareTo() method comparing two string with case sensitive.

---compareToIgnoreCase() method comparing two strings character by character by ignoring case.



----length variable used to find length of the Array.

---- length() is method used to find length of the String.


charAt(int) & split() & trim():-

---------------------------------------

charAt(int):-By using above method we are able to extract the character from particular index position.

public char charAt(int);

Split(String):- By using split() method we are dividing string into number of tokens.

public java.lang.String[] split(java.lang.String);

trim():- trim() is used to remove the trail and leading spaces this method always used for memory saver.


public java.lang.String trim();




endsWith() & startsWith() & substring():-

-----------------------------------------------------

1- endsWith() is used to find out if the string is ending with particular character/string or not.

2- startsWith() used to find out the particular String starting with particular character/string or not.

public boolean startsWith(java.lang.String);

public boolean endsWith(java.lang.String);

3-substring() used to find substring in main String.

public java.lang.String substring(int); int = starting index

public java.lang.String substring(int, int); int=starting index to int =ending index

while printing substring() it includes starting index & it excludes ending index



-----replace() method used to replace the String or character.


public java.lang.String toLowerCase();

public java.lang.String toUpperCase();

----The above methods are used to convert lower case to upper case & upper case to lower case


StringBuffer class method

------------------------------

reverse() & delete() & deleteCharAt()

Append()

Insert() ---is used to insert string any location in existring string


replace():



Wrapper classes

-------------------


1.Java is an Object oriented programming language so represent everything in the form of the object, but java supports 8 primitive data types these all are not part of object.


2- To represent 8 primitive data types in the form of object form we required 8 java classes these classes are called wrapper classes.


3- All wrapper classes present in the java.lang package and these all classes are immutable classes.



datatypes     wrapper-class     constructors

byte              Byte                    byte,String

short            Short              short,String

int                Integer                  int,  String

long    Long             long,String

float             Float                   double,float,String

double          Double              double,String

char            Character               char

boolean      Boolean               boolean,String





in java we are able to create wrapper object in two ways.

a) By using constructor approach


Integer i1 = new Integer(100);



b) By using valueOf() method


Integer a1 = Integer.valueOf(10);



 XxxValue():- it is used to convert wrapper object into correspondingprimitive value.

parseXXX():- it is used to convert String into corresponding primitive value & it is a static method present in wrapper classes.




1-Automatic conversion of primitive to wrapper object is called autoboxing.

2-Automatic conversion of wrapper object to primitive is called autounboxing.


Java .io package

-----------------------


1-Java.io package contains classes to perform input and output operations.

2- By using java.io package we are preforming file handling java.



Stream:-

------------


Stream is nothing but sequence of data


There are three streams are automatically created

1- System.in                standard input stream

2- System.out             standard output stream

3- System.error           standard error stream


I/O Streams:-

-----------------

An I/O stream represents input source or an output destination




Input stream:- Program uses Input stream to read the data from a source one item at a time.


Output stream:- Program uses output stream to write the data to a destination one item at a time




How we create direcotory


File file=new File("directory name");

file.mkdir();


for check it exist or not

-------------------------

if(file.exists())

{

}

else

{


}



How we create text file

------------------------------

File file=new File(text_file_name.txt);

file.createNewFile();

for check it exist or not

-------------------------

if(file.exists())

{

}

else

{


}


FileInputStream

-----------------------

- It is used to read the data from source one item at a time.

- To read the data from source use read() method of FileInputStream class.


public int read() throws java.io.IOException;

read() method returns first character Unicode value in the form of integer value.



 FileOutputStream

--------------------------

-- It is used to write the data to destination one item at a time.

---To write the data to destination use write() method of FileOutputStream class.


public void write(int unicode) throws java.io.IOException;

write() method is taking Unicode value of the character as a parameter



No comments