Posts

Garbage Collection

 1. Garbage collection is a mechanism of requiring the heap space by destroying all unused/unreferenced objects which are eligible for garbage collection from the heap memory. 2. Garbage collector is a demantbead(low priority thread). 3. Garbage collector always runs in the background of every java program. 4. The algorithm which is used by garbage collector is marked and sweep algorithm. 5. Garbage collection is not process of collecting and discards dead objects. It is more like making the "live"  objects(all objects that are reachable from Java and destroy all other objects.) 6. In our java program no need to call the garbage collector manually, but if we want to call the garbage collector manually we can do that in two ways:     a. By using system class (System.c()) - It is a static method.     b. By using Runtime class-               Runtime r=Runtime.getRuntime();             ...

Type Casting

 Type Casting Type Casting:                    Converting one data type into another data type is knowns as Type casting. All the 8 primitives datatype except boolean we can convert from one datatype to another datatype. Types of Type casting: Inplicit type casting Explicit type casting 1. Implicit type casting: It is a process of Converting smaller datatype to larger datatype is known as Implicit type casting. It is also known as Widening. Implicit type casting is done by compiler automatically. There is no loss of information in implicit type casting. 2. Explicit type casting:  It is a process of converting larger datatype to smaller datatype is known as Explicit type casting. It is also known as narrowing. Explicit type casting will not be performed by the compiler, it is the responsibility of the programmer. There may be chance of loss of information. Byte-> short, int, long, float, double. short-> int, long...

Exception Handling

 Exception Handling Exception:                If there is an exception in our program, the program will be terminated. But we can save program by using exception handling techniques. Types of Exception: Checked Exception: The exception which are detected at compilation time by JVM are known as Checked exception. Unchecked Exception: The exception which are detected at run time by JVM are known as Unchecked Exception. Error:               If there is an error in your program, the program will be terminated. We can't save our program. Types of Error: Compile time Error: These errors occurs due to wrong syntax. Runtime Error: These errors occurs due to inefficiency of the machine. Logical Error: These errors are occurs due to bad login in program. Key points In Exception Handling: If we are writing try-catch-finally blocks then we should maintain the order. try-catch-finally   ---> Val...

OOP's Concepts

Image
 OOP's Concepts: Class Object Encapsulation Inheritance Polymorphism Abstraction 1. Class:                  Class is a collection of objects.  Class is a blueprint which defines some properties and behaviors.  It is logical entity. 2. Object:                 Any real world entity which has behavior and state known as Object. It is logical or physical entity. For Ex. chair, book, computer, bottle etc. 3. Encapsulation:               It is a process of wrapping up of data or binding up of data into a single unit, known as encapsulation. For Ex. Capsule(wrapped with different medicines).               It is a process of making fields as private and providing access to those fields with the help of public methods that is through setters and getters methods. 4. Inheritance:       ...

Access Specifiers in Java

Image
 Access Specifiers In Java, there are 4 types of Access Specifiers:      A. Class Level:      1. If class is declared as public then that class is visible to all the classes everywhere inside that project.      2. If the class is declared as default (package private) then that is visible to the classes which are present in the same package. B. Member Level:     At member level we can use all the four access modifiers. 1. Public:  If a method, variable or constructor is declared as public then we can access them from anywhere. When we are accessing the public member its class also should be public otherwise will be getting compile time error. 2. Default: If a method, variable or constructor is declared as default then we can access them from current package only. So it is also called "PACKAGE-PRIVATE". 3. Private:  If a method, variable or constructor is declared as private then we can access them in the current class ...

Constructor in Java

  Constructor: 1. It is used to initialize an object. 2. It is open type of special method. 3. It is used to provide values for the "instance" variables. 4. Constructor is invoked implicitly. 5. The java compiler provides a default constructor if you don't have any Constructor. Rules: 1. Constructor should be having same name as class name. 2. It should not having any return type. Syntax: <Access Modifier><class name>() Two types of constructor: 1. Default Constructor:          Constructor which has no parameters,known as Default Constructor. 2. Parameterized Constructor :          Constructor which has a parameters, known as Parameterized constructor.          Constructor will be called simultaneously whenever we are creating an object. Keypoints in Java Constructor: 1. We are supposed to initialize an object with the available constructor present in the class. 2. If we are trying to initialize ...

Data types and Variables

Image
  Datatype:     Specifies the size and then type of values that can be stored in an identifier.     They are used to represent how much memory is required to hold the data. Variables:      Variables are nothing but a name given to storage area. Three types of variables:      1. Local Variable      2. Instance variable      3. Static variable 1. Local Variable:   A  local variable  in Java is a variable that’s declared within the body of a method. Then you can use the variable only within that method. Other methods in the class aren’t even aware that the variable exists. If we are declaring a local variable then we should initialize it within the block before using it . 2. Instance variable: The variables which are declared inside a class outside any method /block/ a constructor are known as instance variables.       *  For Instance variables JVM will automatically ass...