Samual Sam has Published 2492 Articles

Can we override private methods in Java

Samual Sam

Samual Sam

Updated on 18-Jun-2020 13:35:44

971 Views

Ideally No. But, using the tricky code, a subclass can override a private method as well. See the example below −ExampleLive Democlass A {    private void display() {       System.out.println("A.display");    }     public void callDisplay() {       System.out.println("A.callDisplay");       display();   ... Read More

Character Stream vs Byte Stream in Java

Samual Sam

Samual Sam

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

8K+ 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

Check if a file is hidden in Java

Samual Sam

Samual Sam

Updated on 18-Jun-2020 13:15:46

124 Views

The java.io.File class provides useful methods on file. This example shows how to check a file hidden or not by using the file.isHidden() method of File class.Exampleimport java.io.File; public class Main {    public static void main(String[] args) {       File file = new File("C:/java.txt");     ... Read More

Checking internet connectivity in Java

Samual Sam

Samual Sam

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

5K+ 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

C/C++ Pointers vs Java references

Samual Sam

Samual Sam

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

2K+ Views

PointersIn C, C++ programming languages, a pointer is a variable that holds the address of another variable.example#include using namespace std;   int main() {    //int variable    int i = 8;    //pointer variable    int * pI;    //assign the address of i to its pointer    pI = &i;    //print the number    cout

Callback using Interfaces in Java

Samual Sam

Samual Sam

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

3K+ 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

618 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

384 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

7K+ 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

Can we change Python for loop range (higher limit) at runtime?

Samual Sam

Samual Sam

Updated on 17-Jun-2020 12:27:13

313 Views

No, You can't modify a range once it is created. Instead what you can do is use a while loop instead. For example, if you have some code like:for i in range(lower_limit, higher_limit, step_size):# some code if i == 10:    higher_limit = higher_limit + 5You can change it to:i ... Read More

Advertisements