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
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 MyClass{ | |
private Integer instanceVariable; // Instance variable | |
private static Integer classVariable = 5; // Class variable | |
public void myMethod(){ | |
String localVariable // Local variable | |
} | |
} |
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 TestingPassByValue() { | |
public static void main(String ... args){ | |
// myFavoriteHobby is Playing billard | |
Hobby myFavoriteHobby = new Hobby("Playing billard"); | |
// hobbyBackup is Playing billard | |
Hobby hobbyBackup = myFavoriteHobby; | |
// passing the value. Simply, you can think it | |
// like passing the value of the pointer (e.g. 42) | |
hobbyGame(myFavoriteHobby); |
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
public class StreamIntermediateOperations { | |
// map: The map method is used to map the items | |
// in the collection to other objects according to the Function passed as argument. | |
List number = Arrays.asList(2,3,4,5); | |
List square = number.stream().map(x->x*x).collect(Collectors.toList()); | |
// filter: The filter method is used | |
// to select elements as per the Predicate passed as argument. | |
List names = Arrays.asList("Reflection","Collection","Stream"); | |
List result = names.stream().filter(s->s.startsWith("S")).collect(Collectors.toList()); |
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
public class StreamTerminalOperations { | |
// collect: The collect method is used to return | |
// the result of the intermediate operations performed on the stream. | |
List number = Arrays.asList(2,3,4,5,3); | |
Set square = number.stream().map(x->x*x).collect(Collectors.toSet()); | |
//forEach: The forEach method is used to | |
// iterate through every element of the stream. | |
List number = Arrays.asList(2,3,4,5); | |
number.stream().map(x->x*x).forEach(y->System.out.println(y)); |
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!"/> |
OlderNewer