Skip to content

Instantly share code, notes, and snippets.

View hakaneroztekin's full-sized avatar

Hakan Eroztekin hakaneroztekin

View GitHub Profile
class Desk {
private String model;
private String material;
public Desk() { // Default constructor
model = "wd001";
material = "wooden";
}
public Desk(String model, String material){ // Parametrized constructor
class Employee {
String name;
Integer salary;
public Employee() {
name = "Daniel";
salary = 120000;
}
public void printDetails(){
@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;
// 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);
}
}
// 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!"/>
class Employee{
int id;
String name;
Address address; // <- aggregation here (Address is a class)
// ...
}
@FunctionalInterface
public interface MyFirstFunctionalInterface {
public void firstWork();
}
// 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();
// 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
//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();