This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Desk { | |
private String model; | |
private String material; | |
public Desk() { // Default constructor | |
model = "wd001"; | |
material = "wooden"; | |
} | |
public Desk(String model, String material){ // Parametrized constructor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Employee { | |
String name; | |
Integer salary; | |
public Employee() { | |
name = "Daniel"; | |
salary = 120000; | |
} | |
public void printDetails(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity // the class will be stored in the DB | |
class HighSchool { | |
@Id // Id annotation | |
@GeneratedValue(strategy = GenerationType.IDENTITY) // Auto generated value | |
@Column(name = "id") // We can specify the column name (optional) | |
private Long id; | |
@Column(name = "name") | |
private Long name; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In the example above, the userLister is not initialized | |
class DependencyProblem { | |
private UserLister userLister; | |
// gets users from DB and renders to the view (just a trivial example) | |
public void render() { | |
List<User> users = userLister.getUsers(); | |
view.render(users); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// index.xhtml | |
<?xml version='1.0' encoding='UTF-8' ?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" | |
xmlns:h="http://xmlns.jcp.org/jsf/html"> | |
<h:head> | |
<title>User Form</title> | |
</h:head> | |
<h:body> | |
<h:outputText value="Hello world!"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Employee{ | |
int id; | |
String name; | |
Address address; // <- aggregation here (Address is a class) | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@FunctionalInterface | |
public interface MyFirstFunctionalInterface { | |
public void firstWork(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// List Interface | |
// We can store the ordered collection of objects. It can have duplicate values. | |
List <data-type> list1= new ArrayList(); | |
List <data-type> list2 = new LinkedList(); | |
List <data-type> list3 = new Vector(); | |
List <data-type> list4 = new Stack(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ArrayList | |
import java.util.*; | |
class TestJavaCollection1{ | |
public static void main(String args[]){ | |
ArrayList<String> list=new ArrayList<String>();//Creating arraylist | |
list.add("Ravi");//Adding object in arraylist | |
list.add("Vijay"); | |
list.add("Ravi"); | |
list.add("Ajay"); | |
// Traversing list through Iterator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//LinkedList | |
import java.util.*; | |
public class TestJavaCollection2{ | |
public static void main(String args[]){ | |
LinkedList<String> al=new LinkedList<String>(); | |
al.add("Ravi"); | |
al.add("Vijay"); | |
al.add("Ravi"); | |
al.add("Ajay"); | |
Iterator<String> itr=al.iterator(); |
OlderNewer