Skip to main content


Showing posts from March, 2019

Types of variables in Java

What is a variable? A variable is a piece of memory which stores a data value. Thus, a variable has a data type. Primarily there are eight primitive data types in java. We will learn about these in a later post. Variables are typically used to store information which our Java program needs to do its job. This can be any kind of information ranging from texts, codes (e.g. country codes, currency codes etc.) to numbers, temporary results of multi-step calculations etc. You can declare a variable as below -  datatype name [ initialization ]; Initialization of a variable is not mandatory in all cases. Types of variables There are three types of variables in Java. We will discuss them one by one. 1. Local variables -  They can be declared in a method, constructor, or block.  When a method is entered, an area is pushed onto the call stack which contains slots for each local variable and parameter.  When the method is called, the parameter slots are initialized

Number System Conversions

When we start learning mathematics, the first thing we learn is Numbers (0, 1, 2, 3, ...). Basically, numbers are a set of values used to represent different quantities. For example, we can represent the number of students in a class, the number of viewers watching the soccer world cup final etc. The numbers we use most frequently are in Decimal Number System . Similarly, there are other number systems which have different digits/characters to represent the quantities. Decimal Number System - 10 digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) Binary Number System - 2 digits (0, 1) Octal Number System - 8 digits (0, 1, 2, 3, 4, 5, 6, 7) Hexadecimal Number System - 16 digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F) You can learn more about the number systems here . Sometimes, it is required to convert decimal numbers to one of the other number systems and vice versa. Therefore, in this blog post, we will look into the different conversion mechanisms. Though there are diffe