Object Oriented Programming Articles

Page 337 of 589

Difference between Iterator and Enumeration in Java

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

Iterator and Enumeration are both cursors to traverse and access elements from the collection. They both belong to the collection framework. Enumeration was added in JDK1.0 and Iterator in JDK 1.2 version in the collection framework.  Java Enumeration Enumeration: An enumeration is a special "class" that indicates a collection of constants. Enumeration can’t make structural changes in the collection because it has read-only access to its elements. It has the following methods − hasMoreElements(): The hasMoreElements() method checks to see if more elements exist in the underlying collection class nextElement(): The ...

Read More

nDifference between Save and SaveAndFlush in Spring Java

Teja Kolloju
Teja Kolloju
Updated on 17-Apr-2025 6K+ Views

Save and SaveAndFlush both can be used for saving entities. They both are both belong to the Spring data library. Save may or may not write your changes to the DB straight away. When we call saveAndFlush system is enforcing the synchronization of your model state with the DB. What is the save method? The save method is used to store an entity in the database. It adds the entity to the transactional buffer, and when the transaction is committed, the data is saved. It then returns the stored entity. Example The following is an example of the save method ...

Read More

Difference between fail-fast and fail safe in Java

Teja Kolloju
Teja Kolloju
Updated on 17-Apr-2025 5K+ Views

In this article, we will find the differences between Fail-Fast and Fail-Safe Iterators. They both describe how collections behave when they are modified during iteration. What is an iterator? An Iterator is an object in Java used to cycle through a collection, accessing or removing elements. It can be obtained by using the iterator() method of a collection. What is FailSafe? Fail-safe also called a Non-Fail-fast Iterator, does not throw ConcurrentModificationException. It works on a copy of the collection. Any changes made in the iterator only affect the copy but not the original collection. Example The following is an ...

Read More

Difference between volatile and transient in java

Teja Kolloju
Teja Kolloju
Updated on 17-Apr-2025 11K+ Views

In this article, we will find the differences between volatile and Transient. Both have a different purpose for specifying before a variable. These modifiers are important in determining the behavior and characteristics of variables in different cases. What is volatile? A volatile keyword is used in a multithreading environment where two threads reading and writing the same variable simultaneously. The volatile keyword flushes the changes directly to the main memory instead of the CPU cache.  Example of Volatile The following is an example of Volatile in Java: public class VolatileExmaple extends Thread { volatile boolean isRunning ...

Read More

Difference Between CrudRepository and JPARepository in Java

Teja Kolloju
Teja Kolloju
Updated on 17-Apr-2025 24K+ Views

CrudRepository and JPA repository both are the interface of the spring data repository library. Spring data repository reduces the boilerplate code by providing some predefined finders to access the data layer for various persistence layers. What is JPA repository? JPA is a repository interface that extends CrudRepository and PagingAndSorting repository. It inherits some finders from crud repository such as findOne, gets and removes an entity. It also provides some extra methods related to JPA such as delete records in batch, flushing data directly to a database base and methods related to pagination and sorting. We need to extend this repository ...

Read More

Can we overload or override a static method in Java?

Shriansh Kumar
Shriansh Kumar
Updated on 16-Apr-2025 5K+ Views

In Java, you cannot override static methods but you can overload them. Overloading a static method is allowed because the JVM determines which method to call at compile time based on the method signature, rather than the object's type. However, overriding is not allowed for static methods because an overridden method is called based on the object's type. In this article, we are going to discuss is it possible to overload and override a static method in Java. Also, we will understand static methods, method overloading and method overriding. What is a Static Method? A method defined using the static ...

Read More

What are the differences between JRadioButton and JCheckBox in Java?

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

Both JRadioButton and JCheckBox components can extend the JToggleButton class in Java, the main difference is that JRadioButton is a group of buttons in which only one button can be selected at a time, whereas JCheckBox is a group of checkboxes in which multiple items can be selected at a time. JRadioButton A JRadioButton is a component that represents an item with a state selected or unselected. Usually, a group of radio buttons is created to provide options to the user, but only one option can be selected at a time. JRadioButton will generate an ActionListener, ChangeListener, and ItemListener interfaces.  Instantiating JRadioButton: JRadioButton Radio_Name = new JRadioButton(); ...

Read More

How can we create a login form in Java?

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

We can develop a login form in Java using Java Swing technology. In this example, we can create two labels username and password, two text fields for the user to enter valid credentials,  and finally, one submit button. Once the user is able to enter the valid credentials in the two text fields, we can able to see Hello admin in the login form. Setting Up the Project We’ll use Java Swing, a GUI toolkit for building desktop applications. Required Libraries are: javax.swing.* (for Swing components) java.awt.* (for layout management) ...

Read More

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 581 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
Showing 3361–3370 of 5,881 articles
« Prev 1 335 336 337 338 339 589 Next »
Advertisements