Showing posts with label Core Java. Show all posts
Showing posts with label Core Java. Show all posts

Collection vs Collections in Java

Collection:

In Java, "Collection" (without an 's') is an interface that's a part of the Java Collections Framework. Now, what's an interface? Think of it as a set of rules that classes need to follow. So, when we say "Collection" in Java, we're talking about a set of rules that classes can follow to be considered a collection.

Top 50 Mostly Asked Core Java Interview Questions

Top 50 core java interview questions, core java interview questions

Java is a widely-used programming language that is known for its robustness, scalability, and platform independence. As an Java developer, it is very important to have a deep understanding of the language and its advanced concepts to excel in interviews. In this article, I am going to share some common and challenging interview questions related to Core Java topics. These questions will help you prepare well for your next Java interview.

Strings In Java

In this post we will study what is strings in Java and why they are immutable. Let's start by understanding what strings are in Java  

In Java, a string is a sequence of characters that is used to represent text.. Strings are immutable in Java that means once a string is created, its value cannot be changed. We will explore it later in the article.

In Java, there are different ways to create strings. You can use double quotes "" or the new keyword. We will  see how to put strings together, which is called string combination. We will also discover efficient ways to combine strings using the + operator and the concat() method.  Let's learn about these methods and when to use them.

Generic Class Example in Java

In this post we are going to learn what is generic class with example. Generic class in java example. 

A Generic class means in that class we can use any type as parameter(T).  In this example we are using the T type parameter to create a generic class.

Example of a Constructor in Java

In this post we are going to create a class in Java with constructor. So let's see how to create a class in Java which contains constructor method.  

First of all we need to know what is a constructor in Java.

What is Arrays in Java

Basically an array in java is a collection of homogeneous elements that simply means array can store elements of same type or we can say it can store elements of same data types. means if we declare integer type array so we can store only integer data type elements in array or if we declared array of character type so we can store only character's in it. 

How to copy Arrays in Java with Examples

In this post we will learn how to copy arrays in java. Copying arrays simply means copying one array elements into another array. There are two main ways to do this first by using loops and second by using methods.

How to compare arrays in Java | Examples

In this post we will learn how to compare two arrays in java. But, before that we need to understand what comparing arrays really means. So without wasting more time  lets get started. 

  What is comparing arrays really means: The comparing arrays means comparing or we can say checking first array elements are same like another one or not. for example: If we have two arrays like we can say arr1[] or arr2[] here,

Length of an Array in Java | Java Program to find Length of an Array

In this article you will learn how to find array length in java. But, before learning how to find array length, you should know exactly array length means what.

In short array length means the limit of elements that array can hold. See in the below diagram we have stored 7 elements in array so length of this array is 7.

How to Print Arrays in Java | Java Program to Accept and Print Array Elements

In this article we are going to learn how to accept and print array elements in Java. 

How to print arrays in java: 

To print array elements we first need to accept it from user. In this post we will learn how to accept array elements from user dynamically and print it on the output screen. Simple java program to insert elements in array. 

How to Sort Arrays in Java

In this post we will learn how to write a  java program to sort array elements. How to sort arrays in java. Sorting array elements means storing or printing it in ascending or descending order. So let's see how to print given array elements in sorted manner.

Java Program to Print Square of Given Array Elements

In previous post we learnt how to print multiplication of given array elements. In this post we will learn how to print squares of given array elements. So let's get started... :)

Java Program to Print Multiplication of Given Array Elements

Java program to print multiplication of given array elements

In previous post we learnt how to print Sum of given array elements. In this post we will learn how to print multiplication of given array elements. 

Java Program to Print Sum of given Array Elements

In previous  post we learnt how to check given element is present in array or not. In this post we will learn how to print sum of given array elements. So let's get started... :)


  Step by step logic of the given program:


1. Accept array limit from user store it in variable say lim.

2. Accept elements from user. Run a for loop from 0 to arr.length-1 and store elements one by one in array:

Java Program to Check whether Given Element is Present in Array or not

In previous tutorial we learnt how to accept and print array elements. In this post we will learn is given element is present in array or not, Java program to check whether given element is present in array or not.

Factorial Program In Java

Factorial Program in Java:

Factorial of a number means the product of all positive descending integers. 
for example: If we want to calculate factorial of 5 then it will be written as 
5 x 4 x 3 x 2 x 1 = 120 . So 120 is the factorial of  5.
  

  Program to Print Factorial of a given number:

Fibonacci Series Program In Java

Fibonacci Series In Java:

The fibonacci series is a series where the next number is the sum of previous two numbers.  
for examples:  0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 etc

above you can see first two numbers of fibonacci series are 0 and 1.

Java program to calculate gross salary of an employee

Ex: Write a java program to calculate gross salary of an employee. How to write a java program to calculate gross salary of an employee using DA and HRA. Java program to calculate gross salary of an employee using DA and HRA.  

We can calculate gross salary   of an  employee using following DA and HRA. The  DA is   20%   of   the   basic   salary   while   the   HRA   is   30%   of   the   basic salary and gross salary is addition of basic salary, DA and HRA.

Java Program to check Given Number is Prime or not

EX: Write a Java Program to check given number is prime or not.


  What is prime number?

Prime number is a number that is greater than 1 and divided by 1 and itself only.
For example: 2, 3, 5, 7, 11, 13, 17, 19, 23... etc. are prime numbers.

Java Program to check Given Number is Palindrome or not

EX: Write a java program to check given number is palindrome or not. How to write a java program to check palindrome number.


  What is Palindrome Number?

A palindrome number is a number that is same after reverse. For example: 252, 676, 77577, 1234321 etc.