Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

Java 2

The document discusses various Java concepts including access modifiers, OOP concepts, threads, collections, exceptions and new features in Java 8 such as lambda expressions and streams API.

Uploaded by

Blackhat Hacker
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Java 2

The document discusses various Java concepts including access modifiers, OOP concepts, threads, collections, exceptions and new features in Java 8 such as lambda expressions and streams API.

Uploaded by

Blackhat Hacker
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Access modifiers:-

In java the access modifiers can be defined as

1. Default
2. Public
3. Private
4. Protected
1. Default:-
A class does not have any parameters is called Default

2. Public:-
The public class can be accessible by everyone in the class and it contains
keyword called public

3. Private:-
The private class can not accessible by everyone because it is declared
with in the class and it contains a keyword called private.

4. Protected:-
The class contains a keyword called protected.

Java:-

Java is a one of the high level programming language and it is


purely depends on oops concepts and it stands for Object Oriented
Programming Language.

OOPS Concepts:

1. Class
2. Object
3. Inheritance
4. Polymorphism
5. Abstraction
6. Encapsulation

1. Class:-
In java a class in nothing but collection of multiple objects and it is a
blue print of an logical entity.

2. Object:-
Object is an instance of class that is used to execute the class.

3. Inheritance:-
Inheritance is nothing but it is deriving a new class from the already
existing class.

4. Polymorphism:-
Polymorphism is a mechanism it performs different things as per objects
and class.

5. Abstraction:-
In java abstraction is nothing but it shows only essential attributes and
hides unnecessary information.

6. Encapsulation:-
Encapsulation is a mechanism it combines the data together and their
function and manipulates under a single unit is called encapsulation.
Constructor:-

A constructor in java is used to create an instance of class

1. Its name is same as class name


2. It has no return type.

String:-

In java strings are known as it is collection of sequence of characters. The


objects of Strings are immutable. It classified into 2 types they are

1. String Buffer
2. String Builder
The difference between String buffer and string builder.

STRING BUFFER STRING BUILDER


It is mutable It is immutable.

Threads:-
Threads can be used to perform complicated tasks in the background
without interrupting the main programme.
Threads can be classified as

Threads
Threads Threads
Threads Implementable- implementable -
Extendable
Runnable Callable
Threads Life Cycle:-

A Thread is always exist on the following states they may be defined as

New

Active -
Terminated.
Runnabe;

Time
Blocked
Waiting

Collection Framework:-

In java collection framework can be defined as various types they are

1. List
2. Set
3. Map

The difference between list, set and map

LIST SET MAP


1. The duplicate 1. The duplicate 1. The duplicate
elements are elements are elements are
allowed not allowed. not allowed.
2. It follows an 2@ It will not 3. It will also not
Insertion order. follows an follow an
insertion order insertion order
List:-
The list can be defined into 2 types they are
1. Array List
2. Linked List

ARRAY LIST LINKED LIST


It is used for retrieve purpose It is used for modification purpose
It is fixed in size It is dynamic in size.

Hashing Algorithm:-

Hashing algorithm will work on uses by Hash code and equals()

Hash code:- It will identifies the buckets, for the first time it will assign the
values directly into the buckets.

If same hash code will appears there will be an hash Collision then
equals method must be callable

Equals():- If it is equal it replace the value into the buckets

If it is not equals it will create a new node and assign value into the
node.

The difference between class, Abstract Class and interface


CLASS ABSTRACT CLASS INTERFACE
A class is fully An abstract class An interface contains
implementable and contains both abstract only abstract methods.
accessible. and non – abstract
methods.
A class contains all An Abstract class half An interface class is not
kinds of methods implementable implementable
An abstract does not An abstract class
support multilevel support multilevel
inheritance inheritance.

Method Over Loading:-

In java a class has multiple methods having the same name but different
parameters.

The parameters can be classified through 3 catageries

1. No.of parameters
2. Type of parameters
3. Order of parameters

Method Over Riding:-

If subclass has the same methods as declared in the parent class.

Sorting in java:-
Sorting in java is nothing but it is used to assend the order in size, the
sorting can be defined as

1. Comparator:-
The comparator is used to order the objects of the user defined class
and it is used to compare the two different objects.

2. Comparable:-
Comparable is used to order the objects of the user defined class and it
is used to compare the one object.

Exceptions:-

In java the exceptions can de defined as

1. Runtime exceptions
2. Io exceptions

1. Runtime Exceptions:-
The runtime exceptions are also known as un- checked
exceptions these are happen due to programming error
The run time exceptions are also classified into various types they are
1. Arithmetic Exceptions
2. Array index out of bounds of exceptions
3. Null pointer exceptions
2. Io exceptions:-
The Io exceptions are also known as checked exceptions these are
happen due to input and output of the programme, it can be classified into
various types they are
1. File not founds exceptions
2. Eofe

Custom Immutable Class:-

In java if ones an object is created we can not change its content, the class
contains various steps they are

1) The class must be declare as final,


2) Data members in the class must be declared as private,
3) Data members in the class must be declared as final,
4) A public constructor is to be initialized,
5) Only getter methods are used.

Mutable Class:-

We can modify whenever the instance of object is created.

Executor Framework:-

It provides a way to separate the task execution logic the application code.
For creating an executor framework we need to create a thread pool, the thread
pool can be classified into various types they are given below,

Single Thread Executor

Fixed thread pool

Cachd Thread pool

Schedule Executor

How to create an custom Exception logic code?

Package com.exception.java.

Public class Exception{

Public static void main(String[] args) {

Try{

Throw new TestException (“this is only a test Exception”);

Catch(TestException){

System.out.println(t.getMessage());

}}
Public class TestException extends Exception{

TestException(String str)

Super(Str0) }}}

Class Loader:-

In java the class loaders are part of jvm ad it is used to load classes and
interface.

The class loaders can be classified into 3 types they are

1. Bootstrap class loader


2. Extension class loaders
3. System class loaders
4. Plugin class loaders

Java 8 Features:-

The java 8 features can be defined as various types they are

 Lambda expressions
 Functional interface
 Method reference
 Streams API
 Date time API
 Optional class
 Nashom, and js Engine.

1. Lambda expression:-
The lambda expressions are anonymous functions, it does not
belongs to any class and it does not a any specific name,

It mainly implementable on functional interface.

2. Functional interface
The functional interface contains only one abstract methods.

3. Method Reference:-
The method reference is a shorthand notation of function using lambda
expression to call a method, it contains various methods that can be
callable
1. Static method reference,
2. Instance method reference of a particular object
3. Instance method reference of a particular type
4. Constructor reference.

5. Streams API:-
The streams Api can be used to process the collection of
objects with the functional style of coding using lambda expression.

6. Date time API:-


`

Built in functions:-

These are classified into 4 types they are given below

1. Functional interface
2. Supplier interface
3. Consumer interface
4. Predicate interface

1.) Functional Interface:-


It contains only one method to accept an object of any data type
2.) Supplier interface:-
It also contains only one method called get()
3.) Consumer interface:-
It also contains only one method called accept()
4.) Predicate interface:-
It also contains only one method called test() for to check true or false.

Threads:-

Threads can be used to perform complicated tasks in the background with out
interepting the main programme.
Life cycle of Thread:-

1. New
2. Active – runnable
3. Waiting
4. Blocked
5. Terminated

How to create custom exception :-

public class Exception

public static void main(String[] args)

try

Throw new TestException("This is only testException");

}
catch(TestException)

sout(t.getmessage());

public class TestException extends Exception

TestException(String str)

super(Str);

You might also like