February 7 2015

Relational operators in java

Relational Operators are used for the purpose of comparing.They compare two quantities to determine if they are equal or greater than other.There are six types of relational operators

  • = = equal to operator
  • != not equal to operator
  • > greater than operator
  •  < less than operator
  •  >=  great than or equal operator
  •  <=  less than or equal to operator

Continue reading

January 21 2015

Fibonacci Series Program In Java

Fibonacci series program in java

Fibonacci series or Fibonacci sequence are the numbers in the following sequence


The first two numbers in the Fibonacci series are 0 and 1.The numbers followed by 0,1 are the sum of previous two numbers.





Fibonacci series program in java

Continue reading

January 19 2015

Java default access modifier

Java default access modifier

If we don’t specify any modifier, it is treated as default access. Any class, variable, method or constructor that has no declared access modifier is accessible by classes in the same package. Default access modifier is also called package access modifier.

A class can have public and default access whereas class members can have private, default, protected and public access.

Default Class Example

Student class does not have any modifier.It is treated as default access and Student class is visible only inside package1 package.

package com.answersz.package1;

class Student {


Continue reading

January 12 2015

Constructor Overloading In Java

Constructor Overloading In Java

Constructors is a special method in Java which is used to initialize the instance variables of the class.A constructor has the same name of the class and does not have any return type(not even void) .A constructor may or may not have parameters.

Whenever a new object is created JVM first allocates memory for the object and then invokes the matching constructor.If class does not have any constructor JVM provides default constructor with no arguments.

Constructors in Java can be overloaded. Two ore more constructors with difference in the parameters is called constructor overloading. Each constructor is used to perform different task.

Constructor Overloading In Java Example

Continue reading

January 3 2015

Java bitwise operators

Bitwise Operators

There are seven bitwise operators in Java that acts on integer datatypes(byte,short,long and int).Bitwise operators acts on bits of the integers.All the operation are perfomed on the binary representation of the number.Binary number system uses only two digits 0 and 1.

Integer.toBinaryString(10) will give the binary number of 10 that is 1010.

Bitwise Operators

Bitwise complement Operator(~)

Bitwise and operator(&) Continue reading

December 15 2014

Prime Numbers Program In Java

Prime Numbers Program In Java

A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.


1.The maximum value should be taken from the user.

2.Iterating from 1 to the maximum value.

3.Checking whether value is divisible any number from 2 to maximum value-1

4.If it is divisible by any number then it is not a prime number.

5.If it is not divisible by any number then it is a prime number.

6.Print the results. Continue reading

December 13 2014

Palindrome String Program In Java

Palindrome String Program In Java

A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward.Some simple examples are RACECAR,DEED, LEVEL,PIP etc.
In the below program the value entered by the user is stored in String  enteredString. Iterating the enteredString  from last character to first character reverse of the entered string is constructed and stored in reverseString . If enteredString and reverseString are equal the entered is a palindrome. If enteredString and reverseString are not equal the given string is not a palindrome.

Program Continue reading

November 8 2014

Java Boolean Operators

Java Boolean Operators

Boolean Operators are operators which act on boolean variables and returns the boolean result.Following are the boolean operators in java

Boolean and operator ( & )

Boolean & operator returns true only if both the variables are true otherwise returns false

Boolean or operator ( | )

Boolean | operator return true if any of the variable is true

Boolean not operator ( ! )

Boolean ! Return true if the value of the variable is false and false if value of the variable is true.

Continue reading