├── Array.java ├── Array2.java ├── BreakApp.java ├── ContinueApp.java ├── ConversionExplicit.java ├── CreateDirectory.java ├── CreateFile.java ├── DBConnect.java ├── Demo.java ├── ExceptionDemo.java ├── ExceptionDemo2.java ├── ExceptionDemo3.java ├── ExceptionDemo4.java ├── ExceptionDemo5.java ├── Jagged.java ├── LabeledBreakApp.java ├── LabeledContinueApp.java ├── PathMethods.java ├── README.md ├── Shirt.java ├── Strings.java ├── ThrowsExecp.java ├── VariableApp.java ├── department.form ├── department.java └── test.java /Array.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | 6 | /** 7 | * 8 | * @author Sakthivel 9 | */ 10 | public class Array{ 11 | public static void main(String[] args) { 12 | int arr[] = {23,67,84,75,95,34,54,6,4,6,86}; 13 | System.out.println("Length: "+arr.length); 14 | System.out.println("Elements are:"); 15 | for (int i = arr.length-1 ;i >= 0 ; i--) 16 | { 17 | System.out.print(arr[i] + " "); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Array2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | 6 | /** 7 | * 8 | * @author Sakthivel 9 | */ 10 | public class Array2 { 11 | public static void main(String[] args) { 12 | int a[][] = new int[3][2]; 13 | a[0][0] = 56; 14 | a[0][1] = 74; 15 | a[1][0] = 88; 16 | a[1][1] = 34; 17 | a[2][0] = 24; 18 | a[2][1] = 43; 19 | for (int i = 0; i < 3 ; i ++){ 20 | for (int j = 0; j < 2 ; j ++){ 21 | System.out.print(a[i][j]+ " "); 22 | } System.out.println(); } 23 | }} 24 | 25 | 26 | -------------------------------------------------------------------------------- /BreakApp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | 6 | /** 7 | * 8 | * @author Sakthivel 9 | */ 10 | public class BreakApp { 11 | public static void main (String args[]) 12 | { 13 | for(int count = 1;count<10;count++) { 14 | if(count ==5) 15 | break; //exit from the current loop 16 | System.out.println("Count is: " + count); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /ContinueApp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | 6 | /** 7 | * 8 | * @author Sakthivel 9 | */ 10 | public class ContinueApp { 11 | public static void main (String args[]) { 12 | for(int count = 1;count<10;count++) { 13 | if(count ==5) 14 | continue; 15 | System.out.println("Count is: " + count); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ConversionExplicit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | 6 | /** 7 | * 8 | * @author Sakthivel 9 | */ 10 | public class ConversionExplicit { 11 | public static void main(String[] args) 12 | { 13 | double d = 100.04; 14 | long l = (long)d; //convert double into long 15 | int i = (int)l; // long convert into int 16 | System.out.println("Double value "+d); 17 | System.out.println("Long value "+l); 18 | System.out.println("Int value "+i); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /CreateDirectory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | 6 | /** 7 | * 8 | * @author Sakthivel 9 | */ 10 | import java.nio.file.*; 11 | import java.io.*; 12 | 13 | public class CreateDirectory { 14 | public static void main(String args[]) { 15 | try { 16 | Path path = Paths.get("C:\\Users\\Sakthivel\\Documents\\valueaddedcourse\\SampleDirectory"); 17 | if (!Files.exists(path)) { 18 | Files.createDirectory(path); 19 | System.out.println("Directory created"); 20 | } else { 21 | System.out.println("Directory already exists"); 22 | } 23 | } catch (IOException e) { 24 | System.out.println(e); //Exception details 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /CreateFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | 6 | /** 7 | * 8 | * @author Sakthivel 9 | */ 10 | import java.nio.file.*; 11 | import java.io.*; 12 | 13 | public class CreateFile { 14 | public static void main(String args[]) { 15 | try { 16 | Path path1 = Paths.get("C:\\Users\\Sakthivel\\Documents\\valueaddedcourse\\SampleDirectory\\Sample.txt"); 17 | if (!Files.exists(path1)) { 18 | Files.createFile(path1); 19 | System.out.println("File created"); 20 | } else { 21 | System.out.println("File already exists"); 22 | } 23 | } catch(IOException e) { 24 | System.out.println(e); // Exception details 25 | } 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /DBConnect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | package javatask; 6 | 7 | /** 8 | * 9 | * @author Sakthivel 10 | */ 11 | import java.sql.*; 12 | 13 | public class DBConnect { 14 | public static void main(String args[]) { 15 | try { 16 | // Step 1: Load the driver class 17 | Class.forName("com.mysql.cj.jdbc.Driver"); 18 | // Step 2: Create the connection object 19 | Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/department", "root", "Sakthivel@2903"); 20 | // Step 3: Create the statement object 21 | Statement stmt = con.createStatement(); 22 | 23 | // Step 4: Execute query 24 | // Uncomment the appropriate line(s) based on the operation you want to perform 25 | 26 | // Creating a table 27 | // stmt.executeUpdate("create table employee (empid int, empname varchar(255))"); 28 | 29 | // Inserting a record 30 | //stmt.executeUpdate("insert into dep_info values(3, 'CSE')"); 31 | 32 | // Updating a record 33 | //stmt.executeUpdate("update employee set empname='Aravind' where empid=120"); 34 | 35 | // Selecting records 36 | ResultSet rs = stmt.executeQuery("select * from dep_info"); 37 | while(rs.next()) 38 | System.out.println(rs.getInt(1)+" "+rs.getString(2)); 39 | // Deleting records 40 | stmt.executeUpdate("delete from dep_info where dep_code='3'"); 41 | 42 | // Step 5: Close the connection object 43 | con.close(); 44 | } catch (Exception e) { 45 | System.out.println(e); 46 | } 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /Demo.java: -------------------------------------------------------------------------------- 1 | class Clothing{ 2 | private float cost; 3 | 4 | public float getCost() { 5 | return cost; 6 | } 7 | 8 | public void setCost(float cost) { 9 | this.cost = cost; 10 | } 11 | } 12 | 13 | public class Demo extends Clothing { 14 | private int _neckSize; 15 | public int getNeckSize(){ 16 | return _neckSize; 17 | } 18 | public void setNeckSize(int nSize){ 19 | this._neckSize = nSize; 20 | } 21 | 22 | public static void main(String [] args){ 23 | Demo de = new Demo(); 24 | de.setCost(350); 25 | System.out.println(de.getCost()); 26 | 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ExceptionDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | 6 | /** 7 | * 8 | * @author Sakthivel 9 | */ 10 | public class ExceptionDemo { 11 | public static void main(String args[]){ 12 | try{ 13 | int a[]=new int[5]; 14 | a[5]=30/0; 15 | } 16 | catch(ArithmeticException e){ 17 | System.out.println(e); 18 | } 19 | catch(ArrayIndexOutOfBoundsException e) { 20 | System.out.println(e); } 21 | catch(Exception e) 22 | { 23 | System.out.println(e); } 24 | System.out.println("rest of the code..."); 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /ExceptionDemo2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | 6 | /** 7 | * 8 | * @author Sakthivel 9 | */ 10 | public class ExceptionDemo2 { 11 | static void validate(int num){ 12 | if(num<0) 13 | throw new ArithmeticException("Invalid value"); 14 | else 15 | System.out.println("Valid to proceed"); 16 | } 17 | public static void main(String args[]){ 18 | try{ 19 | validate(-10); 20 | } 21 | catch(Exception e){ 22 | System.out.println("Error:"+e); 23 | } 24 | System.out.println("rest of the code..."); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /ExceptionDemo3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | 6 | /** 7 | * 8 | * @author Sakthivel 9 | */ 10 | public class ExceptionDemo3 { 11 | static void fun() throws IllegalAccessException { 12 | System.out.println("Inside fun(). "); 13 | throw new IllegalAccessException("demo"); 14 | } 15 | public static void main(String args[]) { 16 | try{ 17 | fun(); 18 | } 19 | catch(IllegalAccessException e){ 20 | System.out.println("caught in main."); 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /ExceptionDemo4.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | 6 | /** 7 | * 8 | * @author Sakthivel 9 | */ 10 | public class ExceptionDemo4 { 11 | public static void main(String args[]) { 12 | try { 13 | int data=25/5; 14 | System.out.println(data); 15 | } 16 | catch(NullPointerException e) { 17 | System.out.println(e); 18 | } 19 | finally { 20 | System.out.println("finally block is always executed"); 21 | } 22 | System.out.println("rest of the code..."); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /ExceptionDemo5.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | 6 | /** 7 | * 8 | * @author Sakthivel 9 | */ 10 | class InvalidAgeException extends Exception { 11 | InvalidAgeException(String s) { 12 | // Call constructor of parent Exception 13 | super(s); 14 | } 15 | } 16 | public class ExceptionDemo5 { 17 | static void validate(int age) throws InvalidAgeException { 18 | if(age<18) 19 | throw new InvalidAgeException("not eligible"); 20 | else 21 | System.out.println("Eligible"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Jagged.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | 6 | /** 7 | * 8 | * @author Sakthivel 9 | */ 10 | public class Jagged { 11 | public static void main(String[] args) { 12 | // Declaring 2-D array with 4 rows 13 | int arr[][] = new int[4][]; 14 | // Making the above array Jagged 15 | // First row has 3 columns 16 | arr[0] = new int[3]; 17 | // Second row has 2 columns 18 | arr[1] = new int[2]; 19 | arr[2] = new int[1]; 20 | arr[3] = new int[4]; 21 | // Initializing array 22 | int count = 5; 23 | for (int i = 0; i < arr.length; i++) 24 | for (int j = 0; j < arr[i].length; j++) { 25 | arr[i][j] = count; 26 | count+=5; 27 | } 28 | // Displaying the values of 2D Jagged array 29 | System.out.println("Contents of 2D Jagged Array"); 30 | for (int i = 0; i < arr.length; i++) { 31 | for (int j = 0; j < arr[i].length; j++) 32 | System.out.print(arr[i][j] + " "); 33 | System.out.println(); 34 | } 35 | } 36 | } 37 | 38 | 39 | -------------------------------------------------------------------------------- /LabeledBreakApp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | 6 | /** 7 | * 8 | * @author Sakthivel 9 | */ 10 | public class LabeledBreakApp { 11 | public static void main(String args[]){ 12 | first: 13 | for (int i = 0; i < 3; i++) { 14 | second: 15 | for (int j = 0; j < 3; j++) { 16 | if (1== i && 1 == j) { 17 | break first; 18 | } 19 | System.out.println(i + " " + j); 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /LabeledContinueApp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | 6 | /** 7 | * 8 | * @author Sakthivel 9 | */ 10 | public class LabeledContinueApp { 11 | public static void main(String args[]){ 12 | first: 13 | for (int i = 0 ; i < 3; i++) { 14 | second: 15 | for (int j = 0; j < 3; j++) { 16 | if (1 == i && 1 == j) { 17 | continue second; 18 | } 19 | System.out.println(i + " " + j); 20 | } 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /PathMethods.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | 6 | /** 7 | * 8 | * @author Sakthivel 9 | */ 10 | import java.nio.file.Path; 11 | import java.nio.file.Paths; 12 | public class PathMethods { 13 | public static void main(String args[]) { 14 | Path p1 = Paths.get ("C:\\Users\\Sakthivel\\Documents\\valueaddedcourse\\Programs\\26. File Path"); 15 | Path normalizedPath = p1.normalize(); 16 | var p2 = Paths.get ("C:\\Users\\Sakthivel\\Documents\\valueaddedcourse\\Programs\\26. File Path"); 17 | System.out.println("NormalizedPath: "+ normalizedPath); 18 | Path subPath = p1.subpath (1, 3); 19 | System.out.println("SubPath: "+ subPath); 20 | System.out.println("getFileName: "+ p1.getFileName()); 21 | System.out.println("getParent: "+p1.getParent()); 22 | System.out.println("getNameCount: "+p1.getNameCount()); 23 | System.out.println("getRoot: " + p1.getRoot()); 24 | System.out.println("isAbsolute: "+p1.isAbsolute()); 25 | System.out.println("toAbsolutePath: "+p1.toAbsolutePath()); 26 | System.out.println("toURI: "+p1.toUri()); 27 | if(p1.equals(p2)) 28 | System.out.println("Both are equal"); 29 | else 30 | System.out.println("Both are not equal"); 31 | } 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # java-fundamentals -------------------------------------------------------------------------------- /Shirt.java: -------------------------------------------------------------------------------- 1 | public class Shirt extends Clothing { 2 | private int _neckSize; 3 | public int getNeckSize(){ 4 | return _neckSize; 5 | } 6 | public void setNeckSize(int nSize){ 7 | this.neckSize = nSize; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Strings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | 6 | /** 7 | * 8 | * @author Sakthivel 9 | */ 10 | public class Strings { 11 | public static void main(String[] args) { 12 | System.out.println("Vy Technical Carrer Development Center"); 13 | System.out.println("Length = "+"VyTCDC".length()); 14 | System.out.println("Vy".concat("TcDc")); 15 | System.out.println("Vy Technical Carrer".substring(3, 12)); 16 | System.out.println("Vy".toUpperCase()); 17 | System.out.println("Vy".toLowerCase()); 18 | System.out.println(" Vy TCDC ".trim()); 19 | System.out.println("Vy".equals("Vy")); 20 | System.out.println("Vy".equals("VY")); 21 | System.out.println("Vy".equalsIgnoreCase("VY")); 22 | System.out.println("VyTCDC".startsWith("Vy")); 23 | System.out.println("VyTCDC".endsWith("dc")); 24 | System.out.println("VyTCDC".toCharArray()); } 25 | } 26 | -------------------------------------------------------------------------------- /ThrowsExecp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | 6 | /** 7 | * 8 | * @author Sakthivel 9 | */ 10 | public class ThrowsExecp { 11 | public static void main(String args[]){ 12 | try{ 13 | String str = null; 14 | System.out.println(str.length()); 15 | } 16 | catch(NullPointerException e){ 17 | System.out.println(e); 18 | } 19 | System.out.println("rest of the code"); 20 | } 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /VariableApp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | 6 | /** 7 | * 8 | * @author Sakthivel 9 | */ 10 | public class VariableApp { 11 | int mark = 95 ;//instance variable 12 | static char grade = 'S'; // static variable 13 | public static void main(String[] args) 14 | { 15 | float average=95.0f; 16 | System.out.println(average);// local variable    17 | } 18 | } 19 | -------------------------------------------------------------------------------- /department.form: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 | 200 | -------------------------------------------------------------------------------- /department.java: -------------------------------------------------------------------------------- 1 | package javatask; 2 | import java.sql.*; 3 | import jav.io.*; 4 | import javax.swing.table.DefaultTableModel; 5 | 6 | /* 7 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 8 | * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template 9 | */ 10 | 11 | /** 12 | * 13 | * @author Sakthivel 14 | */ 15 | public class department extends javax.swing.JFrame { 16 | 17 | /** 18 | * Creates new form department 19 | */ 20 | public department() { 21 | initComponents(); 22 | } 23 | 24 | /** 25 | * This method is called from within the constructor to initialize the form. 26 | * WARNING: Do NOT modify this code. The content of this method is always 27 | * regenerated by the Form Editor. 28 | */ 29 | @SuppressWarnings("unchecked") 30 | // //GEN-BEGIN:initComponents 31 | private void initComponents() { 32 | 33 | jPanel1 = new javax.swing.JPanel(); 34 | jLabel1 = new javax.swing.JLabel(); 35 | jPanel2 = new javax.swing.JPanel(); 36 | deplist = new javax.swing.JButton(); 37 | jButton1 = new javax.swing.JButton(); 38 | jButton2 = new javax.swing.JButton(); 39 | jPanel3 = new javax.swing.JPanel(); 40 | jScrollPane1 = new javax.swing.JScrollPane(); 41 | jTable1 = new javax.swing.JTable(); 42 | 43 | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 44 | setBackground(new java.awt.Color(255, 255, 204)); 45 | 46 | jPanel1.setBackground(new java.awt.Color(204, 255, 204)); 47 | 48 | jLabel1.setBackground(new java.awt.Color(51, 51, 51)); 49 | jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N 50 | jLabel1.setText("M.KUMARASAMY COLLEGE OF ENGINEERING"); 51 | 52 | javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); 53 | jPanel1.setLayout(jPanel1Layout); 54 | jPanel1Layout.setHorizontalGroup( 55 | jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 56 | .addGroup(jPanel1Layout.createSequentialGroup() 57 | .addGap(206, 206, 206) 58 | .addComponent(jLabel1) 59 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 60 | ); 61 | jPanel1Layout.setVerticalGroup( 62 | jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 63 | .addGroup(jPanel1Layout.createSequentialGroup() 64 | .addGap(33, 33, 33) 65 | .addComponent(jLabel1) 66 | .addContainerGap(35, Short.MAX_VALUE)) 67 | ); 68 | 69 | jPanel2.setBackground(new java.awt.Color(255, 153, 153)); 70 | 71 | deplist.setText("ListAll"); 72 | deplist.addActionListener(new java.awt.event.ActionListener() { 73 | public void actionPerformed(java.awt.event.ActionEvent evt) { 74 | deplistActionPerformed(evt); 75 | } 76 | }); 77 | 78 | jButton1.setText("Delete"); 79 | jButton1.setActionCommand(""); 80 | 81 | jButton2.setText("Update"); 82 | 83 | javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); 84 | jPanel2.setLayout(jPanel2Layout); 85 | jPanel2Layout.setHorizontalGroup( 86 | jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 87 | .addGroup(jPanel2Layout.createSequentialGroup() 88 | .addGap(22, 22, 22) 89 | .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 90 | .addComponent(jButton2) 91 | .addComponent(jButton1) 92 | .addComponent(deplist)) 93 | .addContainerGap(39, Short.MAX_VALUE)) 94 | ); 95 | jPanel2Layout.setVerticalGroup( 96 | jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 97 | .addGroup(jPanel2Layout.createSequentialGroup() 98 | .addGap(36, 36, 36) 99 | .addComponent(deplist) 100 | .addGap(58, 58, 58) 101 | .addComponent(jButton1) 102 | .addGap(65, 65, 65) 103 | .addComponent(jButton2) 104 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 105 | ); 106 | 107 | jPanel3.setBackground(new java.awt.Color(255, 255, 204)); 108 | 109 | jTable1.setModel(new javax.swing.table.DefaultTableModel( 110 | new Object [][] { 111 | {null, null}, 112 | {null, null}, 113 | {null, null}, 114 | {null, null} 115 | }, 116 | new String [] { 117 | "Department Code", "Department Name" 118 | } 119 | )); 120 | jScrollPane1.setViewportView(jTable1); 121 | 122 | javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); 123 | jPanel3.setLayout(jPanel3Layout); 124 | jPanel3Layout.setHorizontalGroup( 125 | jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 126 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() 127 | .addContainerGap(134, Short.MAX_VALUE) 128 | .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 452, javax.swing.GroupLayout.PREFERRED_SIZE) 129 | .addGap(28, 28, 28)) 130 | ); 131 | jPanel3Layout.setVerticalGroup( 132 | jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 133 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() 134 | .addContainerGap(85, Short.MAX_VALUE) 135 | .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 343, javax.swing.GroupLayout.PREFERRED_SIZE) 136 | .addGap(30, 30, 30)) 137 | ); 138 | 139 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 140 | getContentPane().setLayout(layout); 141 | layout.setHorizontalGroup( 142 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 143 | .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 144 | .addGroup(layout.createSequentialGroup() 145 | .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 146 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 147 | .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 148 | ); 149 | layout.setVerticalGroup( 150 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 151 | .addGroup(layout.createSequentialGroup() 152 | .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 153 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 154 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 155 | .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 156 | .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) 157 | ); 158 | 159 | pack(); 160 | }// //GEN-END:initComponents 161 | 162 | private void deplistActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deplistActionPerformed 163 | DefaultTableModel model = (DefaultTableModel)jTable1.getModel(); 164 | while(model.getRowCount()>0){ 165 | for(int i=0;i 213 | /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. 214 | * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 215 | */ 216 | try { 217 | for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { 218 | if ("Nimbus".equals(info.getName())) { 219 | javax.swing.UIManager.setLookAndFeel(info.getClassName()); 220 | break; 221 | } 222 | } 223 | } catch (ClassNotFoundException ex) { 224 | java.util.logging.Logger.getLogger(department.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 225 | } catch (InstantiationException ex) { 226 | java.util.logging.Logger.getLogger(department.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 227 | } catch (IllegalAccessException ex) { 228 | java.util.logging.Logger.getLogger(department.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 229 | } catch (javax.swing.UnsupportedLookAndFeelException ex) { 230 | java.util.logging.Logger.getLogger(department.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 231 | } 232 | // 233 | 234 | /* Create and display the form */ 235 | java.awt.EventQueue.invokeLater(new Runnable() { 236 | public void run() { 237 | new department().setVisible(true); 238 | } 239 | }); 240 | } 241 | 242 | // Variables declaration - do not modify//GEN-BEGIN:variables 243 | private javax.swing.JButton deplist; 244 | private javax.swing.JButton jButton1; 245 | private javax.swing.JButton jButton2; 246 | private javax.swing.JLabel jLabel1; 247 | private javax.swing.JPanel jPanel1; 248 | private javax.swing.JPanel jPanel2; 249 | private javax.swing.JPanel jPanel3; 250 | private javax.swing.JScrollPane jScrollPane1; 251 | private javax.swing.JTable jTable1; 252 | // End of variables declaration//GEN-END:variables 253 | } 254 | -------------------------------------------------------------------------------- /test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template 4 | */ 5 | 6 | /** 7 | * 8 | * @author Sakthivel 9 | */ 10 | import java.util.Scanner; 11 | 12 | public class test { 13 | public static void main(String[] args) { 14 | Scanner scanner = new Scanner(System.in); 15 | System.out.print("Enter a number: "); 16 | int num = scanner.nextInt(); 17 | 18 | int square = calculateSquare(num); 19 | 20 | System.out.println("The square for " + num + " is: " + square); 21 | } 22 | 23 | public static int calculateSquare(int num) { 24 | if (num == 1) { 25 | return 1; 26 | } 27 | return num * calculateSquare(num - 1) + num; 28 | } 29 | } 30 | 31 | 32 | --------------------------------------------------------------------------------