Posts

Showing posts from June, 2025

OBJECT ORIENTED PROGRAMMING THROUGH JAVA : Unit - 1 : Type Casting and Type Conversion

  Type   Casting It   is   fairly   common   to   assign   a   value   of   one   type   to   a   variable   of   another   type.   If   the   two   types   are   compatible, then Java will perform the conversion automatically. For example, it is always possible to   assign   an   int   value   to   a   long   variable.   However,   not   all   types   are   compatible,   and   thus,   not   all   type   conversions   are   implicitly   allowed.   For   instance,   there   is   no   automatic   conversion   defined   from   double   to   byte .   Fortunately,   it   is   still   possible   to   obtain   a conversion   between   incompatible   ...

OBJECT ORIENTED PROGRAMMING THROUGH JAVA : Unit - 1 : Variables in Java

  What is a Variable in Java? A variable in Java is a named memory location that stores data values of a specific type. It acts as a container for values that can change during program execution. Variable Declaration and Initialization Syntax : type variableName; // Declaration type variableName = value; // Declaration + Initialization Example : int age; // Declaration age = 25 ; // Initialization String name = "Loki" ; // Declaration and Initialization Types of Variables in Java Java variables are classified based on their scope and position in the program: Type Declared Inside Scope Memory Location Local Variable Method or block Within method/block only Stack Instance Variable Inside class (outside methods) Whole object (per instance) Heap Static Variable Inside class using static Shared across all instances Method Area (static memory) 1. Local Variable Exists only within methods, constructors, or bloc...

OBJECT ORIENTED PROGRAMMING THROUGH JAVA : Unit - 1 : Data types in Java

Image
  Introduction Java language programs deal with the following entities: Primitive Data, Classes and Objects, Interfaces and their references, Arrays, Methods. The primitive data and their types are defined independent of the classes and interfaces. The arrays and methods derive their types from the first three entities.   Data Types in Java Java defines eight primitive types of data: byte , short , int , long , char , float , double , and boolean . The primitive types are also commonly referred to as simple types, and both terms will be used in this book. These can be put in four groups: ü   Integers This group includes byte , short , int , and long , which are for whole-valued signed numbers. ü   Floating-point numbers This group includes float and double , which represent numbers with fractional precision. ü   Characters This group includes char , which repr...