-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPratice2.java
More file actions
310 lines (262 loc) · 8.46 KB
/
Pratice2.java
File metadata and controls
310 lines (262 loc) · 8.46 KB
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
// public class Pratice2{
// public static void main(String[] args){
// Scanner sc=new Scanner(System.in);
// System.out.print("Enter number 1:");
// int num1=sc.nextInt();
// System.out.print("Enter number 2:");
// int num2=sc.nextInt();
// System.out.print("sum of number 1 and number 2 is:"+(num1+num2));
// }
// }
//methods
import javax.swing.JFrame;
// public class Pratice2 {
// int logic(int a, int b) {
// return a + b;
// }
// int logic(int a, int b, int c) {
// return a + b + c;
// }
// public static void main(String[] args) {
// Scanner sc = new Scanner(System.in);
// Pratice2 obj = new Pratice2();
// System.out.print("Enter number 1:");
// int a = sc.nextInt();
// System.out.print("Enter number 2:");
// int b = sc.nextInt();
// System.out.print("Enter number 3:");
// int c = sc.nextInt();
// obj.logic(a, b);
// obj.logic(a, b, c);
// System.out.println("Sum of 2 numbers are " + obj.logic(a, b));
// System.out.println("Sum of 2 numbers are " + obj.logic(a, b, c));
// }
// }
// Custom class
// class Emp{
// String name;
// int id;
// int salary;
// }
// public class Pratice2{
// public static void main(String[] args){
// Scanner sc=new Scanner(System.in);
// Emp Abhi=new Emp();
// Abhi.name="Abhi";
// Abhi.id=7;
// Abhi.salary=800;
// System.out.println("Creating custom class");
// System.out.println("Employee Name: "+Abhi.name);
// System.out.println("Employee ID: "+Abhi.id);
// System.out.println("Employee Salary: "+Abhi.salary);
// }
// }
// Use of Getter and setter
// class Emp {
// private String name;
// private int id;
// private int salary;
// public void setname(String a) {
// name = a;
// }
// public String getname() {
// return name;
// }
// public void setid(int a) {
// id = a;
// }
// public int getid() {
// return id;
// }
// public void setSalary(int a) {
// salary = a;
// }
// public int getsalary() {
// return salary;
// }
// }
// public class Pratice2 {
// public static void main(String[] args) {
// Scanner sc = new Scanner(System.in);
// Emp Abhi = new Emp();
// Abhi.setname("Abhi");;
// Abhi.setid(8);
// Abhi.setSalary(800);
// System.out.println("Creating custom class");
// System.out.println("Employee Name: " + Abhi.getname());
// System.out.println("Employee ID: " + Abhi.getid());
// System.out.println("Employee Salary: " + Abhi.getsalary());
// }
// }
//Inheritance
// class Base {
// int x;
// public void setx(int a) {
// x = a;
// }
// public int getx() {
// return x;
// }
// }
// class Derived extends Base{
// int y;
// public void sety(int b){
// y=b;
// }
// public int gety(){
// return y;
// }
// }
// public class Pratice2 {
// public static void main(String[] args){
// Base b=new Base();
// b.setx(6);
// System.out.println(b.getx());
// }
// }
//// Exception handling
// public class Pratice2 {
// public static void main(String[] args){
// Scanner sc=new Scanner(System.in);
// System.out.print("Enter number 1:");
// int a=sc.nextInt();
// System.out.print("Enter number 2:");
// int b=sc.nextInt();
// try{
// int c=a/b;
// System.out.println("Division of Number 1 and number 2 is:"+c);
// } catch(Exception e){
// System.out.println("ERROR reason:"+e);
// }
// }
// }
//File handling
//public class Pratice2 {
// public static void main(String[] args) throws IOException {
// File myfile=new File("Abc.txt");
// myfile.createNewFile();
// FileWriter myFileWriter=new FileWriter("abc.txt");
// myFileWriter.write("This is it");
// myFileWriter.close();
// File myFile=new File("abc.txt");
// Scanner sc=new Scanner(myFile);
// while(sc.hasNextLine()){
// String line=sc.nextLine();
// System.out.println(line);
// }
// sc.close();
// if(myFile.delete()){
// System.out.println("File deleted");
// }
// }
//}
//Threads by extending thread class
// class Mythread extends Thread {
// public void run() {
// while (true) {
// System.out.println("This is java thread");
// System.out.println("I am happy");
// }
// }
// }
// class Mythread1 extends Thread {
// public void run() {
// while (true) {
// System.out.println("This is java thread1");
// System.out.println("I am happy2.0");
// }
// }
// }
// public class Pratice2 {
// public static void main(String[] args) {
// Mythread obj=new Mythread();
// obj.run();
// }
// }
//THraed by implementing interface
// class myThread implements Runnable {
// public void run() {
// System.out.println("This is a thread");
// System.out.println("This is a thread");
// System.out.println("This is a thread");
// System.out.println("This is a thread");
// System.out.println("This is a thread");
// System.out.println("This is a thread");
// System.out.println("This is a thread");
// System.out.println("This is a thread");
// System.out.println("This is a thread");
// System.out.println("This is a thread");
// System.out.println("This is a thread");
// System.out.println("This is a thread");
// System.out.println("This is a thread");
// System.out.println("This is a thread");
// System.out.println("This is a thread");
// System.out.println("This is a thread");
// System.out.println("This is a thread");
// System.out.println("This is a thread");
// }
// }
// class myThread1 implements Runnable {
// public void run() {
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// System.out.println("This is a thread not a threat");
// }
// }
// public class Pratice2 {
// public static void main(String[] args) {
// myThread t1 = new myThread();
// Thread t3 = new Thread(t1);
// myThread1 t2 = new myThread1();
// Thread t4 = new Thread(t2);
// t3.start();
// t4.start();
// }
// }
//AWT
// import java.awt.*;
// public class Pratice2{
// public static void main(String[] args){
// Frame f=new Frame();
// f.setVisible(true);
// f.setSize(400,300);
// f.setTitle("Aniket");
// }
// }
//Swing
// import javax.swing.*;
// public class Pratice2 {
// public static void main(String[] args) {
// JFrame j=new JFrame();
// j.setVisible(true);
// j.setSize(500,300);
// j.setTitle("Aniket");
// ImageIcon image=new ImageIcon("a.jpg");
// j.setIconImage(image.getImage());
// }
// }