Java Articles

Page 187 of 450

Difference between mutable and immutable object

Aishwarya Naglot
Aishwarya Naglot
Updated on 10-Oct-2024 5K+ Views

In Java, state of the immutable object can’t be modified after it is created but definitely reference other objects. They are very useful in multi-threading environment because multiple threads can’t change the state of the object so immutable objects are thread-safe. Immutable objects are very helpful to avoid temporal coupling and always have failure atomicity and also helpful in multiple threading. Why though? because no one can change the object right? So, it becomes thread-safe, it means it will not cause any unexpected issues when different parts of the program are trying to access that particular object. On the other ...

Read More

Difference between Applets and Servlets in Java.

Aishwarya Naglot
Aishwarya Naglot
Updated on 10-Oct-2024 6K+ Views

In Java, both Applets and Servlets are the programs or applications that run in a Java environment. Applets are designed to provide interactive features that can be embedded into web pages and allow users to engage with content directly through their web browsers. On the other hand, Servlets operate on the server side, they handle requests and responses, which is most important for generating dynamic content in web applications. The main difference in both programs is that their processing is done in different environments. Difference between Applets and Servlets Some of the major differences between Applets and Servlets are as ...

Read More

Java program to remove path information from a filename returning only its file component

Samual Sam
Samual Sam
Updated on 10-Oct-2024 2K+ Views

In this article, we will learn to remove path information from a filename returning only its file component using Java. The method fileCompinent() is used to remove the path information from a filename and return only its file component. This method requires a single parameter i.e. the file name and it returns the file component only of the file name. Problem Statement Write a program in Java to remove path information from a filename returning only its file component − Input "c:\JavaProgram\demo1.txt" The input is the file path. Output demo1.txt Steps to remove path information Following are the steps to remove ...

Read More

Java program to interchange elements of first and last in a matrix across columns

AmitDiwan
AmitDiwan
Updated on 10-Oct-2024 832 Views

In this article, we will understand how to interchange elements of first and last in a matrix across columns in Java. The matrix has a row and column arrangement of its elements. A matrix with m rows and n columns can be called as m × n matrix. Individual entries in the matrix are called elements and can be represented by a[i][j] which suggests that the element a is present in the ith row and jth column. Problem Statement Write a Java program to interchange elements of first and last in a matrix across columns. Input  The matrix is defined as: ...

Read More

Java program to select all the items in a JList

Krantik Chavan
Krantik Chavan
Updated on 10-Oct-2024 983 Views

In this article, we will learn how to select all the items in a JList in Java. The program creates a simple graphical user interface with a list of sports. It uses the setSelectionInterval() method to select all items in the list. This ensures that from the first item to the last item in the list, everything is selected when the program runs. Problem Statement Write a Java program to select all the items in a JList. Below is the demonstration of the same − Input sports[]= {"Football", "Fencing", "Cricket", "Squash", "Hockey", "Rugby"} Output Steps to select all ...

Read More

Java Program to insert an element at the Bottom of a Stack

Aishwarya Naglot
Aishwarya Naglot
Updated on 04-Oct-2024 575 Views

A stack is a data structure that follows the LIFO (Last In, First Out) principle. In other words, The last element we add to a stack is the first one to be removed. When we add (or push) elements to a stack, they are placed on top; i.e. above all the previously-added elements. There may be certain scenarios where we need to add an element at the bottom of the stack. There are multiple ways to add an element to the bottom of the stack. they are − Using Auxiliary Stack ...

Read More

Java Program to display upper triangular matrix

Shriansh Kumar
Shriansh Kumar
Updated on 30-Sep-2024 1K+ Views

In this article, we will understand how to display an upper triangular matrix of a given matrix in Java. A matrix has row and column arrangement of its elements. A matrix with m rows and n columns can be called as m × n matrix. And, the term upper triangular matrix refers to a matrix whose all elements below the main diagonal are 0. Example Scenario: Input: matrix = { 2, 1, 4 }, { 1, 2, 3 }, { 3, 6, 2 } Output: upptri_mat = 2 1 4 0 2 3 0 0 2 Using ...

Read More

Java program to check order of characters in string

Shriansh Kumar
Shriansh Kumar
Updated on 30-Sep-2024 2K+ Views

You are given a String, your task is to write a program in Java that checks the order of its characters. If the order is previously defined, you have to check if the characters are in the given order otherwise check for alphabetical order. Let's understand the problem statement with an example − Example Scenario: Input: str = "abcmnqxz"; Output: res = TRUE The given string is in alphabetical order. Using Iteration In this approach, use a for loop to iterate over the string and check if the value of character at the current place and the previous ...

Read More

Java regex to exclude a specific String constant

Arnab Chakraborty
Arnab Chakraborty
Updated on 29-Sep-2024 2K+ Views

In this program, we will use a regular expression to check if a given string does not contain the substring "kk" using Java. The regular expression ^((?!kk).)*$ is designed to match strings that do not include the "kk" pattern anywhere in the string. The program will evaluate a sample string and print whether or not it contains "kk". Problem Statement Write a program in Java for checking whether a given string contains the substring "kk." If the string does not contain "kk" the program will return true otherwise it will return false. Input String s = "tutorials" Output true ...

Read More

Java regex to exclude a specific String constant

Arnab Chakraborty
Arnab Chakraborty
Updated on 29-Sep-2024 2K+ Views

In this program, we will use a regular expression to check if a given string does not contain the substring "kk" using Java. The regular expression ^((?!kk).)*$ is designed to match strings that do not include the "kk" pattern anywhere in the string. The program will evaluate a sample string and print whether or not it contains "kk". Problem Statement Write a program in Java for checking whether a given string contains the substring "kk." If the string does not contain "kk" the program will return true otherwise it will return false. Input String s = "tutorials" Output true ...

Read More
Showing 1861–1870 of 4,498 articles
« Prev 1 185 186 187 188 189 450 Next »
Advertisements