Home / JAVA (page 3)

JAVA

Basic concepts of Java

Java is Object Oriented programming language which was developed at Sun Microsystems. By object-oriented we mean, it is a technique to develop logical modules, such as classes that contain properties, methods, fields and events. An object is created in the program to represent the class. Objects are used to access data and behaviors of different software modules like classes, namespaces, ...

Read More »

Constructor in Java

In Java Constructor is a block of code which gets executed automatically when object of that class is created. It is not a function so does not return any value. Name of a class and a constructor should be same. Constructor and functions are same only with difference that constructor runs automatically after the initialization of object. Constructor can be ...

Read More »

Java program for Method overriding

Overriding is a technique in which we can recreate any function of base class by modifying this function with same name in the derived class. The function in parent or base class is with same name and must also has same type of arguments if provided in the function of the child class. Here child class inherited all the functionalists ...

Read More »

java program for pattern #14

1 01 101 0101 10101 This is an easy to implement pattern but the quality of a programmer depends on the way they implement their algorithm. How much can you reduce your coding. So here is how you can code this pattern without using if statement. Also see: Alternate c program for pattern#14 class pattern { public static void main(String ...

Read More »

Java program for Floyds Triangle

Floyds triangle

Java program for Floyds Triangle: Floyd’s Triangle is one of the most popular pattern in programming lanuguage. It is not usually famous by its name as it is very easy in implementation. The diagram below shows you the floyds triangle: // Java program for Floyd's triangle import java.util.*; class floyd { public static void main(String args[]) { int i,j,n,k=1; Scanner ...

Read More »

Java program for armstrong number using recursion

This is a Java program for armstrong number. But what is an armstrong number? An armstrong number is onw whose sum of the cube of digits is the number itself. Example #1: 153 ; 13 + 53 + 33 = 1+ 125 + 27 = 153 (Hence Armstrong) Example #2: 370 ; 33 + 73 + 03 = 27 + 343 + ...

Read More »

Java program to check for palindrome

Java program to check for Palindrome. What is a palindrome number or palindrome string? There are following definitions: A palindrome number or a palindrome string is one whose mirror image is same as itself. A Palindrome is exactly same as seen from beginning or ending. Concept used here: if(s.charAt(i) == s.charAt(l-i-1); MADAM : s.charAt(0) =M    (first character) s.charAt(l-1-0) =M ...

Read More »

Java program to remove duplicate characters

Program to remove duplicate characters

Java program to remove duplicate characters or repeated character from a given string. Example: Thiiis is aa tessstt ssstring OUTPUT:  This is a test string Thus our motive is to remove repeated characters or duplicate characters from a given string. This is done by following concept. Step #1: select the starting character:   ch=str.charAt(0);    (hhhello) Step #2: Add the ...

Read More »

Java program to swap two numbers without using a third variable

Here are 4 Tricks to swap two numbers without using a third variable. Here is a java program to swap two numbers without using a third variable. To do so you can use basic mathematical operations like multiplication, division and addition, subtraction. See the Further Explanation:  Incoming terms: tricks to swap two numbers, swap two numbers various tricks.

Read More »

Java program to print the magic number series

This is a Java program to print the Magic number series. However before starting let me tell you what is a magic number. A Magic number is a number whose sum of digits eventually leads to 1. Example#1:  19 ;  1+9 =10 ; 1+0 = 1.  Hence a magic number. Example#2:  224; 2+2+4=10; 1+0 =1.  Hence a magic number. Example#3:  874; ...

Read More »