Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e60814b

Browse files
Uploaded Learn Folder
1 parent 09f03b1 commit e60814b

33 files changed

+1661
-0
lines changed

‎Learn/Class_Object_1.java‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package Learn;
2+
3+
public class Class_Object_1
4+
{
5+
6+
// 1: Main within the class
7+
/* In Java, an object is created from a class. We have already created
8+
the class named Class_Object_1,so now we can use this to create objects.*/
9+
/* int x=5;
10+
public static void main(String args[])
11+
{
12+
Class_Object_1 myObj = new Class_Object_1();
13+
System.out.println(myObj.x);
14+
} */
15+
16+
17+
// 2: Main outside the class
18+
/* Java Program to demonstrate having the main method in another
19+
class Creating Student class. */
20+
21+
//Creating another class TestStudent1 which contains the main method
22+
public static void main(String args[])
23+
{
24+
Student s1=new Student();
25+
System.out.println(s1.id);
26+
System.out.println(s1.name);
27+
}
28+
}
29+
30+
class Student
31+
{
32+
int id;
33+
String name;
34+
}
35+

‎Learn/Class_WrapperClasses.java‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package Learn;
2+
/*
3+
* The wrapper class implements the technique to convert the primitive into object and object into primitive.
4+
* Primitive data types are faster then Wrapper.
5+
* There are certain things that only work with Wrapper class e.g. Hibernate, Collection API.
6+
*/
7+
public class Class_WrapperClasses
8+
{
9+
public static void main(String args[])
10+
{
11+
int i = 5; // Primitive data type
12+
Integer ii = new Integer(5); // Wrapper class
13+
14+
// Putting a variable inside an object
15+
Integer ij = new Integer(i); // Boxing - Wrapping
16+
int j = ij.intValue(); // UnBoxing - UnWrapping
17+
18+
// Assigning the value to object
19+
Integer value = i; // AutoBoxing
20+
int k = value; // AutoUnBoxing
21+
22+
}
23+
}

‎Learn/ConstructorOverloading.java‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package Learn;
2+
3+
class ConstructorOverloading
4+
{
5+
private int stuID;
6+
private String stuName;
7+
private int stuAge;
8+
9+
ConstructorOverloading()
10+
{
11+
stuID = 100;
12+
stuName = "New Student";
13+
stuAge = 17;
14+
}
15+
16+
ConstructorOverloading(int num1, String str, int num2)
17+
{
18+
stuID = num1;
19+
stuName = str;
20+
stuAge = num2;
21+
}
22+
23+
/* The get method returns the variable value, and the set method sets the value.
24+
However, as the name variable is declared as private, we cannot access it from outside this class. */
25+
//Getter and setter methods
26+
public int getStuID()
27+
{
28+
return stuID;
29+
}
30+
public void setStuID(int stuID)
31+
{
32+
this.stuID = stuID;
33+
}
34+
35+
public String getStuName()
36+
{
37+
return stuName;
38+
}
39+
public void setStuName(String stuName)
40+
{
41+
this.stuName = stuName;
42+
}
43+
44+
public int getStuAge()
45+
{
46+
return stuAge;
47+
}
48+
public void setStuAge(int stuAge)
49+
{
50+
this.stuAge = stuAge;
51+
}
52+
53+
public static void main(String args[])
54+
{
55+
ConstructorOverloading obj = new ConstructorOverloading();
56+
System.out.println("Student Name is: "+obj.getStuName());
57+
System.out.println("Student Age is: "+obj.getStuAge());
58+
System.out.println("Student ID is: "+obj.getStuID());
59+
60+
ConstructorOverloading obj2 = new ConstructorOverloading(555, "Chat", 25);
61+
System.out.println("Student Name is: "+obj2.getStuName());
62+
System.out.println("Student Age is: "+obj2.getStuAge());
63+
System.out.println("Student ID is: "+obj2.getStuID());
64+
}
65+
}
66+
67+

‎Learn/CopyConstructor.java‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package Learn;
2+
3+
class JavaExample
4+
{
5+
String web;
6+
7+
JavaExample(String a)
8+
{
9+
web = a;
10+
}
11+
12+
// It copies the values of one object to the another object (the object that invokes this constructor)
13+
JavaExample(JavaExample ref)
14+
{
15+
web = ref.web;
16+
}
17+
18+
void disp()
19+
{
20+
System.out.println("Website: "+web);
21+
}
22+
}
23+
24+
public class CopyConstructor
25+
{
26+
public static void main(String args[])
27+
{
28+
JavaExample obj1 = new JavaExample("BeginnersBook");
29+
30+
// Passing the object as an argument to the constructor. This will invoke the copy constructor
31+
JavaExample obj2 = new JavaExample(obj1);
32+
33+
obj1.disp();
34+
obj2.disp();
35+
}
36+
}

