
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7442 Articles for Java

17K+ Views
Declaring Multiple Classes in Java Program A single Java program may contain two or more classes, it is possible in two ways: Multiple non-nested classes Nested classes The Multiple non-nested Classes We can create as many classes as we want in a single Java program but writing many classes in a single file is not recommended as it makes code difficult to read rather we can create a single file for every class. When we compile a Java program with two or more classes (non-nested), the same number of .class ... Read More

4K+ Views
Method overriding works because of the run-time method binding feature in Java. So, if we force the Java compiler to do static binding for a method then we can prevent that method from being overridden in a derived class. Preventing Method Overriding in Java We can prevent method overriding in Java in 3 ways: By declaring a method as "final" in the base class By declaring a method as "static" in the base class By declaring a method as "private" in the base class Final Methods cannot be Overridden ... Read More

3K+ Views
To append text to JTextArea, use the component’s append() method. Let’sa say the following is our text in the JTextArea -JTextArea textArea = new JTextArea("The text added here is just for demo. "+ "This demonstrates the usage of JTextArea in Java. ");Now, append text to the same textArea -textArea.append("In this example we have deleted some text from the beginning."+ "We have also appended some text.");The following is an example to append text to JTextArea -Examplepackage my; import java.awt.GridLayout; import javax.swing.*; public class SwingDemo { SwingDemo() { JFrame frame = new JFrame("Demo"); JTextArea textArea ... Read More

4K+ Views
The Java team and developer community suggest us to follow naming conventions. They are just conventions and are not mandatory but help in writing Java programs that are more understandable and easier to read. For example, class names should generally be nouns, and interface names should be adjectives. Additionally, capitalize the first letter of each separate word. The names used for classes, variables, and methods are called identifiers. Need to Follow Java Naming Conventions Following are the reasons to follow naming conventions: Multiple developers work on the same project simultaneously. Names that follow naming standards reduce ... Read More

15K+ Views
The default and parameterized constructors are two types of Constructor in Java. The constructor is a special member of a Java class whose name is the same as the class name. It is used to assign values to a class variable at the time of object creation. In this article, we are going to discuss the difference between default and parameterized constructors. Default Constructor When we do not add a constructor to a Java class. The compiler adds a default constructor implicitly. It accepts 0 arguments. If we do not initialize the instance variables of a class, a default constructor will ... Read More

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

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

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

117 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

190 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