Programming Articles - Page 2577 of 3366

What are the different types of classes in Java?

Shriansh Kumar
Updated on 21-May-2025 16:09:47

3K+ Views

In Java, a class is a datatype which defines properties (variables) and behaviors (methods) of an object. Defining an object does not consume memory; only its object or instance does.Depending on the requirement, we will create various types of classes in Java. In this article, we are going to discuss them. Types of classes in Java The Java class is classified into different types based on its methods, as shown in the list given below: Concrete class Abstract class Final class POJO class Static class Inner Class Wrapper Class Singleton Class Concrete class Any normal class which does ... Read More

Why Object class is the super class for all classes in Java?

Shriansh Kumar
Updated on 30-May-2025 17:21:43

4K+ Views

The java.lang.Object class is the root or superclass of the class hierarchy, it belongs to the java.lang package. All predefined classes and user-defined classes are direct or indirect subclasses of the Object class. Why is Object Class a Superclass? To understand why the Object class is the superclass of every class in Java, we need to understand why a superclass is needed in the first place: To share common properties. To accept and return any type of object. Sharing Common Properties using Object Class There are 11 common properties that every ... Read More

Explain final class and final method in PHP.

Alok Prasad
Updated on 30-Jul-2019 22:30:26

2K+ Views

The final keyword is introduced by PHP5 related to the object-oriented programming concept.But before we move on to the final, we need to ensure that we have a good understanding of the inheritance concept. In inheritance, we can inherit a class from another class. Also, we can override a function in an inherited class, to replace the behavior originally provided. In some cases, we might need to keep a class from being inherited from or we may need to prevent a function to be overridden. This can be achieved with the final, by prefixing the class and function with the ... Read More

Can we declare the main () method as final in Java?

raja
Updated on 06-Feb-2020 11:11:06

5K+ Views

Yes, we can declare the main () method as final in Java. The compiler does not throw any error.If we declare any method as final by placing the final keyword then that method becomes the final method.The main use of the final method in Java is they are not overridden.We can not override final methods in subclasses.If we are using inheritance and we need some methods not to overridden in subclasses then we need to make it final so that those methods can't be overridden by subclasses.We can access final methods in the subclass but we can not override final methods.Exampleclass BaseClass ... Read More

How can I set scrollbars to never appear in Java?

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

123 Views

To set scrollbars to never appear, use the JScrollPane.HORIZONTAL_SCROLLBAR_NEVER and JScrollPane.VERTICAL_SCROLLBAR_NEVER. Let’s say you created a Box with some button components. Now, create a JScrollPane:JScrollPane scrollPane = new JScrollPane();Set the Viewport view as Box:scrollPane.setViewportView(box);Now, set the scrollbars to never appear:scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);The following is an example to set scrollbars to never appear:Examplepackage my; import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.Box; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JScrollPane; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Demo");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       JButton button1 = new JButton("One");       JButton button2 ... Read More

How to determine whether the JSlider is currently snapping to tick marks in Java?

Chandu yadav
Updated on 30-Jul-2019 22:30:26

194 Views

At first, we will create a slider and set it to snap to tick marks:JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 40); slider.setMinorTickSpacing(10); slider.setMajorTickSpacing(20); slider.setPaintTicks(true); slider.setPaintLabels(true); slider.setSnapToTicks(true);After that, we will check whether the slider is currently snapping to tick marks. The result would be displayed in the TRUE/FALSE booleanslider.getSnapToTicks()Display the result in the Console as shown below:System.out.println("Snapping to tick marks? = "+slider.getSnapToTicks());The following is an example to determine whether the slider is currently snapping to tick marks:Examplepackage my; import java.awt.Color; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JSlider; import javax.swing.WindowConstants; public class SwingDemo {    public static void main(String[] args) ... Read More

How to enable the display of hidden files in a JFileChooser in Java?

Arjun Thakur
Updated on 30-Jul-2019 22:30:26

368 Views

Set the following to FALSE to enable the display of hidden files −JFileChooser file = new JFileChooser(); file.setFileHidingEnabled(false);The following is an example to enable the display of hidden files in a JFileChooser −Examplepackage my; import javax.swing.JFileChooser; public class SwingDemo {    public static void main(String[] args) {       JFileChooser file = new JFileChooser();       file.setMultiSelectionEnabled(false);       file.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);       file.setFileHidingEnabled(false);       int res = file.showOpenDialog(null);       if (res == JFileChooser.APPROVE_OPTION) {          java.io.File f = file.getSelectedFile();          System.err.println(f.getPath());       }   ... Read More

Customize the tooltip font, color , background and foreground color in Java

George John
Updated on 30-Jul-2019 22:30:26

2K+ Views

To customize the tooltip font, color and background, use UIManager.UIManager.put("ToolTip.background", Color.ORANGE); UIManager.put("ToolTip.foreground", Color.BLACK); UIManager.put("ToolTip.font", new Font("Arial", Font.BOLD, 14));Above, we have set the font with −Tooltip.fontWe have set the foreground and background color with the following above −ToolTip.foreground ToolTip.backgroundThe following is an example to customize tooltip −Examplepackage my; import java.awt.Color; import java.awt.Font; import java.awt.GraphicsEnvironment; import java.awt.GridLayout; import java.awt.Point; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; import javax.swing.SwingConstants; import javax.swing.UIManager; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame.setDefaultLookAndFeelDecorated(true);       JFrame frame = new JFrame("Register!");       JLabel label1, label2, ... Read More

Make the JSlider vertical and move top-to-bottom in Java

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

270 Views

To set the JSlider to be vertical, use the VERTICAL constant while creating the slider −JSlider slider = new JSlider(JSlider.VERTICAL, 0, 100, 60);Now, for the inverted slider i.e. moving from top-to-bottom −slider.setInverted(true);The following is an example to set the slider vertical and move top-to-bottom −Examplepackage my; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JSlider; import javax.swing.WindowConstants; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame("Frame with Slider");       JSlider slider = new JSlider(JSlider.VERTICAL, 0, 100, 60);       slider.setInverted(true);       slider.setMinorTickSpacing(5);       slider.setMajorTickSpacing(20);     ... Read More

How to display the vertical and horizontal scrollbars always even if it is not required

Chandu yadav
Updated on 30-Jul-2019 22:30:26

114 Views

Use the following constants for the JScrollBar to display the vertical and horizontal scrollbars always even if it is not required −scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);The following is an example to display the vertical and horizontal scrollbars always even if it is not required −Examplepackage my; import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.Box; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JScrollPane; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Demo");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       JButton button1 = new JButton("Questions and Answers");       JButton button2 = new JButton("Videos");       JButton ... Read More

Advertisements