Home » core java » Page 30

Tag Archives: core java

Find the maximum of numbers with Math.max in Java

Bipartite Graph

In this example, we shall show you how to find the maximum numbers in Java, using the Math Class and the method Math.max. 1. About Math Class The java.lang.Math class contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. By using the associated functions directly, you can skip creating the logic ...

Read More »

Generate random numbers with Math random

Bipartite Graph

With this example we are going to demonstrate how to generate random numbers using random() method of Math Class. The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. In short, to generate random numbers you should: Call random() API method of Math. This method returns a double value ...

Read More »

Calculate square root in Java with Math sqrt

Bipartite Graph

This is an example of how to calculate the square root in Java, using the sqrt(double a) method of Math Class. The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. Calculating the square root of a number implies that you should: Use the sqrt(double a) method of Math Class. The method gets a double ...

Read More »

Calculate power with Math pow

Bipartite Graph

In this example we shall show you how to calculate the power of a number using the pow(double a, double b)  API method of Math Class. The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. To calculate the power of a number one should perform the following steps: ...

Read More »

Access password protected URL with Authenticator

Bipartite Graph

With this example we are going to demonstrate how to access a password protected URL using the Authenticator Class. The class Authenticator represents an object that knows how to obtain authentication for a network connection. Usually, it will do this by prompting the user for information. Applications use this class by overriding getPasswordAuthentication() in a sub-class. This method will typically ...

Read More »

Read text from URL

Bipartite Graph

This is an example of how to parse text from a URL. The URL Class is used to represent a Uniform Resource Locator, a pointer to a “resource” on the World Wide Web. Parsing text from a URL implies that you should: Create a URL object from the String representation.  Use openStream() API method to open a connection to this ...

Read More »

Parse URL example

Bipartite Graph

In this example we shall show you how to parse a URL. Class URL represents a Uniform Resource Locator, a pointer to a “resource” on the World Wide Web. A resource can be something as simple as a file or a directory, or it can be a reference to a more complicated object, such as a query to a database ...

Read More »

Convert between URL and URI

Bipartite Graph

With this example we are going to demonstrate how to convert between a URL and a URI. Class URL represents a Uniform Resource Locator, a pointer to a “resource” on the World Wide Web. A resource can be something as simple as a file or a directory, or it can be a reference to a more complicated object, such as ...

Read More »

Create Server Socket

Bipartite Graph

This is an example of how to create a ServerSocket. A server socket waits for requests to come in over the network. It performs some operation based on that request, and then possibly returns a result to the requester. Creating a server socket implies that you should: Create a ServerSocket, bound to a specified port. Use accept() API method to ...

Read More »

Write text to Socket

Bipartite Graph

In this example we shall show you how to write text to a Socket. To write text to a Socket one should perform the following steps: Get the output stream of the socket, using getOutputStream() API method of Socket. Create an OutputStreamWriter with the socket ouputstream. Create a BufferedWriter that uses a default-sized output buffer. Use write(String str) API method to ...

Read More »