Samual Sam has Published 1776 Articles

Character Stream vs Byte Stream in Java

Samual Sam

Samual Sam

Updated on 18-Jun-2020 13:25:51

11K+ Views

Byte StreamsJava byte streams are used to perform input and output of 8-bit bytes. Though there are many classes related to byte streams but the most frequently used classes are, FileInputStream and FileOutputStream. Following is an example which makes use of these two classes to copy an input file into ... Read More

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

956 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

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

752 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

Check if two line segments intersect

Samual Sam

Samual Sam

Updated on 17-Jun-2020 09:40:21

5K+ Views

Let two line-segments are given. The points p1, p2 from the first line segment and q1, q2 from the second line segment. We have to check whether both line segments are intersecting or not.We can say that both line segments are intersecting when these cases are satisfied:When (p1, p2, q1) ... Read More

Advertisements