Fundamentals & Data Types

Bytecode: Bytecode is a set of optimized instruction generated by java compiler during compilation phase & nature of the bytecode is more powerful than pointer code of ‘C’, C# language. Bytecode is common for all operating system.

JVM(Java Virtual  Machine): JVM is one of the programs developed by Sun Microsystem developer, available as a part of the java software & whose role is reading the line by line of bytecode & convert into the native understanding format of operating system. JVM is specific to the operating system.

JVM provides the inbuilt facility called garbage collection which will recollect unused space to improve the performance of the java based application.

Garbage Collection: A garbage collector is one of the system background java programs which is running along with our java program & whose role is to collect unused memory space & it improves the performance of the java based application.

So garbage collector is taking care of automatic memory management.

API(Application Programming Interface): Java provides a rich set of API where java program can reduce the existing code & developing their application without writing their own source code.


Java provides user-friendly syntax so that a java programmer will have the comfort of writing error-free program in a limited span of time.


Data Types

Purposes of a data type in every programming language is that to allocate sufficient amount of new memory space in the main memory of the computer, for the input of the program.

In most of the programming language, data types are of three types:

  1. Fundamentals / Pre-defined / Built-in Data Types
  2. Derived Data Types
  3. Programmer / User / Referential Defined Data Types.


Fundamental data types allow us to store single value & they never allow us to store multiple values at same time. For Ex:

int a;a=10;  Valid

a=10;  Valid

a=10,20,30; Invalid

Derived data types allow us to store multiple values of the same type but they never allow us to store multiple values of different types.

In most of the programming language, concept of array comes under derived data types.

int a[] = {10,20,30}     Valid

int b[] = { 10,Satya,20.20}    Invalid

Programmer defined data types allow us to store multiple value of same type or different types or both the types.

Datatype Name Size (Bytes)
Byte 1
Short 2
Int 4
Long 8
Float 4
Double 8
Char 2
Boolean 1


A constant is a variable whose value cannot be changed during execution of the program.

  • To make any constant we use a keyword called final.
  • Final keyword is placing an important role in three places as follows:
  1. At data member/variable level
  2. At method level
  3. At class level

Final at data member /variable level

The “final” keyword can be applied at data member level in 2 ways as follows:

  1. Final at data member level /declaration level.

Ex: final datatype x,y,z;

  1. Final at data member level /initialization level.

Ex: final datatype x=val1;

Final at data member level /declaration level

Once we declared variable as final then it allows us to place 1st time assignment value & it never allows us to place second time or subsequent assignment values & never allows single modification.

Ex: final float Pi;

Pi = 3.14178                  Correct

Pi = Pi + 1;                     Incorrrect

Pi = 3.14178 + 0;           Incorrrect

Pi = Pi + 1;                     Incorrrect


Final at data member level /initialization level

Ex: final datatype x=val1;

Once we declared a variable is made as final then it never allows single assignment & single modification.For ex:

final float Pi = 3.14178f;           Correct

Pi = Pi + 1;                                   Incorrect

Hence any common value when we place in a variable then it is mandatory to the java programmer to make such value as final.

Note: Final variable values cannot be modified.


Final at Method level

In most of the programming language, to perform any type of operation we use the concept of function. In java concept of function is known as methods.

In the real world, if we develop any function/method which is common for most of the programmer then such common method must be made as constant by using final keyword.

Once the method is final, we cannot redefine/overridden.

Final at class level

If we don’t want to give features of base class then the definition of base class must be made as a constant class by using final keyword. Hence final classes never participate in inheritance.

Note: Final variable cannot be modified.

Final method cannot be redefined.

Final classes cannot be inherited.


In any programming language, any type of operation uses the concept of function. In java programming, the concept of function is known as the method .Without method, we cannot perform any operation.

Definition: A part of the main program is called function/method. Self-contained block of the structure is called method.

The slogan of method is “Write Once and Call Anywhere (WORA)”.

Parts of the method:

  1. Method definition
  2. Method Call
  3. Method Declaration

Phases in method:

At the time of dealing with method the programmer must ensure three phases they are:

  • A method must take input (Either from inside the method definition or method call).
  • A method can do the process (When process the input inside the method definition).
  • A method can give the output (It can display the output either inside the method definition or return of output outside).


Number of approaches to define methods:

Sno. Take Input Return Values
1. No No
2. No Yes
3. Yes No
4. Yes Yes


Syntax for defining the methods:

Returntype  Methodname(List of parameter if any)


Block of statement

Business logic();


  • Returntype represents the type of value being returned by the method. If the method is returning any value then as a return type we write its datatype [Every datatype acts as a Return type].
  • If the method is not returning any value them its return type must be void [Void is a return type but not a data type in Java].
  • Method name represent a java valid variable name treated as name of the method.

Note: If the method is containing one word or more than one word then as a java programmer we must write/use in such a way that 1st word  1st letter is small & subsequent word 1st letter must be capital [Hungarian Notation].

Normal Notation                             Hungarian Notation

 Itemstatechanged()                         itemStateChanged()

get()                                                    get()

  • List of formal parameter represents variable names used in the method editing which are used for holding the input which is coming from method calls.
  • Block of statement represent set of executable statement which are providing solution to the client requirement & this logic is called business logic.
  • Variable used inside the method definition is called local variables.
  • Variable used in the method heading & in the method body can be accessed within the context of same method definition & not possible to access in other method definition [is called scope of the variable].
  • To return the result of the method in a method definition we use return statement & it can return only one value.

1st Approach:  Method can take values & method can return values.

Method definition                                                                                     Method  Calling

int area(int l,int b)                                                                                 int r2= area(10,20);


int a = l * b;

return a;



2nd Approach:  Method cannot take values & method cannot return values.

Method definition                                                                                                  Method Calling

Void Area                                                                                                                  Area();


int l, b, a ;



print a;



3rd Approach:  Method can take values & cannot return values.

Method Definition                                                                                                   Methods Calling

Void Area(int l, int b)                                                                                               Area(10,20);         {

int a= l * b;

print a;


4th Approach:  Method can take values & return values.

Method definition                                                                                                    Method Calling

Int area()                                                                                                                     int z = area();

{                                                                                                                                                              int x =area();

int l = 10; b=20, a;


return  a;



Method Overloading

A method is said to be overloaded if & only if method name is same but signature is different .

Signature represent the following points:

  1. Number of parameter
  2. Order of parameter
  3. Type of parameter

Note : Atleast one thing is different.

At the time of overloading a method, never consider its return type.

Method Overriding

Method heading is same but method body is different.

The process of defining the original method for performing different types of operation is called method overriding.

Note: A final method cannot be overridden where as overloaded method may or may not be final.






















































Blog at

Up ↑

%d bloggers like this: