Posts

Compiler time TypeCasting in Java ? with Example

 Java mein type casting compile time par bhi hota hai, lekin uska ek specific context hota hai jo compile-time type safety ko maintain karta hai. *********************************************************************************** ### Compile-Time Type Casting in Java 1. **Syntax and Context**:    - Compile-time type casting Java mein hota hai jab hum ek reference variable ko uski derived class (subclass) mein convert karte hain.    - Syntax: `SubclassType obj = (SubclassType) superTypeObject;`      - Yahaan `superTypeObject` ek superclass type ka reference hai jo subclass type mein cast kiya ja raha hai. 2. **Type Safety Check**:    - Compile-time type casting ek type safety check provide karta hai. Jab hum ek superclass type ko subclass type mein cast karte hain, tab Java compile-time par yeh check karta hai ki kya yeh conversion possible hai.    - Agar conversion possible nahi hai (for example, jab superclass reference actual...

Array Of Objects (Example)

** Array of Objects  -   Student s   []=new Student[2]  - s   [  reference (100) , reference 2 (110)  ](Array of object where address present)                    index(0)                    index(1) -heap memory  :      -----------------------------------------     |         reference 1   (obj) 100               |     |         reference 2    (obj)  110              |     |                                                               ...

Different Array Types In Java ?

**Array is An Object (it stored inside the Heap memory) ** Normal 1D Array (We Know That )  ** Normal 2D Array (We Know That) ** Jagged Array (Exam ple) ******************************************************************************** import java.math.*; public class Jagged_Arr{ public static void main(String args[]) { int matr[][]=new int[4][]; matr[0]=new int[4]; matr[1]=new int[2]; matr[2]=new int[3]; matr[3]=new int[2]; for(int i=0;i<matr.length;i++) { for(int j=0;j<matr[i].length ;j++) { matr[i][j]=(int) (Math.random()*100); } } for(int row[] : matr) { for(int ele : row) { System.out.print(ele+ " "); } System.out.println(); } } } ******************************************************************************** ** 3D Array (Exapmle) ******************************************************************************** public class Multi_3D_Arr { public static void main(String[] args) { int r=...

What is Stack and Heap Memory and Method Area in JVM ?

Detailed View: Method Area : Holds class-level information and method definitions. Heap Memory : Allocates memory for objects and their instance variables. Stack Memory : Handles method calls, storing parameters, local variables, and method execution contexts. Summary: Method Area : Contains class definitions and method bytecode. Heap Memory : Stores objects and their instance variables. Stack Memory : Manages method execution contexts, including parameters and local variable. Method Area : The Method Area stores: Class level information, including method definitions (bytecode) and static variables. Constant pool (literal values and symbolic references). Field data, including instance variables and their types. It does not store actual objects or instances; it stores information related to classes and their structure. Heap Memory : The Heap Memory stores: Objects (instances of classes) and their instance variables. When you use new SomeClass() , it allocates memory on the heap for the ...

How Java Works ? (JDK,JRE,JVM)

Q . How Java Works ? (JDK,JVM,JRE) --->     (In Short)         1 )  JDK (Java Development Kit ) :         *   It Provides "Javac" Compiler Without "JDK" we can't Compiler our Source Code(.java)                                    into Byte Code(.class) file for that we need JDK .                         2) JVM (Java Virtual Machine) :         * It Excecutes Our Byte Code(.class) file in that "JVM"  Search for  PSVM(String args[])             to Run the code:                 3) JRE (Java Runtime Enviroment) :       * It Normally provides Libraries and various Components to our "JVM" Like an ...