Core Java Notes
Core Java Notes
1.What is java?
• 1. Platform independent
• 2. Open source
• 3. Multithreading
• 4. More secure
• 5. Portable
• During the compilation the java program is converted into byte code(not machine specific).
• Bytecode can be runned by jvm of any platform.
• So code developed in one platform is capable of running in all other platform.
• A program in which source code is available to the general public for use and/or modification
from its original design at free of cost is called open source.
• Notepad
• Netbeans
• Eclipse
• JDeveloper(oracle)
• RAD(IBM)
JDK:
----
JRE:
----
JVM:
----
Class:
------
Method:
-------
Object:
-------
• byte
• short
• int
• long
• float
• double
• boolean
• char
• String
• nextByte();
• nextShort();
• nextInt();
• nextLong();
• nextFloat();
• nextDouble();
• next().charAt(0);
• next();
• nextLine();
• nextBoolean();
• Accessing one class Properties in another class without multiple object creation.
• It avoids time and memory wastage.
• It ensures code reusability
18.What are the ways to access the methods /data from another class?
• We can access the another class methods either by creating object or using extends keyword.
• Poly-many.
• Morphism-forms.
• Taking more than one forms is called polymorphism or one task implemented in many ways.
When we have multiple methods with same method name but differs only based on its
datatype,datatype count and order.
• Class-name
• Method-same
• Argument-differ based on datatype,order,number
• Single Inheritance
• Multilevel Inheritance
• Multiple Inheritance
• Hybrid Inheritance
• Hierarchical Inheritance
• Compilation error/syntax error-After extends keyword we can mention only one classname( , not
allowed)
• Priority problem-When multiple parent classes has methods with same name and
arguments,compiler will not know
which method should be called.
Multiple inheritance:
-------------------------
• More than one parent class directly supporting into same child class.
• Multiple inheritance not supported in java due to Compilation problem and priority problem
Multilevel inheritance:
-----------------------
• More than one parent class supporting into one child class in tree level structure.
• It is supported in java
Public:
-------
Protected:
------------
• It will support only abstract method(without business logic), won't support non abstract
method(method with business logic)
• In interface "public abstract" is default.
• using "implements" keyword we can implement the interface in a class where we can write the
business logic for all
unimplemented methods.
Abstract class:
-----------------
Interface:
-----------
• equals();
• equalsignorecase();
• contains();
• split();
• toUpperCase();
• toLowerCase();
• subString();
• isEmpty();
• identifyHashCode();
• startsWith();
• endsWith();
• CompareTo();
• charAt();
• indexOf();
• lastIndexOf();
• replace();
• Constructor is a special method which is called by default when object is created for that
particular class.(implicit call)
• Class name and constructor name must be same.
• It doesn't have any return type.
• It supports method overloading but won't support method overriding.
• purpose of constructor:It is used to initialise the values to variables.
• Parameterized constructor
• Non parameterized constructor
• constructor is not directly called by your code, its called by memory allocation and object
initialisation in the run time.
• Its return value is opaque to the user so we cant mention it.
• The process of calling one constructor from another constructor with respect to current object is
called constructor chaining.
• By using this() and super() methods we can achieve constructor chaining.
• No,we can't override the static method because it is part of a class rather than an object.
• When a variable is declared as static,then a single copy of variable is created and shared among all
object at class level.
• Static variable are essentially global variable.
• All the instance of the class share the same static variable.
• When a method is declared as static,we need not create object to call the paticular method.We
can call as Classname.methodname()
• Static method in java belong to the class(not to an object).
• They use no instance variables and will usually take the input from the parameters and perform
action on it,then return some result.
51.What is mean by final keyword and what's happend when we declare final as in
class,method,variable?
Final:
-----
Finally:
--------
• Code given inside finally block will always get executed whether exception occurs or not.
54.What is Exception?
• Exception is an unexpected event which when occurs in a program,your program will terminate
abnormally.
• We can avoid this abnormal termination using exception handling
mechanisms(try,catch,finally,throw,throws)
56.What are the difference between checked expection and unchecked expection?
Unchecked exception:
-------------------------
Checked exception:
----------------------
• Throwable
• Exception
• Yes we can have try block without catch block.But in that case finally block must be
present.(There will be no syntax error)
• Possible but we will not able to handle the exception without catch block.
62.What are the differences between final finally and finalize in java?
Final:
-----
Finally:
--------
• It’s a block of statement that definitely executes after the try catch block.
• Exception occurs or not,finally block always get executed.
Finalize:
---------
Throw:
------
• Throw is a keyword, using which we can throw any any exception.This keyword always given
inside the method.
Throws:
---------
Exception
Advantage:
-------------
Disadvantages:
----------------
70.What is collection ?
ArrayList:
----------
• Asynchronized
• It is not a thread safe
Vector:
-------
• Synchronized
• Thread safe
LinkedList:
-----------
ArrayList:
----------
74.Describe the Collections type hierarchy ? What are the main interfaces ?
Collection:
------------
• List
• Set
Hierarchy:
-----------
List:
----
• ArrayList
• LinkedList
• Vector
Set:
----
• Hashset
• LinkedHashSet
• Treeset
Map:
----
• HashMap
• LinkedHashMap
• Hashtable
• TreeMap
• ConcurrentHahMap
Set:
----
List:
-----
HashSet:
---------
TreeSet:
---------
• By addAll() we can convert List into set.(all the elements in list will get added to set)
78.What is map?
HashMap:
----------
Hashtable:
----------
Set:
----
Map:
----
• Yes,we can iterate the list using both normal and enhanced for loop.
• indexOf();
• get();
• lastIndexOf();
• HashMap :k?,v?
• LinkedHashMap:k?,v?
• TreeMap :k?,v?
• HashTable :k?,v?
• HashMap :k-1 null,v- n null
• LinkedHashMap:k-1 null,v- n null
• TreeMap :k-ignore null,v- allow null
• HashTable :k-ignore null,v- ignore null
• Set<Entry<key,value>>
87.Write the methods to get the key only and value only?
• mkdir();
• mkdirs();
• list();
• createNewFile();
• isDirectory();
• isFile();
• isHidden();
90.While creating a file if we not mention the format then under which format it will save the file?
• If we do not mention the file format it will automatically take format as file.
91.What are the difference between append and updating the file?
Enumeration:
--------------
Iterator:
---------
List Iterator:
--------------
Enumerator:
------------
Iterator:
----------
ListIterator:
--------------
Enumerator Methods:
------------------
• hasMoreElements();
• nextElement();
Iterator Methods:
----------------
• hasNext();
• next();
• remove();
ListIterator Methods:
---------------------
• hasNext();
• next();
• remove();
• hasPrevious();
• previous();
• Statement which has control over the loop or program is called control statements.
• Example:if,if else,for,while,dowhile etc
Break:
------
Continue:
----------
----------
While:
------
Do While:
---------
if and if else
===============
if
--
if else
--------
• executes the else part when the condition becomes false and executes if part when condition
becomes true.
Immutable string:
-----------------
mutable string:
----------------
removeAll():
------------
• removeAll() is a method , it is used to compare the 2 lists and remove all the common values
retainAll():
------------
• retainAll() is a method, it is used to compare both lists and retains only the common values
Literal String:
---------------
Heap memory:
------------
Static memory:
--------------
• java.lang
equals:
-------
Hashcode:
----------
• collections.SynchronisedList(refName of array);