Skip to content

Commit 7b8949d

Browse files
pojo and record
1 parent e132c18 commit 7b8949d

File tree

5 files changed

+204
-1
lines changed

5 files changed

+204
-1
lines changed

.idea/uiDesigner.xml

+124
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ControlFlow/Switch.java

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package ControlFlow;
2+
3+
public class Switch {
4+
5+
6+
public static void main(String[] args) {
7+
//classic
8+
9+
int a = 2;
10+
//works with byte, short, int, char, String, enum and their main classess
11+
switch(a){
12+
case 1:
13+
System.out.println("1");
14+
break;
15+
case 2:
16+
System.out.println("2");
17+
break;
18+
case 3: case 4: case 5:
19+
System.out.println("3 or 4 or 5");
20+
default:
21+
System.out.println("different");
22+
}
23+
24+
//modern java switch
25+
26+
switch (a){
27+
case 1 -> System.out.println("1");
28+
case 2 -> System.out.println("2");
29+
case 3, 4, 5 -> System.out.println("3, 4, 5");
30+
default -> System.out.println("different");
31+
}
32+
}
33+
34+
public static String funWithReturn(String month){
35+
return switch (month){
36+
case "JANUARY", "Februaru", "March" -> "1st";
37+
case "April" -> "2nd";
38+
default -> {
39+
yield month + " is bad"; //must be in a code block
40+
}
41+
};
42+
}
43+
}

src/DataTypes/Transitions/ParsingValues.java src/DataTypes/Casting/ParsingValues.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package DataTypes.Transitions;
1+
package DataTypes.Casting;
22

33
public class ParsingValues {
44
public static void main(String[] args) {

src/OOP/POJOandRecord/LPAStudent.java

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package OOP.POJOandRecord;
2+
3+
public record LPAStudent(String id, String name, String classList) {
4+
//fields are final, can't be modified
5+
6+
}

src/OOP/POJOandRecord/POJO.java

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package OOP.POJOandRecord;
2+
3+
public class POJO {
4+
//plain old java objects
5+
6+
//used to house data and pass between functional classes.
7+
8+
//mostly getters and setters
9+
10+
//usage with databases, files or streams
11+
12+
//may be called JavaBean/Bean
13+
14+
//also entity
15+
16+
//data transfer object
17+
18+
19+
public class Student{
20+
private String id;
21+
private String name;
22+
private String classList;
23+
}
24+
25+
public static void main(String[] args) {
26+
LPAStudent recordStudent = new LPAStudent("111333", "Michael", "Java");
27+
System.out.println(recordStudent);
28+
System.out.println(recordStudent.name() + " is taking " + recordStudent.classList());
29+
}
30+
}

0 commit comments

Comments
 (0)