Type Conversion and Casting: If you have a experience in a programming language, then you know this thing that it is common to assign a value of one type of variable to another type variable. Java performs type conversion automatically when the two types are compatible. For example, it is always possible to assign a…

# Month: August 2020

## Data Types In Java

In a Java there are eight different primitive types of data: byte, short, int, long, char, float, double, and boolean. This types are also referred to as a simple data types and these types are grouped into four different types: Integers: In this group byte, short, int and long are included, which are for whole-valued…

## HOW TO GET DISTINCT ELEMENTS FROM AN ARRAY BY AVOIDING DUPLICATE ELEMENTS?

Here we explain how to find distinct elements from an array by avoiding duplicate elements. In the below program we use array of integers int num[], in this array we found distinct elements. For finding the distinct elements we use the following two ways. Program: Find distinct elements from an array Output: following is the…

## PROGRAM TO ADD TWO NUMBERS WITHOUT USING PLUS (‘+’) SIGN

In our daily life we add some numbers and for this addition we use “+” sign. I have a one question, Can it be possible without using plus sign we add numbers? the answer is Yes! we can add two numbers without using the plus (“+”) sign. In the below program we use two different…

## Java String Methods with Examples

Java string methods with examples: There are different string methods in java we will use this methods for perform various operations on the string in java.Following are some Java String Methods with Examples. Program: Get character from a string In this program we use charAt() method to get or access the single character from a…

## Basic operations on String in Java- Strings Concatenation, Compare

Following programs are for performing the strings basic operations in java like string concatenation, string compare. To perform the string concatenation, string compare in java uses the inbuilt methods in java. String Length: Program: Find the length of string Here we first create the string named str and use the length() method to get the…

## Reverse a String

How to reverse the string? We will use the following different solutions for reversing the string. First, we get input from the user using a command line. In the first solution of this problem we buffer the input string using the StringBuffer(String string) method. Then reverse this buffer and after reversing convert the buffer into…

## Linear Search

Linear Search is a used for finding the key element in the multiple of elements in a given array. Now a days, Linear search is not that much used because Linear search algorithm is slow as compare to binary search or hashing. Algorithm: First step is traverse the array Next is match the search element…

## Selection Sort

Selection sort is a simple sorting algorithm. This sorting algorithm is an in-place comparison-based algorithm in which the list is divided into two parts, the sorted part at the left end and the unsorted part at the right end. Initially, the sorted part is empty and the unsorted part is the entire list. The smallest…

## Quick Sort

Sort algorithms order the elements of an array according to a predefined order.Quick sort is a divide and conquer algorithm. In a divide and conquer sortingalgorithm the original data is separated into two parts “divide” which areindividually sorted and “conquered” and then combined. Algorithm: If the array contains only one element or zero elements than…

## Loops and Loop Control Statements in Java

Loops and Loop Control Statements- There may be a situation when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on. Programming languages provide various Loop and Loop control statements that…

## Loop Control Statements

Loop Control Statements: Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed. Java supports the following control statements. Break Statement Continue Statement Break Statement: The break statement in Java programming language has the followingtwo usages − When the break…

## For Loop

A loops statement allows us to execute a statement or group of statementsmultiple times and following is the general form of a loop statement in mostof the programming languages . To gain a bit more control over the execution of a loop, we have another option. The for loop requires three different statements to operate….

## While Loop

If we want to run a specific statement more than once in a loop, we need another method. To do this, java comes with another couple of keywords, while and for. The while statement is somewhat easier to use. It needs only one bool argument to determine if it should continue to execute. This statement…

## Operators in Java

Java defines several operators. To perform the different types of operations on variables and their values this operators are use. Logic allows you to control what part of a function is evaluated based on changesto variables. Using logic, you’ll be able to change which statements in your codewill run. Simply put, everything you write must…

## Variables

Variables are used to store the information to be referenced and manipulated in a computer program. Variables are also provide a way of labeling data with a descriptive name, so that our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that hold information….

## What are Functions?

Functions, sometimes called methods, contain statements which can process data. The statements can or cannot process data.Other statements are also can access the Methods. This action is called as calling a function or making a function call. Functions may look different in different programming languages, but the way they work is mostly the same. The…

## Merge Sort

There are different sorting algorithms are available like selection sort, insertion sort etc. In this article we learn about one of them sorting algorithm, working of this sorting algorithm and example of this sorting algorithm. Merge sort algorithm is the simplest sorting algorithm as compare to other sorting algorithms. The Merge sorting algorithm can be…

## Insertion Sort

There are different sorting algorithms are available like selection sort, insertion sort etc. In this article we learn about one of them sorting algorithm. Also working of this sorting algorithm and example of this sorting algorithm. Insertion sorting algorithm is the simplest sorting algorithm as compare to other sorting algorithms. Insertion sorting is a simple…

## Bubble sort

There are different sorting algorithms are available like selection sort, insertion sort etc. In this article we learn about one of them sorting algorithm, working of this sorting algorithm and example of this sorting algorithm. Bubble sort algorithm is the simplest sorting algorithm as compare to other sorting algorithms. In the bubble sorting algorithm, array…

## Binary search

Binary search is one of the fundamental algorithms in computer science. In order to explore it, we’ll first build up a theoretical backbone, then use that to implement the algorithm properly and avoid those nasty off-by-one errors everyone’s been talking about. Finding a value in a sorted sequence In its simplest form, binary search isused…

## Binary Search Program

There are two types of searching are possible. First is linear search and second is binary search. In this article we explain about the binary search program, if you want to learn about what is linear search and how it works? see this article Linear Search. The linear search and binary search are used to…

## Declare, Instantiate and Initialize the Arrays

In this article we learn how to declare instantiate and initialize the array. Arrays are nicely organized lists of data. Think of a numbered list that starts at zero and extends one line every time you add something to the list. Arrays are useful for any number of situations because they’re treated as a single…

## Arrays

Arrays are nicely organized lists of data. Array is a collection of the homogeneous data types. Think of a numbered list that starts at zero and extends one line every time you add something to the list. The arrays are useful for any number of situations because they’re treated as a single hunk of data….

## Swapping of Two Numbers

Here we will see the swapping of two numbers using two different methods. In first method we exchange the values using the temporary variables and in second method Swapping of numbers without temporary variable. Swapping of numbers is the way of exchanging the values in the variables. Suppose there are two variables a and b,…

## Addition of Two Numbers

In this program we will see the addition of two numbers using two different methods. In first program we specify the values of two numbers in the program itself. And in second program take the both numbers entered by user and add. In third program we use add () function. Adding the numbers using java…

## How To Run a Java Program

If you are new in java programming and you want to know how to run a java program then see the below steps. For running the java program use the Notepad and Command Prompt. Simple Java Program: In order to start with basic Java programming, let us look at the standard Hello World program. In…