java Archives - Page 10 of 10 - Coddicted

Can we execute a program without main() method in java?

Yes ,using static block (not possible in JDK 1.7)   for example: class A {  static {  String name = getName();  System.out.println(name); }   public static String getName() {  return “project code bank”; } }   output: project code bank Exception in thread “main” java.lang.NoSuchMethodError: main   using System.exit(0) in the static we can avoid ...

Autoboxing and Unboxing 1

Autoboxing, introduced in Java 5, is the automatic conversion the Java compiler makes between the primitive (basic) types and their corresponding object wrapper classes (eg, int and Integer, double and Double, etc). The underlying code that is generated is the same, but autoboxing provides a sugar coating that avoids the tedious and hard-to-read casting typically ...

ArrayList and Vector

java.util.Vector was introduced with the first version of java development kit (JDK 1.1) and java.util.ArrayList  was introduced in java version 1.2 as a part of collections framework, later vector has also been retrofitted to implement List and became the part of the collections framework. Both ArrayList and Vector use array as a internal data structure and are dynamically resizable with default size zero and ...

Adding rows and columns in JTable dynamically 5

Adding rows and columns in JTable dynamically
Java Source code to add Row and Column in JTable dynamically package com.example; import java.awt.BorderLayout; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Vector; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.WindowConstants; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; public class JTableSample { private JFrame mainFrame ; private JTable ...

Russian Peasant Multiplication 2

Russian Peasant Multiplication
Description: Russian Peasant Multiplication. This program allows one to do multiplication by just doing muliplication or division by 2 (and addition). This is interesting since computers generally use base 2 arithmetic.The algorithm is as follows. Start two rows, one with the multiplicand (say, A) and the other the multiplier (say B). The goal is to ...