Monday, 28 August 2017

Java Notes

Java Technology

HelloWorld.java -> Java Code
HelloWorld.class -> Java ByteCode

Bytecode

Object : -An  real-world object with state and behaviour

Class:- It’s a blueprint from which objects can be created

Class can be public or default.it cannot be declared as private or protected.

Class Name consists of:- alphabets, Numbers, $,_

Inheritance

Extends

Interface – A Contract between a class and the outside world.

Implements

Package

Variables
Instance Variables (Non-Static Fields)
Class Variables (Static Fields)
Local Variables
Parameters


Literals :- Java Literals are syntactic representations of variables.

Using Underscore Characters in Numeric Literals
long creditCardNumber = 1234_5678_9012_3456L; which is equal to 1234567890123456

Array
Java.util.Arrays
Arrays.binarySearch(array,key)
Arrays.fill(array,value)
Arrays.Equals(array1,array2) 1 dimension
Arrays.deepequals(array1,array2) 2 dimension

Operators


Type Comparison Operator instanceof

Bitwise and Bit Shift Operators

<<,<<<,&,|,^

If another class cannot call a Class constructor, it cannot directly create Class objects.

Variable Argument (Varargs)

            private static int add(int... i) {
                        int sum = 0;
                        for (int k = 0; k < i.length; k++) {
                                    sum += i[k];
                        }
                        return sum;
            }

Object Creation of  a class by name myClass:-

new()
myClass.class.newInstance()
Class obj = Class.forName("myClass”);
myClass myclass = obj.getInstance();
Serialization
Clone()


compile-time constant
A constant variable of primitive type or type String that is declared final and initialized with a compile-time constant expression.

Important Nested Classes

Nested classes that are declared static are called static nested classes.
Non-static nested classes are called inner classes.
There are two special kinds of inner classes: local classes and anonymous classes.
a local class can access local variables and parameters of the enclosing block that are final or
effectively final
Shadowing
Local classes are similar to inner classes because they cannot define or declare any static members
Final and Effectively Final:-
A variable or parameter whose value is never changed after it is initialized is effectively final.

Serializable

serialize an object means to convert its state to a byte stream so that the byte stream can be
 reverted back into a copy of the object.
A Java object is serializable if its class or any of its superclasses implements either the
 java.io.Serializable interface or its subinterface, java.io.Externalizable.

Enum

All enums implicitly extend java.lang.Enum.hence they cannot be extended further.
Note: The constructor for an enum type must be package-private or private access. It automatically
creates the constants that are defined at the beginning of the enum body. You cannot invoke an
enum constructor yourself


All interfaces are inherently static
Annotation

Interfaces
abstract methods, default methods, and static methods.
All constant values defined in an interface are implicitly public, static, and final, you can omit
these modifiers.

The Java programming language supports multiple inheritance of type

Using an Interface as a Type

Overriding and Hiding Methods

covariant return type

Instance methods are preferred over interface default methods.

Static methods in interfaces are never inherited.

virtual method invocation

hiding fields
hiding methods

Methods called from constructors should generally be declared final.

Abstract Class Implements an Interface

Abstract calss can have final methods.

static import

Generics

type inference

bounded type parameters

Given two concrete types A and B (for example, Number and Integer), MyClass<A> has no
 relationship to MyClass<B>, regardless of whether or not A and B are related. The common
parent of MyClass<A> and MyClass<B> is Object.

static import

exception

exception handling

call stack

Checked Exceptions
Errors and runtime exceptions are collectively known as unchecked exceptions

All exceptions inherit from Throwable class

If a catch block handles more than one exception type, then the catch parameter is implicitly final.

try-with-resources statement is a try statement that declares one or more resources.
Any object that implements java.lang.AutoCloseable, which includes all objects which implement
 java.io.Closeable, can be used as a resource.

suppressed exceptions

runtime exception  occurs when a method tries to access a member of an object through a null
reference

StackTraceElement

File IO

java.io vs java.nio

Io Streams

Array based memory

byte streams

InputStream and OutputStream are superclasses

FileInputStream and FileOutputStream are descendends of above two classes.Used for byte reading

FileReader and FileWriter same as above used for character’s reading.

BufferedReader and PrintWriter used in Line-Oriented I/O


Buffered Streams


There are four buffered stream classes used to wrap unbuffered streams: BufferedInputStream and
BufferedOutputStream create buffered byte streams, while BufferedReader and BufferedWriter
create buffered character streams.


flushing the buffer.

Datastreams

objectStreams


FileVisitor to walkthrough file tree

Type Erasure and Bridge Methods
       
Restrictions on generics

 ACID (Atomicity, Consistency, Isolation, Durability)

No comments:

Post a Comment

Installing Docker and Minikube

  install docker-   sudo apt install docker.io   set user to docker group:- sudo gpasswd -a   {user} docker   imp commands:- ...