Samual Sam has Published 2310 Articles

Checking internet connectivity in Java

Samual Sam

Samual Sam

Updated on 18-Jun-2020 13:09:30

6K+ Views

Internet connectivity can be checked using java.net.URL and java.net.URLConnection class. Following are the required steps.Create a URL object and pass it the URL say GoogleCall URL.openConnection() method to get a URLConnection object.Call URLConnection.connect() method to check the internet connectivity. connect() method opens a communications link to the resource referenced by ... Read More

Callback using Interfaces in Java

Samual Sam

Samual Sam

Updated on 18-Jun-2020 12:29:08

4K+ Views

In the case of Event-driven programming, we pass a reference to a function which will get called when an event occurs. This mechanism is termed as a callback. Java does not support function pointers. So we can not implement the same direction. But using interfaces we can achieve the same ... Read More

Automatic resource management in Java

Samual Sam

Samual Sam

Updated on 18-Jun-2020 12:13:37

868 Views

automatic resource management or try-with-resources is a new exception handling mechanism that was introduced in Java 7, which automatically closes the resources used within the try-catch block.ResourceA resource is an object which is required to be closed once our program finishes. For example, a file is read, database connection and ... Read More

Array To Stream in Java

Samual Sam

Samual Sam

Updated on 18-Jun-2020 10:53:23

500 Views

With Java 8, Arrays class has a stream() methods to generate a Stream using the passed array as its source.DescriptionThe java.util.Arrays.stream() method returns a sequential Stream with the specified array as its source. −Arrays.stream(array)DeclarationFollowing is the declaration for java.util.Arrays.stream() methodpublic static Stream stream(T[] array)Type ParameterT − This is the type ... Read More

Association, Composition and Aggregation in Java

Samual Sam

Samual Sam

Updated on 18-Jun-2020 10:41:15

9K+ Views

AssociationAssociation refers to the relationship between multiple objects. It refers to how objects are related to each other and how they are using each other's functionality. Composition and aggregation are two types of association.CompositionThe composition is the strong type of association. An association is said to composition if an Object ... Read More

How to create Python dictionary from the value of another dictionary?

Samual Sam

Samual Sam

Updated on 17-Jun-2020 11:11:54

2K+ Views

You can do this by merging the other dictionary to the first dictionary. In Python 3.5+, you can use the ** operator to unpack a dictionary and combine multiple dictionaries using the following syntax −Syntaxa = {'foo': 125} b = {'bar': "hello"} c = {**a, **b} print(c)OutputThis will give the ... Read More

Magic Square

Samual Sam

Samual Sam

Updated on 17-Jun-2020 10:16:55

6K+ Views

The magic square is a square matrix, whose order is odd and where the sum of the elements for each row or each column or each diagonal is same. The sum of each row or each column or each diagonal can be found using this formula. n(n2+ 1)/2Here are the rules ... Read More

Polynomial Time Approximation Scheme

Samual Sam

Samual Sam

Updated on 17-Jun-2020 10:07:44

1K+ Views

Polynomial Time Approximation schemeWe can find some polynomial time solution for NP-Complete problems like 0-1 Knapsack problem or Subset sum problem. These problems are very popular in the real world, so there must be some ways to handle these problems.The Polynomial Time Approximation Scheme (PTAS) is a type to approximate ... Read More

Lexicographically minimum string rotation

Samual Sam

Samual Sam

Updated on 17-Jun-2020 10:03:27

691 Views

Let us consider a string is given, we know that the string is a sequence of characters. The Lexicographical rotation is the rotation of string, to convert characters in lexicographical order.The solution is simple, we simply concatenate the given string with itself, then in another array, all rotation of strings ... Read More

Nuts and Bolt Problem

Samual Sam

Samual Sam

Updated on 17-Jun-2020 09:56:52

2K+ Views

A list of different nuts and another list of bolts are given. Our task is to find the correct match of nuts and bolts from the given list, and assign that nut with the Bolt, when it is matched.This problem is solved by the quick-sort technique. By taking the last ... Read More

Advertisements