0% found this document useful (0 votes)
3 views3 pages

Java Variables and Memory Management Guide

The document explains the use of static and non-static variables in Java, detailing their memory allocation and purpose. It also covers concepts like garbage collection, methods, factory methods, and the use of the 'this' keyword, along with the definitions and functionalities of static and non-static blocks and constructors. Additionally, it includes a Java code example for converting a decimal number to binary.

Uploaded by

kondepatichinni
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Java Variables and Memory Management Guide

The document explains the use of static and non-static variables in Java, detailing their memory allocation and purpose. It also covers concepts like garbage collection, methods, factory methods, and the use of the 'this' keyword, along with the definitions and functionalities of static and non-static blocks and constructors. Additionally, it includes a Java code example for converting a decimal number to binary.

Uploaded by

kondepatichinni
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

[Link] WE WILL USE NON STATIC VARIABLES?

A) NON STATIC VARIABLES ARE USED TO STORE SPECIFIC VALUES OF AN OBJECT


[Link] WE WILL USE STATIC VARIABLES?
A) STATIC VARIABLE ARE USE TO STORE COMMON VALUES OF AN MULTIPLE OBJECTS.

<object existing heap area without reference is called as Abandon object.

[Link] MEMORY IS ALLOCATED FOR STATIC VARIABLES?


A) FOR STATIC VARIABLES MEMORY WILL BE ALLOCATED INSIDE CLASS STATIC AREA AND
DURING CLASS LOADING TIME.
[Link] MEMORY IS ALLOCATED FOR NON STATIC VARIABLES?
A) FOR NON STATIC VARIABLES MEMORY WILL BE ALLOCATED INSIDE HEAP AREA DURING OBJECT
CREATION
5. WHERE MEMORY IS ALLOCATED FOR LOCAL VARIABLES ARE STORED?
A) FOR LOCAL VARIABLES MEMORY IS ALLOCATED INSIDE STACK AREA DURING METHOD
EXECUTION TIME.

<Package is nothing but just like a folder using packages we can avoid naming
collisions.
<packages are collection of classes, interfaces and sub packages.

GARBAGE COLLECTOR:
<Garbage collector is a part of JVM this mechanism is used to remove the abandon
objects from memory.
<Garbage collector is used for memory management purpose.

A method is a block of code which only runs when it is called.

You can pass data, known as parameters, into a method.

Methods are used to perform certain actions, and they are also known as functions.

Why use methods? To reuse code: define the code once, and use it many times.

<Information can be passed to methods as a parameter. Parameters act as variables


inside the method.
<When a parameter is passed to the method, it is called an argument.
<Note that when you are working with multiple parameters, the method call must have
the same number of arguments as there are parameters, and the arguments must be
passed in the same order.

@@@@ without extensor keyword we cant override........................in


constructor..

FACTORY METHOD:
<If any methods creating object of a class and returning the instance those methods
are called as factory methods.
<factory methods should be available in within same class.
<factory methods are used to return the objects.

this keyword:
<this keyword is used to refer non static variables by using current instance
<we can't use this keyword inside static contest.

WHEN WE WILL USE this keyword


<If local variables name & non static variables names are same to refer non static
variables this keyword is mandatory.
BLOCKS:
BLOCKS ARE ALSO CALLED AS MULTILINE INTILIZER IN JAVA WE HAVE 2 TYPES OF BLOCKS
[Link] BLOCK
[Link] STATIC BLOCK

[Link] BLOCK:
<Static block are used to initialize the static data members of a class
<Static blocks are also known as multiline static initializer.
<Inside static block we can't initialize the non static data members.
<Static blocks will execute during class loading time.
<In a class we can create a 'n' number of static blocks those static blocks will
get executed top to bottom.

[Link] STATIC BLOCK:


<Non static block are used to initialize the non static data members.
<Non static blocks are also known as multiline non static initializer
<In non static blocks we can initialize the both static and non static data
members.
<Non static blocks will execute whenever object is created.
<In a class we can create a 'n' number of non static blocks those blocks are
executed top to bottom.

CONSTRUCTOR:
<Constructor is a special type non static method
<Constructor is used to initialize the non static data members of class
<Constructor name should be same name as class.
<Constructor will get executed whenever object is created.
<We can create a constructor with formal arguments or without formal arguments
<Constructor with formal arguments is called as parametrized constructor.
<Constructor without formal arguments is called as non argument constructor.
<Constructor can't be a finite and static
<constructor is also known as special type non static multiline initializer.

DEFAULT CONSTRUCTOR:
<In a class if programmer not created any constructor compiler will add one
constructor during compile time the constructor is called as default

import [Link];

public class dectobin {

public static void main(String[] args) {


Scanner Scn=new Scanner([Link]);
[Link]("enter a num");
int n=[Link]();
int bin=0;
int i=1;
while(n>0)
{
int bit=n%2;
bin=bit*i+bin;
i*=10;
n/=2;
}
[Link](bin);
}
}

You might also like