Articles on Trending Technologies

Technical articles with clear explanations and examples

Can we change the order of public static void main() to static public void main() in Java?

Alshifa Hasnain
Alshifa Hasnain
Updated on 16-Apr-2025 4K+ Views

Yes, we can change the order of public static void main() to static public void main() in Java, the compiler doesn't throw any compile-time error or runtime error. In Java, we can declare access modifiers in any order, the method name comes last, the return type comes second to last and then after it's our choice. But it's recommended to put access modifier (public, private and protected) at the forefront as per Java coding standards. Java Method Modifiers and Their Order Java allows you to place method modifiers (the keyword "public, " "static, " "final, " etc.) in various orders. The Java ...

Read More

What are the key steps in read/write from/to a URL connection in java?

Maruthi Krishna
Maruthi Krishna
Updated on 16-Apr-2025 607 Views

The URL class in the java.net package represents a web address or URL (Uniform Resource Locator), which points to a web resource such as a file, page, or directory in the World Wide Web (internet). The URL class provides various constructors, one of which accepts a String parameter (representing a URL) and constructs an object of the URL class. Reading From a URL You can read content from a URL using the openStream() method. This method opens a connection to the web address specified by the current URL object and gives you an InputStream object. The Java InputStream is an ...

Read More

Java program to find Largest, Smallest, Second Largest, Second Smallest in an array

Ashin Vincent
Ashin Vincent
Updated on 16-Apr-2025 5K+ Views

In this problem we are given an array of numbers, and we have to find the largest, smallest, second largest, and second smallest elements in an array in Java. Let’s understand the problem better with the help of an example: Input int arr[] = {55, 10, 8, 90, 43, 87, 95, 25, 50, 12}; Output Smallest element = 8 2nd Smallest element = 10 Largest element = 95 2nd Largest element = 90 To solve this problem, use the following approaches: Using Arrays.sort() Using nested for-loops Optimized one-pass approach Using Arrays.sort() In this ...

Read More

Find average of a list in Java

Ashin Vincent
Ashin Vincent
Updated on 16-Apr-2025 1K+ Views

Given a list of numbers, our task is to calculate the average of this list. The average of a list can be found by adding all the elements in the list and dividing the sum by the total number of elements. In this article we will learn different methods to implement this in Java. There are multiple ways in Java to find the average of a list. In this article we will explore two different approaches: Using Java Streams Using for loop Find Average of a List Using Java Streams This approach shows how to find ...

Read More

Difference between Scanner and BufferReader Class in Java

Ashin Vincent
Ashin Vincent
Updated on 16-Apr-2025 13K+ Views

Scanner and BufferedReader classes are used to read input from an external system. Scanner is normally used when we know input is of type string or of primitive types, and BufferedReader is used to read text from character streams while buffering the characters for efficient reading of characters. What is Scanner Class? The Scanner class is included in the java.util package. It is mostly used when the data type of the input is already known. We commonly use it with data ty+pes like strings, integers, floats, and booleans. It has built-in methods like nextInt(), nextDouble(), and nextLine() that help ...

Read More

Differences between abstract class and concrete class in Java

Ashin Vincent
Ashin Vincent
Updated on 16-Apr-2025 13K+ Views

Abstract class and concrete class are fundamental concepts of object oriented programming in Java. In this article, we will learn the differences between an abstract class and concrete class. What is an Abstract Class? An abstract class is a class that cannot be used to create objects. It can only be accessed using its subclasses. It can contain abstract methods, which are methods without a body. It acts as a blueprint for its subclasses. It can also contain concrete or regular methods. Example This example shows how to implement an abstract class in java: ...

Read More

Difference between Claude 3.7 Sonnet and ChatGPT 4.0

Hornet dynamics
Hornet dynamics
Updated on 16-Apr-2025 281 Views

Claude 3.7 Sonnet and ChatGPT 4.0 are popular AI tools that are used for content generation, image generation, and more. Claude 3.7 Sonnet is used mainly very strong at coding, math, logical reasoning, while ChatGPT 4.0 is often better at natural language understanding and creative writing. In this article, we will discuss the important differences between Claude 3.7 Sonnet and ChatGPT 4.0. But before discussing the differences, let us first discuss their basics. What is a Claude 3.7 Sonnet? Cloud 3.7 is a new AI model tool launched by Anthropic in February 2025. This is one of its most innovative ...

Read More

What are the differences between paint() method and repaint() method in Java?

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Apr-2025 7K+ Views

In this article, we will learn about the differences between the paint() method and the repaint() method in Java. In the AWT and Swing frameworks, rendering graphical components is done in two different roles by the two methods paint() and repaint(). The paint() Method This method holds instructions to paint this component. In Java Swing, we can change the paintComponent() method instead of paint() method as paint calls paintBorder(), paintComponent() and paintChildren() methods. We cannot call this method directly instead we can call repaint(). Syntax The following is the syntax: public void paint(Graphics g) { // paint() method ...

Read More

How can we minimize/maximize a JFrame programmatically in Java?

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Apr-2025 5K+ Views

In this article, we will learn to minimize/maximize a JFrame programmatically in Java. In Swing, programmers often need to resize the window as needed. For example, they can shrink the window when carrying out background tasks or expand the window size for a better full-screen experience. What is a JFrame? A JFrame class is a subclass of Frame class and the components added to a frame are referred to as its contents, these are managed by the contentPane. A JFrame contains a window with title, border, (optional) menu bar and user-specific components. By default, we can minimize a JFrame by ...

Read More

Difference between Stack and Heap memory in Java

Teja Kolloju
Teja Kolloju
Updated on 15-Apr-2025 7K+ Views

JVM has divided memory space between two parts: one is Stack and another one is Heap space. Stack space is mainly used for storing order of method execution and local variables. Stacks always store blocks in LIFO order whereas heap memory uses dynamic allocation for allocating and deallocating memory blocks.  Memory allocated to the heap lives until one of the following events occurs : Program terminated  Memory free  What is a Heap memory? Heap memory is allocated for storing objects, arrays, and JRE (Java Runtime Environment) classes. Memory may be ...

Read More
Showing 31141–31150 of 61,297 articles
Advertisements