Tagged: java

How to overload java methods by changing data type 0

How to overload java methods by changing data type

Below code shows how to overload java method by changing data type.See also Overloading java methods by changing the number of arguments.   public class MethodOverload { public void sumNumbers(int num1,int num2) { int...

How to overload java methods by changing number of arguments 0

How to overload java methods by changing number of arguments

The main reason why programmers overload methods are for easier readability.Think of a scenario where you have a method to multiply two numbers and another method multiply three numbers.These methods will have different names.Instead...

Java program that takes two numbers as input  from a user and displays the product of two numbers. 0

Java program that takes two numbers as input from a user and displays the product of two numbers.

Below Java program code takes two integers from the user , multiplies  them and display import java.util.Scanner; public class JavaMultiply { public static void main(String args[]) { Scanner in = new Scanner(System.in); System.out.print(“Input first...

Java program to divide two numbers and print on the screen 0

Java program to divide two numbers and print on the screen

Below java program code divided two numbers and prints the output on the screen. /** * * @author Eric * site www.techoverload.net */ public class JavaDivide { public static void main(String args[]) { int...

Write a Java program to print the sum of two numbers 0

Write a Java program to print the sum of two numbers

Below java program code prints sum of two numbers and displays the result. /** * * @author Eric * site www.techoverload.net */ public class JavaSum { public static void main(String args[]) { int num1=20;...

Write a Java program to display “Hello world” 0

Write a Java program to display “Hello world”

Below java program code is used to display “Hello World”  and print your name in a seperate line. /** * * @author Eric * Site:www.techoverload.net */ public class JavaHelloWord { public static void main(String...

How to connect to a mysql database using com.mysql.jdbc.Driver 0

How to connect to a mysql database using com.mysql.jdbc.Driver

Below code shows how to connect to a MySQL database using com.mysql.jdbc.Driver. import java.sql.DriverManager; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import javax.swing.JOptionPane; public class DbConnection { public Connection con; public Connection dbConnect(){ try {...

Java JLabel setBorder() Method Example 0

Java JLabel setBorder () Method Example

Below code shows how to use Java JLabel setBorder ()  Method Example import java.awt.Color; import java.awt.FlowLayout; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; /** * * @author acer */ public class JLabelExample { JLabelExample(){ JFrame frame=new JFrame();...

How to create a simple JLabel with Text 0

How to create a simple JLabel with Text

Below code shows how to create a simple JLabel with Text.   import java.awt.FlowLayout; import javax.swing.JFrame; import javax.swing.JLabel; public class JLabelExample extends JFrame { JLabelExample() { super(“JLabel Example”); JLabel label=new JLabel(“JLabel with Text”); add(label);...