├── Java.txt ├── chatbot.java ├── mouse.java └── multithread.java /Java.txt: -------------------------------------------------------------------------------- 1 | Java is a programming language and a platform. 2 | Java is a high level, robust, object-oriented and secure programming language. 3 | Java was developed by Sun Microsystems (which is now the subsidiary of Oracle) in the year 1995. 4 | James Gosling is known as the father of Java. Before Java, its name was Oak. 5 | Since Oak was already a registered company, so James Gosling and his team changed the name from Oak to Java. 6 | Platform: Any hardware or software environment in which a program runs, is known as a platform. 7 | Since Java has a runtime environment (JRE) and API, it is called a platform. 8 | -------------------------------------------------------------------------------- /chatbot.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class SimpleChatbot { 4 | 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | 8 | System.out.println("Hi there! Ask me a question."); 9 | String userInput = scanner.nextLine(); 10 | 11 | if (userInput.contains("hello") || userInput.contains("hi")) { 12 | System.out.println("Hello! How can I help you?"); 13 | } else if (userInput.contains("how are you")) { 14 | System.out.println("I'm just a bot, but thanks for asking!"); 15 | } else { 16 | System.out.println("I'm sorry, I don't understand that question."); 17 | } 18 | 19 | scanner.close(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /mouse.java: -------------------------------------------------------------------------------- 1 | import javax.swing.*; 2 | import java.awt.*; 3 | import javax.swing.event.*; 4 | import java.awt.event.*; 5 | class A extends JFrame implements MouseListener 6 | { 7 | JLabel l1; 8 | public A() 9 | { 10 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 11 | setSize(400, 400); 12 | setLayout(new GridBagLayout()); 13 | l1 = new JLabel(); 14 | Font f = new Font("Verdana", Font.BOLD, 20); 15 | l1.setFont(f); 16 | l1.setForeground(Color.BLUE); 17 | l1.setAlignmentX(Component.CENTER_ALIGNMENT); 18 | l1.setAlignmentY(Component.CENTER_ALIGNMENT); 19 | add(l1); 20 | addMouseListener(this); 21 | setVisible(true); } 22 | public void mouseExited(MouseEvent m) 23 | { 24 | l1.setText("Mouse Exited"); 25 | } 26 | public void mouseEntered(MouseEvent m) 27 | { 28 | l1.setText("Mouse Entered"); 29 | } 30 | public void mouseReleased(MouseEvent m) 31 | { 32 | l1.setText("Mouse Released"); 33 | } 34 | 35 | public void mousePressed(MouseEvent m) 36 | { 37 | l1.setText("Mouse Pressed"); 38 | } 39 | public void mouseClicked(MouseEvent m) 40 | { 41 | l1.setText("Mouse Clicked"); 42 | } } 43 | class Mevents 44 | { public static void main(String[] args) 45 | { 46 | A a = new A(); 47 | } } -------------------------------------------------------------------------------- /multithread.java: -------------------------------------------------------------------------------- 1 | class MultithreadingDemo extends Thread 2 | { 3 | public void run() 4 | { 5 | try 6 | { 7 | System.out.println("Thread " + Thread.currentThread().getId()+ " is running"); 8 | } 9 | 10 | catch (Exception e) 11 | { 12 | System.out.println("Exception is caught"); 13 | } 14 | } 15 | } 16 | 17 | class Multithread 18 | { 19 | public static void main(String[] args) 20 | { 21 | int n = 8; 22 | for (int i = 0; i < n; i++) 23 | { 24 | MultithreadingDemo object = new MultithreadingDemo(); 25 | object.start(); 26 | } 27 | } 28 | } 29 | 30 | class MultithreadingDemo implements Runnable 31 | { 32 | public void run() 33 | { 34 | try { 35 | System.out.println( "Thread " + Thread.currentThread().getId() + " is running"); 36 | } 37 | 38 | catch (Exception e) 39 | { 40 | System.out.println("Exception is caught"); 41 | } 42 | } 43 | } 44 | 45 | class Multithread 46 | { 47 | public static void main(String[] args) 48 | { 49 | int n = 8; 50 | for (int i = 0; i < n; i++) 51 | { 52 | Thread object = new Thread (new MultithreadingDemo()); 53 | object.start (); 54 | } 55 | }} --------------------------------------------------------------------------------