Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Shriansh Kumar
Page 3 of 22
JavaScript program to retrieve clients IP address
Internet Protocol address, in short, IP address, is a unique address represented by a string of numbers that identifies a device on the internet or a local network. In JavaScript, we can retrieve a client's IP addresses using 3rd party API services such as ipify or ipapi. We can then further use this information to track user locations, personalize content based on the location, or implement security measures. Understanding Client-Side IP Detection JavaScript running in the browser cannot directly access the client's IP address due to security restrictions. However, we can use external APIs that return the public ...
Read MoreJavaScript function to take a number n and generate an array with first n prime numbers
We are required to write a JavaScript function that takes in a number n and returns an array that contains first n prime numbers. We know that prime numbers are those numbers that are only divisible by 1 and themselves like 2, 3, 19, 37, 73 etc. Let's understand the problem with an example − Input: n = 6; Output: prime_numbers = [ 2, 3, 5, 7, 11, 13 ] Using Iteration We will first write a function that checks whether a given number is prime or not and then run a loop ...
Read MoreJavaScript how to get an alert to appear when I click on a button in a class?
An alert in JavaScript is a dialog box that displays important information or warnings to the user. It contains a message with an OK button that dismisses the dialog when clicked. Clicking a button triggers an event handler that invokes a function instructing the browser to display the alert dialog. In this article, we will explore different ways to show an alert when a user clicks on a button in a class. For example, click on the button below to see an alert: .alerttoappear { margin: auto; width: ...
Read MoreDifference Between JSP and PHP
Both JSP and PHP are two popular technologies that serve to create dynamic web pages. Both are similar in the ways that they allow developers to embed code within an HTML document that can interact with databases, sessions, cookies, and other web features. However, they also have some significant differences that may affect the choice of which one to use for a web project. In this article, we will explore the difference between JSP and PHP in terms of their syntax, performance, scalability, security, and compatibility. What is JSP? JSP stands for Java Server Pages and is used ...
Read MoreWhy an interface doesn\'t have a constructor whereas an abstract class have a constructor in Java?
Interfaces in Java are used for defining a contract that classes can implement. They can contain method signatures, default methods, static methods, and constants. we must implement the methods defined in the interface in the implementing class. Constructor in an Interface A Constructor is to initialize the non-static members of a particular class with respect to an object. An Interface in Java doesn't have a constructor because all data members in interfaces are public static final by default, they are constants (assign the values at the time of declaration). There are ...
Read MoreSort an Array of Triplet using Java Comparable and Comparator
In this article, we will create an array of triplet and try to sort them using the Comparable and Comparator interfaces. The term array of triplet means an array having three elements. An Array is a fixed-length linear data structure that stores group of elements with similar datatypes in a sequential manner. Sort an Array of Triplet using Comparator As the name suggests, Comparator is used to compare something. In Java, the Comparator is an interface that can be passed as a parameter to sorting methods like Arrays.sort() or Collections.sort() to sort custom objects. To use it, we need to ...
Read MoreSimple Calculator using TCP in Java
The Internet Protocol suite contains all sort of protocols that enables communication between devices over the Internet. TCP is a connection-oriented protocol, which means it maintains the established connection between two devices till the end of a communication. This is the reason it is used while web surfing, sending emails and transferring files. In this article, we will develop a simple client-server side calculator using TCP in Java. The client will request the operation and the server will send the result to client device after calculating it. Java Networking Let's briefly understand a few basic concepts about Java networking that ...
Read MoreShuffling Elements of Unordered Collections in Java
There are two types of Collections in Java. One is ordered and the other one is unordered collection. The ordered collections store their elements in the order in which they are inserted i.e. it maintains the insertion order of elements. Whereas, the unordered collections such as Map and Set do not maintain any order. In this article, we will create an unordered collection and try to shuffle its elements using the inbuilt method Collections.shuffle(). The Collections.shuffle() Method The Collections.shuffle() method is provided by java.util package. It takes a list as an argument and then rearranges the elements randomly. Therefore, before ...
Read MoreJava Program to Check if a given Class is an Anonymous Class
The type of nested class that has no name is called an anonymous class. Before diving into a Java program to check if a given class is an anonymous class, we need to understand what is a nested class. Let's discuss this in detail. What is a Java Nested Class? A class created within another class in Java is called a nested class. We know that we cannot declare a Java class private, but we can define a nested class as private. There are two types of nested classes in Java: static and non-static. The static nested class is defined ...
Read MoreJava Program to Add the data from the Specified Collection in the Current Collection
In Java, a collection is an object that allows us to group several numbers of objects as a single unit. The Collection interface is the root of the collection framework. We can perform various operations on collection like adding, removing, iterating, searching and retrieving objects. In this article, we will discuss Java programs to add data from the specified collection to the current collection with the help of addAll() method. Using addAll() method of Collection Interface The addAll() method of Collection interface adds data from a specified collection into current collection. It returns a boolean value, which is TRUE if the ...
Read More