
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 26504 Articles for Server Side Programming

957 Views
In this article, you will learn to write a program in Java to calculate the sum of squares of first n natural numbers. This program efficiently computes the sum using a mathematical formula − (val * (val + 1) / 2) * (2 * val + 1) / 3 Problem Statement Write a program in Java to calculate the sum of squares of first n natural numbers, where n is a user-defined value. Input val = 8 Output The sum of squares of first 8 natural numbers is204 Steps to calculate sum of squares of first n natural numbers Following are ... Read More

214 Views
To find the smallest K digit number divisible by X, the Java code is as follows −Example Live Demoimport java.io.*; import java.lang.*; public class Demo{ public static double smallest_k(double x_val, double k_val){ double val = 10; double MIN = Math.pow(val, k_val - 1); if (MIN % x_val == 0) return (MIN); else return ((MIN + x_val) - ((MIN + x_val) % x_val)); } public static void main(String[] args){ double x_val = 76; double k_val ... Read More

289 Views
In this article, we will learn how to count the number of elements with odd factors (i.e., perfect squares) in a given range using Java. Perfect squares have odd divisors, and we can calculate them by counting the perfect squares in the specified range. Problem StatementGiven a range defined by a lower and upper bound, write a Java program to calculate how many numbers in this range have odd factors (i.e., perfect squares).Input Lower Range: 55Upper Range: 1000Output The number of elements with odd factors between 55 and 1000 is: 24 Steps to calculate the number of elements with ... Read More

324 Views
In this article, we will learn how to find the nth multiple of a given number in the Fibonacci series using Java. The Fibonacci series is a sequence where each number is the sum of the two preceding ones. We will use loops, conditional statements, and the modulus operator to find the position of the nth multiple of a specific number in the series. Problem StatementGiven a number and its multiple positions, find the position of the nth multiple of a number in the Fibonacci series. Input A number whose multiple is to be found: 9The nth ... Read More

397 Views
When ‘public’ is used in ‘main’ −Example Live Demopublic class Demo{ public static void main(String args[]){ System.out.println("This is a sample only"); } }OutputThis is a sample onlyA class named Demo contains the main function that is public. It has a print function, which successfully compiles, executes and prints the message on the console.When ‘public’ is replaced with ‘private’Example Live Demopublic class Demo{ private static void main(String args[]){ System.out.println("This is a sample only"); } }OutputError: Main method not found in class Demo, please define the main method as: public static void main(String[] args) ... Read More

1K+ Views
To replace null values with default value in Java Map, the code is as follows −Example Live Demoimport java.util.*; import java.util.stream.*; public class Demo{ public static Map null_vals(Map my_map, T def_val){ my_map = my_map.entrySet().stream().map(entry -> { if (entry.getValue() == null) entry.setValue(def_val); return entry; }) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); return my_map; } public static void main(String[] args){ Map my_map = new HashMap(); my_map.put(1, null); my_map.put(2, 56); ... Read More

1K+ Views
Static variable: Declared with the help of the keyword ‘static’, they are also known as class variables. They are defined within a constructor or outside a class function. When a variable is static, it is shared between all objects of the class, irrespective of the number of objects that are created.Demonstrating how the ‘static’ keyword, when used with variable works −Example Live Demopublic class Demo{ String name; static String designation; public void display_data(){ System.out.println("The name is: " + name); System.out.println("The designation of this team members is : " + designation); } ... Read More

2K+ Views
To find the IP Address of the client, the Java code is as follows −Example Live Demoimport java.net.*; import java.io.*; import java.util.*; import java.net.InetAddress; public class Demo{ public static void main(String args[]) throws Exception{ InetAddress my_localhost = InetAddress.getLocalHost(); System.out.println("The IP Address of client is : " + (my_localhost.getHostAddress()).trim()); String my_system_address = ""; try{ URL my_url = new URL("http://bot.whatismyipaddress.com"); BufferedReader my_br = new BufferedReader(new InputStreamReader(my_url.openStream())); my_system_address = my_br.readLine().trim(); } ... Read More

2K+ Views
You are given a String, your task is to write a program in Java that checks the order of its characters. If the order is previously defined, you have to check if the characters are in the given order otherwise check for alphabetical order. Let's understand the problem statement with an example − Example Scenario: Input: str = "abcmnqxz"; Output: res = TRUE The given string is in alphabetical order. Using Iteration In this approach, use a for loop to iterate over the string and check if the value of character at the current place and the previous ... Read More

2K+ Views
In this article, we will learn to print common characters of two strings in alphabetical order using Java. The program uses arrays to count how often each letter appears in both strings and then compares these counts to identify the common characters. Problem Statement Write a Java program to print common characters of two strings in alphabetical order − Input my_str_1 = "itsasample" my_str_2 = "thisisasample" Output The common characters between the two strings in alphabetical order is :aaeilmpsst Steps to print common characters of two strings in alphabetical order Following are the steps to print common characters of two strings ... Read More