Sunday, 18 December 2022

Java Collections- SET

  Write a program using hashset to add the a,b,c alphabet and remove the c alphabet and  displayed the set and size of this set.



import java.util.HashSet;

public class simplehashset {
    public static void main(String[ ] args) {
        HashSet<String> set = new HashSet<String>();
        set.add("A");
        set.add("B");
        set.add("C");
        System.out.println(set);
        set.remove("A");
        System.out.println(set);

        System.out.println(set.size());
       
    }
}


OUTPUT: 
[A, B, C]
[B, C]
2


Java collections - List

 Java collections  

A ) List

 Write a program by using arraylist and Add the number 5,2,2,1,3 and remove 2 number index (1) and arranging the ascending order



import java.util.ArrayList;
import java.util.Collections;

public class simplelist {
    public static void main(String[ ] args) {
        ArrayList<Integer> number = new ArrayList<Integer>();
        number.add(5);
        number.add(2);
        number.add(2);
        number.add(1);
        number.add(3);

        System.out.println(number);
        number.remove(2);
        Collections.sort(number);
        System.out.println(number);
    }
}



OUTPUT: 

[5, 2, 2, 1, 3]

[1, 2, 3, 5]

Java program to illustrate and defining implements extending implements class.



public class avi implements Runnable
{
       public static void main(String[] args) {
        Thread guruThread1 = new Thread("avi");
        Thread guruThread2 = new Thread("avi");
        guruThread1.start();
        guruThread2.start();
        System.out.println("Thread names are following:");
        System.out.println(guruThread1.getName());
        System.out.println(guruThread2.getName());
    }
    @Override
    public void run() {
    }
}



      output : avi 

a        avi 













Multithreading 1) Java program to illustrate and defining thread by Extending thread class.

 Multithreading 


 Java program to illustrate and defining thread by  Extending thread class. 





class Test extends Thread
{
    public void run()
    {
        System.out.println("Run method executed by child Thread");
    }
    public static void main(String[] args)
    {
        Test t = new Test();
        t.start();
        System.out.println("Main method executed by main thread");
    }
}



OUTPUT: Main method executed by main thread
Run method executed by child Thread

Design an applet/application to create form using Text Field, Text Area, Button and Label. Label 1 name : Enter your name Lable 2 name : Adress Button : submit

 

Design an applet/application to create form using Text Field, Text Area, Button and Label.  

Label 1 name : Enter your name

Lable 2 name : Adress

Button : submit




package com.javaguides.javaswing.login;

import java.awt.*;

public class BasicAWT
{
 public static void main(String args[])
 {
  Frame f = new Frame();
  f.setSize(400,400);
  f.setVisible(true);
  f.setLayout(new FlowLayout() );
 
  Label l1 = new Label();
  l1.setText("Enter Your Name ");
   
  TextField tf = new TextField(" enter name");
 
  Label l2 = new Label("Address");
  TextArea ta = new TextArea("",3,40);
 
  Button b = new Button("Submit");
   
  f.add(l1); f.add(tf); f.add(l2); f.add(ta); f.add(b);
 }
}



output: 




Develop a program to select multiple languages known to user. 1) Marathi 2) Hindi 3) English

 


Develop a program to select multiple languages known to user.

1)Marathi

2)Hindi

English 


import java.awt.*;
class Lan {
    Lan() {
        Frame f = new Frame();

        Label l1 = new Label("Select known Languages");

        l1.setBounds(100, 50, 120, 80);
        f.add(l1);

        Checkbox c2 = new Checkbox("Hindi");
        c2.setBounds(100, 150, 50, 50);
        f.add(c2);
        Checkbox c3 = new Checkbox("English");
        c3.setBounds(100, 200, 80, 50);
        f.add(c3);
        Checkbox c4 = new Checkbox("marathi");
        c4.setBounds(100, 250, 80, 50);
        f.add(c4);

        f.setSize(500, 500);
        f.setLayout(null);
        f.setVisible(true);
    }

    public static void main(String ar[]) {
        new Lan();
    }
}


OUTPUT:


Write a program to create three buttons with caption ok , reset, and cancel;

 


SWING 


import java.awt.*;

class But {
    But() {
        Frame f = new Frame();
        Button b1 = new Button("Ok");
        b1.setBounds(100, 50, 50, 50);
        f.add(b1);
        Button b2 = new Button("Reset");
        b2.setBounds(100, 101, 50, 50);
        f.add(b2);
        Button b3 = new Button("Cancel");
        b3.setBounds(100, 150, 80, 50);
        f.add(b3);
        f.setSize(500, 500);
        f.setLayout(null);
        f.setVisible(true);
    }

    public static void main(String a[]) {
        new But();
    }
   }

OUTPUT:




GitHub Most Imp Command For Every Developer Learn:

 Top Command for GitHub:  1) git clone 2) git init and git status   3) git add file name  or git add .  4) git commit -m message  5) git rem...