‎Learn/DataInputStream_class.java‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package Learn;
2+
3+
import java.io.*;
4+
public class DataInputStream_class
5+
{
6+
public static void main(String args[])throws IOException
7+
{
8+
DataInputStream in = new DataInputStream(System.in);
9+
10+
/*System.out.println("Enter Your Name: ");
11+
String name =in.readLine();
12+
System.out.println("Name: "+name);
13+
14+
System.out.println("Enter Your Age: ");
15+
int age =Integer.parseInt(in.readLine());
16+
System.out.println("Age: "+age);*/
17+
18+
System.out.println("Enter Character: ");
19+
char c=(char)System.in.read();
20+
System.out.println("Gender: "+c);
21+
22+
23+
// float = Float.parseFloat(in.readLine()); & double = Double.parseDouble(in.readLine());
24+
}
25+
}

‎Learn/Enum.java‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package Learn;
2+
3+
/* Enum is short of this
4+
class Mobile
5+
{
6+
static final Mobile APPLE = new Mobile(100);
7+
static final Mobile SAMSUNG = new Mobile();
8+
static final Mobile HTC = new Mobile(90);
9+
}*/
10+
11+
interface demo3
12+
{ } // enum can implement but can't extend
13+
14+
enum Mobile implements demo3
15+
{
16+
// Two ways we can set price:
17+
// direct method for apple and htc
18+
APPLE(100), SAMSUNG, HTC(90);
19+
20+
// using constructor & methods for samsung
21+
int price;
22+
Mobile()
23+
{
24+
price = 80;
25+
}
26+
Mobile(int p)
27+
{
28+
price = p;
29+
}
30+
public int getPrice()
31+
{
32+
return price;
33+
}
34+
}
35+
36+
public class Enum
37+
{
38+
public static void main(String args[])
39+
{
40+
System.out.println(Mobile.APPLE.getPrice());
41+
System.out.println(Mobile.SAMSUNG.getPrice());
42+
System.out.println(Mobile.HTC.getPrice());
43+
44+
Mobile m[] = Mobile.values();
45+
46+
for(Mobile mobile : m)
47+
System.out.println(mobile);
48+
}
49+
}

‎Learn/EqualsMethod.java‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package Learn;
2+
3+
/* .equals()
4+
* In general, both equals() and "==" operators in Java are used to compare objects to check equality, but here are some of the differences between the two:
5+
* The main difference between the .equals() method and == operator is that one is a method, and the other is the operator.
6+
* We can use == operators for reference comparison (address comparison) and .equals() method for content comparison. In simple words, == checks if both objects point to the same memory location whereas .equals() evaluates to the comparison of values in the objects.
7+
* If a class does not override the equals method, then by default, it uses the equals(Object o) method of the closest parent class that has overridden this method.
8+
*/
9+
10+
public class EqualsMethod
11+
{
12+
public static void main(String args[])
13+
{
14+
String s1 = "HELLO";
15+
String s2 = "HELLO";
16+
String s3 = new String("HELLO");
17+
18+
System.out.println(s1 == s2); // true
19+
System.out.println(s1 == s3); // false
20+
System.out.println(s1.equals(s2)); // true
21+
System.out.println(s1.equals(s3)); // true
22+
23+
}
24+
25+
}
26+
27+
/* Explanation: Here, we create two objects, namely s1 and s2.
28+
* Both s1 and s2 refer to different objects.
29+
* When we use the == operator for s1 and s2 comparison, the result is true as both have the same addresses in the string constant pool.
30+
* Using equals, the result is true because it’s only comparing the values given in s1 and s2. */

‎Learn/GUIApplets.java‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package Learn;
2+
3+
import java.applet.*;
4+
import java.awt.*;
5+
/* <applet CODE="GUIApplets.class" WIDTH=400 HEIGHT=600>
6+
</applet> */
7+
8+
public class GUIApplets extends Applet
9+
{
10+
public void init()
11+
{
12+
setBackground(Color.black);
13+
setForeground(Color.white);
14+
}
15+
16+
public void paint(Graphics g)
17+
{
18+
// Classes:
19+
Color c = new Color(0,255,0);
20+
Font f = new Font("Bookman Old Style",3,30);
21+
g.setColor(c);
22+
g.setFont(f);
23+
// Methods:
24+
int x[] = {200, 250, 260, 270, 290};
25+
int y[] = {100, 200, 300, 400, 500};
26+
g.drawPolygon(x,y,5);
27+
28+
g.drawString("Welcome to Applets",40,40);
29+
g.drawLine(40,240,100,40);
30+
31+
g.drawRect(40, 70, 100, 100);
32+
g.drawRect(20, 20, 100, 100); // its a SQUARE
33+
g.fillRect(40, 70, 100, 100);
34+
g.drawOval(40, 170, 30, 30);
35+
g.drawOval(40, 40, 30, 30); // its a CIRCLE
36+
g.fillOval(40, 170, 30, 30);
37+
38+
g.drawArc(40,260,60,100,60,60);
39+
}
40+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /