Programming Articles - Page 2446 of 3363

Python Program for Find the perimeter of a cylinder

Pavitra
Updated on 11-Sep-2019 11:45:20

151 Views

In this article, we will learn about the solution to the problem statement given below −Problem statement − Input diameter and height, find the perimeter of a cylinderPerimeter is nothing but the side view of a cylinder i.e. a rectangleTherefore Perimeter= 2 * ( h + d )here d is the diameter of the cylinderh is the height of the cylinderNow let’s see the implementationExample Live Demo# Function to calculate the perimeter of a cylinder def perimeter( diameter, height ) :    return 2 * ( diameter + height ) # main diameter = 5 ; height = 10 ; print ... Read More

How to display a JRadioButtonMenuItem in Java?

raja
Updated on 03-Jul-2020 12:47:44

1K+ Views

A JRadioButtonMenuItem is a subclass of the JMenuItem class in Java. A JRadioButtonMenuItem is a menu item that is part of a group of menu items in which only one item in the group can be selected and the selected item displays its selected state. We can add multiple radio button menu items to a ButtonGroup object to form a button group. If one radio button menu item in a button group is selected, all other radio button menu items will be unselected.Syntaxpublic class JRadioButtonMenuItem extends JMenuItem implements AccessibleExampleimport javax.swing.*; import java.awt.*; public class JRadioButtonMenuItemTest extends JFrame {    private JMenuBar mb;   ... Read More

How can we use the StringTokenizer class in Java?

raja
Updated on 01-Dec-2023 14:52:22

297 Views

A StringTokenizer is a subclass of Object class and it can allow an application to break a string into tokens. A set of delimiters can be specified either at creation time or on a per-token basis. An instance of StringTokenizer behaves in two ways depending on whether it was created with the returnDelims flag having the value true or false. The object of StringTokenizer internally maintains a current position within the string to be tokenized. The important methods of StringTokenizer c;ass are hasMoreElements(), hasMoreTokens(), nextElement(), nextToken() and countTokens(). Syntax public class StringTokenizer extends Object implements Enumeration Example 1 import java.util.*; public class StringTokenizerTest1 { ... Read More

How can we initialize a boolean array in Java?

Vivek Verma
Updated on 05-May-2025 13:46:37

25K+ Views

Initializing a Boolean Array in Java refers to the process of assigning values (allocating memory) to the Boolean array for the first time. We can initialize an array or any variable - Either at the time of creation. Or, later in the program, using the assignment operator when we are just defining it initially. A Boolean array can be used to store only Boolean values (i.e., either true or false), and the "default value" of each element in a Boolean array is false.  In some cases, we may need to initialize all ... Read More

When can we use the pack() method in Java?

raja
Updated on 03-Jul-2020 12:33:28

5K+ Views

The pack() method is defined in Window class in Java and it sizes the frame so that all its contents are at or above their preferred sizes. An alternative to the pack() method is to establish a frame size explicitly by calling the setSize() or setBounds() methods. In general, using the pack() method is preferable to call than setSize() method, since pack leaves the frame layout manager in charge of the frame size and layout managers are good at adjusting to platform dependencies and other factors that affect the component size.Syntaxpublic void pack()Exampleimport java.awt.*; import javax.swing.*; public class PackMethodTest extends JFrame {    public ... Read More

How to read data from PDF file and display on console in Java?

Maruthi Krishna
Updated on 10-Sep-2019 13:44:22

11K+ Views

There are several libraries to read data from a pdf using Java. Let us see how to read data from a PDF document and display it on the console using a library named PDFBox.You can extract text using the getText() method of the PDFTextStripper class. This class extracts all the text from the given PDF document to use this.Load an existing PDF document using the static method load() of the PDDocument class.Instantiate the PDFTextStripper class.Retrieve.read the contents of the PDF page to a String using the getText() method of the PDFTextStripper class.Finally, close the document using the close() method of ... Read More

How to calculate String Buffer capacity in Java?

Maruthi Krishna
Updated on 10-Sep-2019 13:38:26

1K+ Views

The String class of the java.lang package represents a set of characters. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings objects are immutable, once you create a String object you cannot change their values, if you try to do so instead of changing the value a new object is created with the required value and the reference shifts to the newly created one leaving the previous object unused.The StringBuffer (and StringBuilder) class is used when there is a necessity to make a lot of modifications to a String.Unlike Strings, objects of ... Read More

How can we replace specific part of String and StringBuffer in Java?

Maruthi Krishna
Updated on 10-Sep-2019 13:33:41

332 Views

The String class of the java.lang package represents a set of characters. All string literals in Java programs, such as "abc", are implemented as instances of this class.Example Live Demopublic class StringExample {    public static void main(String[] args) {       String str = new String("Hello how are you");       System.out.println("Contents of the String: "+str);    } }OutputHello how are youStrings objects are immutable, once you create a String object you cannot change their values, if you try to do so instead of changing the value a new object is created with the required value and the ... Read More

How to trim white space in StringBuffer in Java?

Maruthi Krishna
Updated on 10-Sep-2019 13:28:48

3K+ Views

The String class of the java.lang package represents a set of characters. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings objects are immutable, once you create a String object you cannot change their values, if you try to do so instead of changing the value a new object is created with the required value and the reference shifts to the newly created one leaving the previous object unused.The StringBuffer (and StringBuilder) class is used when there is a necessity to make a lot of modifications to a String.Unlike Strings, objects of ... Read More

How can we check if specific string occurs multiple times in another string in Java?

Maruthi Krishna
Updated on 10-Sep-2019 13:24:09

3K+ Views

You can find whether a String contains a specified sequence of characters using any of the methods −The indexOf() method − The indexOf() method of the String class accepts a string value and finds the (starting) index of it in the current String and returns it. This method returns -1 if it doesn’t find the given string in the current one.The contains() method − The contains a () method of the String class accepts a sequence of characters value and verifies whether it exists in the current String. If found it returns true else it returns false.In addition to these, you ... Read More

Advertisements