18 Eylül 2017 Pazartesi

Eclipse

Proje Yapısı
Şöyledir
Project Name
    --> .settings
    --> .bin
    --> lib
    --> resources
    --> src
    --> .classpath
    --> .project
Dizinlerin açıklaması şöyle
.settings
 This file records project specific settings and workspace preferences.

.bin
 folder is usually where the compiled files are copied to.

lib
 contains external libraries that are used in your project (like Apache Commons)

resources
 the resources like images, text, pdf, audio, video are usually copied here

src
 the folder where the project's source files are located.

.classpath
 It contains information that the JDT feature needs in order to properly compile
the project: the project's source folders, the output folders , and classpath 
entries.

.project
 This file is maintained by the core Eclipse platform, and its goal is to
describe the project from a generic, plugin-independent Eclipse view. 
Automatic Updates
Kapatmak için şöyle yaparız.
Install/Update > Automatic Updates > Uncheck “Automatically find new updates”

ClassPath
Yeni bir dizin eklemek için şöyle yaparız.
Project -> Properties -> Build Path -> Configure Build Path -> Add Class Folder
Workspace'te olmayan yeni bir jar eklemek için şöyle yaparız.
Project -> Properties -> Build Path -> Configure Build Path -> Add Externak JARs
Add Jar ile farkı şöyle
Add Jar - to include jar files in you build path which are already present in your project.
Add External jar - used to include jar files which are 'outside' your eclipse project workspace folder. They will either be linked or copied.
Code Style
Süslü parantez olmayan kodların aynı satırda olması yani şöyle
if(true) return 0;
Şöyle yaparız.
Window -> Preferences -> Java -> Code Style -> Formatter -> Edit (Active profile) -> rename it -> Control Statements -> select "Keep 'then' statement on same line", "Keep 'else' statement..." and "Keep 'else if' on one line"; and press Ok.

Plugin
Başlatırken çalışacak pluginleri görmek için şöyle yaparız.
General > Startup and Shutdown

Server
Tomcat sunucusu tanımlamak için şöyle yaparız
Window->Show View-> Other->Server->New Server

Spellcheck
Kapatmak için şöyle yaparız.
General > Editors > Text Editors > Spelling : Disable spell checking


DayOfWeek Sınıfı

from metodu
Şöyle yaparız.
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("ccc", Locale.GERMAN);
DayOfWeek mo = dtf.parse("Mo", DayOfWeek::from);
plus metodu 
Örnek
Şöyle yaparız
DayOfWeek dayOfWeek = DayOfWeek.TUESDAY;
DayOfWeek dayOfWeek1 = dayOfWeek.plus(10);
System.out.println(dayOfWeek1); // FRIDAY

15 Eylül 2017 Cuma

ChronoUnit Sınıfı

Giriş
Şu satırı dahil ederiz.
import java.time.temporal.ChronoUnit;
between metodu - days
(İkinci parametre - birinci parametre) değerini verir.

Örnek
Şöyle yaparız.
LocalDate d1 = ...;
LocalDate d2 = ...;

long daysInBetween = ChronoUnit.DAYS.between(d1, d2);
between metodu - hours
(İkinci parametre - birinci parametre) değerini verir.

Örnek
LocalDateTime kullanarak şöyle yaparız.
LocalDateTime timeNow = LocalDateTime.now();
LocalDateTime timeAfterSometime = timeNow.plusHours(4).plusMinutes(11);
long hoursDiff = ChronoUnit.HOURS.between(timeNow, timeAfterSometime); // 4
Örnek
ZonedDateTime kullanarak şöyle yaparız.
ZonedDateTime zd1 = ...;
ZonedDateTime zd2 = ...;
long x = ChronoUnit.HOURS.between(zd1, zd2);
between metodu - minutes
(İkinci parametre - birinci parametre) değerini verir.

Örnek
Şöyle yaparız.
LocalDateTime timeNow = LocalDateTime.now();
LocalDateTime timeAfterSometime = timeNow.plusHours(4).plusMinutes(11);
long minutesDiff = ChronoUnit.MINUTES.between(timeNow, timeAfterSometime); // 251
between metodu - month
(İkinci parametre - birinci parametre) değerini verir.

Örnek
Şöyle yaparız.
public long monthsBetweenJava8(Date fromDate, Date toDate) {
  if (fromDate == null || toDate == null) {
    throw new IllegalArgumentException();
  }
  LocalDateTime ldt1 = fromDate.toInstant().atZone(ZoneId.systemDefault())
    .toLocalDateTime();
  LocalDateTime ldt2 = toDate.toInstant().atZone(ZoneId.systemDefault())
    .toLocalDateTime();
  return ChronoUnit.MONTHS.between(ldt1, ldt2);
}

14 Eylül 2017 Perşembe

JPA Anotasyonları

Giriş
JPA anotasyonları için şu satırı dahil etmek gerekir.
import javax.persistence.*;
Entity
JPA @Entity Anotasyonu yazısına taşıdım.

Table
JPA Table yazısına taşıdım.

Column
JPA @Column Anotasyonu yazısına taşıdım.

Enumerated
JPA @Enumerated Anotasyonu yazısına taşıdım.

GeneratedValue
JPA @GeneratedValue Anoyasyonu yazısına taşıdım.

Id
JPA @Id Anotasyonu yazısına taşıdım.

JoinColumn
JPA @JoinColumn Anotasyonu yazısına taşıdım.

NamedQuery
Şöyle yaparız.
@Entity
@NamedQuery(name="NodeType.FetchNodeTypes", query="Select C FROM NodeType")
public class NodeType {...}
Bu sorgu daha sonra EntityManager.createNamedQuery() metodu ile kullanılabilir.

NamedNativeQuery
Şöyle yaparız
@NamedNativeQueries({
  @NamedNativeQuery(name = "Card.findPrefix",
    query = "SELECT DISTINCT(FLOOR(c.number/10000)) FROM Card c")
Bu sorgu daha sonra EntityManager.createNamedQuery metodu ile kullanılabilir.

Embeddable
JPA Embeddable yazısına taşıdım.

IdClass
JPA IdClass yazısına taşıdım

Temporal
JPA @Temporal Anotasyonu yazısına taşıdım.

Transient
Şu satırı dahil ederiz.
import javax.persistence.Transient;
Açıklaması şöyle
This annotation specifies that the property or field is not persistent. It is used to annotate a property or field of an entity class, mapped superclass, or embeddable class.
Version
JPA @Version Anotasyonu yazısına taşıdım.

OneToOne
JPA OneToOne İlişki yazısına taşıdım.

OneToMany
JPA ManyToOne İlişki yazısına taşıdım.

ManyToMany
JPA ManyToMany İlişki yazısına taşıdım.

@MappedSuperClass
@MappedSuperClass yazısına taşıdım.