Skip to content

Commit f53fee1

Browse files
committed
Restructuring
1 parent 24fb984 commit f53fee1

34 files changed

+244
-186
lines changed

Diff for: .classpath

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<classpathentry kind="src" path="com/ericsson/training"/>
55
<classpathentry kind="src" path="com/ericsson/trainingjava/designpatterns"/>
66
<classpathentry kind="src" path="mypc"/>
7+
<classpathentry kind="src" path="CommonBugs"/>
78
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
89
<classpathentry kind="lib" path="C:/Users/send2/.m2/repository/junit/junit/4.7/junit-4.7.jar"/>
910
<classpathentry kind="output" path="bin"/>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: com/caveofprogramming/tutorials/t37/abstractclass/Camera.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package t37.abstractclass;
22

3-
43
public class Camera extends Machine {
54

65
@Override

Diff for: com/caveofprogramming/tutorials/t37/abstractclass/Car.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package t37.abstractclass;
22

3-
43
public class Car extends Machine {
54

65
@Override

Diff for: com/caveofprogramming/tutorials/t37/abstractclass/Machine.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,21 @@ public int getId() {
1111
public void setId(int id) {
1212
this.id = id;
1313
}
14-
15-
// Abstract classes can have abstract methods - this would be appropriate if I want all my child classes to have a method (for example "start") to implement it, but i don't want Machine itself to implement it because the implementation will be completely different for every particular machine.
16-
// I can create an abstract method like this and then add it to the child classes:
14+
15+
// Abstract classes can have abstract methods - this would be appropriate if I
16+
// want all my child classes to have a method (for example "start") to implement
17+
// it, but i don't want Machine itself to implement it because the
18+
// implementation will be completely different for every particular machine.
19+
// I can create an abstract method like this and then add it to the child
20+
// classes:
1721
public abstract void start();
22+
1823
public abstract void doStuff();
24+
1925
public abstract void shutDown();
20-
21-
// Or I can create a method that call all the abstract methods and then again add them to the child class:
26+
27+
// Or I can create a method that call all the abstract methods and then again
28+
// add them to the child class:
2229
public void run() {
2330
start();
2431
doStuff();
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
package t37.abstractclass;
22
// Abstract class is something that is going to act as a base for the other classes.
3+
34
// If the other subclasses has something in common we can put the code into the base class.
45

56
public class T37_AbstractClass {
6-
7+
78
public static void main(String[] args) {
8-
9+
910
Camera cam1 = new Camera();
1011
cam1.setId(5);
11-
12+
1213
Car car1 = new Car();
1314
car1.setId(6);
14-
15-
/* Machine is called abstract because we are never going to call it. Machine only act as a base for other classes.
16-
I can prevent the users to instantiate a new Machine object by machine Machine class "abstract" (see code in class).
17-
18-
Machine machine1 = new Machine();
19-
*/
20-
15+
16+
/*
17+
* Machine is called abstract because we are never going to call it. Machine
18+
* only act as a base for other classes. I can prevent the users to instantiate
19+
* a new Machine object by machine Machine class "abstract" (see code in class).
20+
*
21+
* Machine machine1 = new Machine();
22+
*/
23+
2124
car1.run();
2225
}
23-
26+
2427
}
+18-14
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,52 @@
11
package t42.innerclasses;
22

3-
43
public class Robot {
54

65
private int id;
7-
8-
// Non-static inner classes or nested classes - they are use when you need to group together some functionality and you need the class to have access to the instance variables of the outer class.
9-
6+
7+
// Non-static inner classes or nested classes - they are use when you need to
8+
// group together some functionality and you need the class to have access to
9+
// the instance variables of the outer class.
10+
1011
private class Brain { // This class can be both private and public.
1112
public void think() {
1213
System.out.println("Robot " + id + " is thinking...");
1314
}
1415
}
15-
16-
// Static inner classes - they are used when you want a normal class that isn't associated with instances of the outer class but that for some reason you want to group it with the outer class.
17-
16+
17+
// Static inner classes - they are used when you want a normal class that isn't
18+
// associated with instances of the outer class but that for some reason you
19+
// want to group it with the outer class.
20+
1821
public static class Battery {
1922
public void charge() {
20-
System.out.println("Battery charging..."); // because the class is static, we cannot refer to the id in Robot unless we were to declare id as static.
23+
System.out.println("Battery charging..."); // because the class is static, we cannot refer to the id in
24+
// Robot unless we were to declare id as static.
2125
}
2226
}
2327

2428
public Robot(int id) {
2529
this.id = id;
2630
}
27-
31+
2832
public void start() {
2933
System.out.println("Starting robot: " + id);
30-
34+
3135
Brain brain = new Brain();
3236
brain.think();
33-
37+
3438
final String name = "Robert";
35-
39+
3640
// We can also create classes from inside a method:
3741
class Temp {
3842
public void doSomething() {
3943
System.out.println("ID is: " + id); // it can refer to instance data
4044
System.out.println("Name is: " + name); // but it can't refer to data if it's not set as 'final'.
4145
}
4246
}
43-
47+
4448
Temp temp = new Temp();
4549
temp.doSomething();
4650
}
47-
51+
4852
}

Diff for: com/caveofprogramming/tutorials/t42/innerclasses/T42_InnerClasses.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
public class T42_InnerClasses {
44

55
public static void main(String[] args) {
6-
6+
77
Robot robot = new Robot(7);
88
robot.start();
9-
9+
1010
Robot.Battery battery = new Robot.Battery();
1111
battery.charge();
12-
12+
1313
}
14-
14+
1515
}

Diff for: com/caveofprogramming/tutorials/t43/enumtypes/Animal.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
public enum Animal {
44
CAT("Taylor"), DOG("Alaska"), MOUSE("Jerry"); // They are objects of the type Animal
5-
5+
66
private String name;
7-
7+
88
// We can give the enum type a constructor and also give methods
9-
// The constructor will have to be declared either private or miss it off completely:
10-
9+
// The constructor will have to be declared either private or miss it off
10+
// completely
11+
1112
Animal(String name) {
1213
this.name = name;
1314
}
1415

1516
public String getName() {
1617
return name;
1718
}
18-
19+
1920
public String toString() {
2021
return "This animal is called " + name;
2122
}

Diff for: com/caveofprogramming/tutorials/t45/serialization/Person.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package t45.serialization;
2+
23
import java.io.Serializable;
34

45
// To make a serializable object or class:
@@ -8,7 +9,7 @@ public class Person implements Serializable {
89
private static final long serialVersionUID = 4801633306273802062L;
910
private int id;
1011
private String name;
11-
12+
1213
public Person(int id, String name) {
1314
this.id = id;
1415
this.name = name;
@@ -18,7 +19,10 @@ public Person(int id, String name) {
1819
public String toString() {
1920
return "Person [id=" + id + ", name=" + name + "]";
2021
}
21-
22+
2223
}
2324

24-
// Serialization is the process of converting an object into a stream of bytes in order to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called deserialization.
25+
// Serialization is the process of converting an object into a stream of bytes
26+
// in order to store the object or transmit it to memory, a database, or a file.
27+
// Its main purpose is to save the state of an object in order to be able to
28+
// recreate it when needed. The reverse process is called deserialization.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package t45.serialization;
2+
23
import java.io.FileInputStream;
34
import java.io.FileNotFoundException;
45
import java.io.IOException;
@@ -7,32 +8,29 @@
78
public class ReadObjects {
89

910
public static void main(String[] args) {
10-
11+
1112
System.out.println("Reading objects...");
12-
13-
try(FileInputStream fi = new FileInputStream("people.bin")) {
14-
13+
14+
try (FileInputStream fi = new FileInputStream("people.bin")) {
15+
1516
ObjectInputStream os = new ObjectInputStream(fi);
16-
17+
1718
Person person1 = (Person) os.readObject();
1819
Person person2 = (Person) os.readObject();
19-
20+
2021
os.close();
21-
22+
2223
System.out.println(person1);
2324
System.out.println(person2);
24-
25+
2526
} catch (FileNotFoundException e) {
26-
// TODO Auto-generated catch block
2727
e.printStackTrace();
2828
} catch (IOException e) {
29-
// TODO Auto-generated catch block
3029
e.printStackTrace();
3130
} catch (ClassNotFoundException e) {
32-
// TODO Auto-generated catch block
3331
e.printStackTrace();
3432
}
35-
33+
3634
}
37-
35+
3836
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package t45.serialization;
2+
23
import java.io.FileNotFoundException;
34
import java.io.FileOutputStream;
45
import java.io.IOException;
@@ -9,30 +10,28 @@ public class WriteObjects {
910
public static void main(String[] args) {
1011

1112
System.out.println("Writing objects...");
12-
13+
1314
Person mike = new Person(543, "Mike");
1415
Person sue = new Person(123, "Sue");
15-
16+
1617
System.out.println(mike);
1718
System.out.println(sue);
18-
19+
1920
try (FileOutputStream fs = new FileOutputStream("people.bin")) {
20-
21+
2122
ObjectOutputStream os = new ObjectOutputStream(fs);
22-
23+
2324
os.writeObject(mike);
2425
os.writeObject(sue);
25-
26+
2627
os.close();
27-
28+
2829
} catch (FileNotFoundException e) {
29-
// TODO Auto-generated catch block
3030
e.printStackTrace();
3131
} catch (IOException e) {
32-
// TODO Auto-generated catch block
3332
e.printStackTrace();
3433
}
35-
34+
3635
}
3736

3837
}

Diff for: com/caveofprogramming/tutorials/t46/serializingarrays/Person.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class Person implements Serializable {
99
private static final long serialVersionUID = 4801633306273802062L;
1010
private int id;
1111
private String name;
12-
12+
1313
public Person(int id, String name) {
1414
this.id = id;
1515
this.name = name;
@@ -19,7 +19,10 @@ public Person(int id, String name) {
1919
public String toString() {
2020
return "Person [id=" + id + ", name=" + name + "]";
2121
}
22-
22+
2323
}
2424

25-
// Serialization is the process of converting an object into a stream of bytes in order to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called deserialization.
25+
// Serialization is the process of converting an object into a stream of bytes
26+
// in order to store the object or transmit it to memory, a database, or a file.
27+
// Its main purpose is to save the state of an object in order to be able to
28+
// recreate it when needed. The reverse process is called deserialization.

0 commit comments

Comments
 (0)