-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJava Basics.txt
More file actions
153 lines (88 loc) · 3.77 KB
/
Java Basics.txt
File metadata and controls
153 lines (88 loc) · 3.77 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
Shortcuts
---------
psvm <tab> - public static void main
sout <tab> - system.out.println()
CMD + FN + F12 - displays available methods of a class
Build Mechanisms
----------------------
[ Maven ]
- acts like a make file for group together functions and processes
- build/project management tool
- dependency management and versions
- project structure
// Important POM.xml Properties
Archetype = Template
GroupId =
Artifact
pom.xml = project object model file
Maven Plugins = Modules
Maven Goals = the result the maven module method should produce (i.e. compile -> compile code)
*By default, Maven always tries to compile code using Java 5 which is outdated. Must change to the JDK you are using
*ALWAYS reimport your maven project after make changes to it or your pom file
[ Gradle ]
[ Ant ]
Building A Executable Jar
--------------------------------
jar tf target/sample_springboot_api-0.0.1-SNAPSHOT.jar // examine the contents of a jar
maven clean // cleans target directory and previously generated artifacts
maven install // generate a jar
Java Core Concepts
----------------------------
Working With Databases
---------------------------------
[ JPA - Java Persistence API ]
[ Hibernate ]
Variable Declaration
---------------------------
Funcitions
--------------
Object Oriented Programming Constructs
------------------------------------------------------
[ Class ]
- blueprint for a house; we can build as many houses as we want based on the blueprint
[ Instance ]
- each house I build using the blueprint is called an instance
[ Reference ]
- each house I build has a physical location on the disk; I can copy that reference as many times as I like, but there is only one house
House blueHouse = new House("blue")
House anotherHouse = bluehouse // this is a reference to the same "physical" object blueHouse (in memory)
this - keyword used to access/call the current class variables and methods; commonly used with constructors, setters, and getters
private String color;
public House(String color) {
this.color = color;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
}
super - keyword used to access/call the parent/superclass variable and method
class SuperClass {
public void printMethod() {
System.out.println("Printed in Superclass.");
}
}
class SubClass extends SuperClass {
@Override
public void printMethod () { // same name as method in Superclass
super.printMethod(); // call the superclass printMethod
System.out.println("Printed in Subclass");
}
}
Constructor Chaining
-----------------------------
One contstructor calling the next.
Method Overloading - providing two or more seperate methods in a class with the same name but different parameters; allows us to reuse the same method name; reduces duplicate code and we don't have to remeber multiple method names; can happen inside a single class or a subclass of that class
Method Overriding - defining a method in a subclass that already exists in the parent class with the same signature (name and arguments); recommended to put @Override above the method definition as an annotation; can't override static methods
Static Variables - uses static keyword; shared across all instances of the class
Instance Variables - doesn't use the static keyword; belongs to the specific instance of a class
Static Methods - uses static keyword; does not use instance variables
Instance Methods - belongs to an instance of a class; class must be instantiated in order to use the method
Depencencies - POM.xml
---------------------------------
Logging - Slf4j
----------------
- best logging API layer available for Java
- configuration file is defined in xml, but logback can bootstrap itself w/ a BasicConfiguration if no configuration file is found