Java Naming Conventions
Using naming conventions makes the program easier to read and understand
for you and
Using naming conventions makes the program easier to read and understand
for you and
Classes and Objects in Java Java class is a set of related objects. The object(addition a1=new addition();a1 is the object) has some attributes, whose value consists of much of the state of an object. Class is a user-defined data type in Java. The complete set of data and code of an object can be made … Read more
Java program to calculate the area of a rectangle using Scanner classes: import java.util.Scanner; public class Rarea { public static void main(String[] args) { Scanner inn = new Scanner(System.in); double height, width, area; System.out.println(“Area of Rectangle”); System.out.print(“Please enter the height: “); height = inn.nextDouble(); System.out.print(“Please enter the width: “); width = inn.nextDouble(); area = height … Read more
The Event classes represent the events that are generated when an end user interacts with the AWT components. The EventObject class is the superclass for handling all events. The class exists in the package java. util. The AWTEvent class is a subclass of the EventObject class, and all AWT events originate from the AWTEvent class. … Read more
Changing Font and Color in Java Applet To display text(write the text), you must first select a font. A font is specified by its name, such as “Arial”, the style(plain, bold, italic, or bold italics), and the point size. A font is an object in Java, so we need to create it via a call … Read more
The switch statement is a multi-way decision-making statement in which we can select only one . The switch statement starts with the “switch” keyword like (switch(expression)). Switch defines one or more case values which we know as case labels. Case labels consist of case keywords followed by a colon(:), and every case is terminated by … Read more
Daemon Thread in Java There are two types of threads The threads created by the user(create a thread in the program ) are called user threads. The threads that work in the background providing service to others are called Daemon Threads. The two methods used only in the daemon thread, not in the user thread … Read more
Finally, Block in Java Finally blocks(finally{}) are executed once the try block(try{}) exits. This block executes even after unexpected exceptions(errors) have occurred. Irrespective of the try block, the expression in the finally block(finally{}) is always executed. This block(finally{}) is built with the capability of recovering lost data and preventing the leak of resources. On closing … Read more
Add Border to JPanel Borders are basically margined around the edges of a Swing component. Borders are useful for providing titles and empty spaces around components. The setBorder() is used to put a border around a component. Borders in JPanel Example import java.awt.*; import javax.swing.*; import javax.swing.border.*; import java.awt.event.*; public class VariousBorders extends JPanel { … Read more
BorderLayout divides the container into five parts (directions), east, west, north, south, and centre. By using this Layout, we can place AWT components in each part (different locations). BORDER LAYOUT IN JAVA EXAMPLE import java.awt.*; import java.applet.*; public class bordr extends Applet { Button b1,b2,b3,b4,b5; public void init() { b1=new Button(“east”); b1.setBackground(Color.RED); b2=new Button(“west”); … Read more