Apache Maven Nedir?

Yayınlandı: Ocak 12, 2015 / Uncategorized

Maven javada proje geliştirirken , projede kullanılan teknolojileri bir arada tutan çatı görevine sahiptir. Bu teknolajiler : Spring , hibernate , Log4j gibi projede kullanılan teknolojilerin jar dosyalarıdır.

Bir uygulamanın maven projesi olduğu içersinde barındırdığı pom.xml dosyasından belli olur.
pom.xml: bu dosya maven içersinde kullanılan jar dosyalarının , uygulamanın nasıl çalışacağı gibi ayarlarının yapıldığı dosyadır.

Örnek pom.xml dosyası :

4.0.0
 POS
XXXXXIntegration
 war 0.0.1-SNAPSHOT
XXXXXIntegration Maven Webapp
  1.5 3.1.2.RELEASE
 7.5.4.v20111024
 2.4.2-fuse-00-05
 http://localhost:8080/manager/text
XXXXXXX
 tomcat
 tomcat
 javax.transaction
 jta
 1.1
 org.slf4j
 slf4j-api
 1.6.6
 org.slf4j
 slf4j-log4j12
 1.7.6
 log4j
 log4j
 1.2.17
 org.springframework
 spring-web
 ${spring.version}
 org.springframework
 spring-context-support
 ${spring.version}
 
 org.springframework
 spring-core
 ${spring.version}
 org.springframework
 spring-beans
 ${spring.version}
 org.springframework
 spring-expression
 ${spring.version}
 org.springframework.ws
 spring-ws-core
 2.1.4.RELEASE
 
 jdom
 jdom
 1.0
 
 jaxen
 jaxen
 1.1
 javax.servlet
 servlet-api
 2.5
 org.apache.cxf
 cxf-rt-core
 2.6.1
 
 org.apache.cxf
 cxf-rt-frontend-jaxrs
 2.6.1
 org.apache.cxf
 cxf-bundle
 2.6.1
 org.apache.axis
 axis
 1.4
 org.apache.mina
 mina-core
 2.0.7
 jar
 
 org.apache.mina
 mina-integration-beans
 2.0.7
 jar
 org.apache.mina
 mina-core

 org.apache.mina
 mina-integration-ognl
 2.0.7
 jar
 
 
 org.apache.mina
 mina-core
 org.apache.mina
 mina-integration-beans
 
 org.apache.mina
 mina-integration-jmx
 2.0.7
 jar
 
 org.apache.mina
 mina-core
 
 
 org.apache.mina
 mina-integration-beans
 
 org.apache.mina
 mina-integration-ognl
 javax.xml
 jaxrpc
 1.1
 wsdl4j
 wsdl4j
 1.6.2
 
 
 org.apache.axis
 axis-saaj
 1.4
 commons-logging
 commons-logging
 1.2
 commons-discovery
 commons-discovery
 0.2
 commons-lang
 commons-lang
 2.3
 
 cglib
 cglib
 2.2
 
 commons-collections
 commons-collections
 3.2.1
 org.hibernate.javax.persistence
 hibernate-jpa-2.0-api
 1.0.1.Final
 mysql
 mysql-connector-java
 5.1.9
 com.microsoft.sqlserver
 sqljdbc4
 4.0
 org.hibernate
 hibernate
 3.2.3.ga
 org.hibernate
 hibernate-entitymanager
 3.3.2.GA
 
 
 org.springframework
 spring-orm
 3.1.4.RELEASE
 
 org.hibernate
 hibernate-annotations
 3.3.0.ga
 org.hibernate
 hibernate-commons-annotations
 3.0.0.ga

 
 dom4j
 dom4j
 1.6.1
 antlr
 antlr
 2.7.7
 com.googlecode.genericdao
 dao-hibernate
 1.2.0
 org.quartz-scheduler
 quartz
 1.8.6
   remote
 
 BimKart
   org.apache.tomcat.maven
 tomcat6-maven-plugin
 2.2
 
 http://10.2.41.137:8080/manager/text
 TomcatServer
 /BIMCard tomcat
 tomcat 
local
 
 BimKart
   org.apache.tomcat.maven
 tomcat7-maven-plugin
 2.2
 
 http://localhost:8080/manager/text
 TomcatServer
 /BimKart tomcat
 tomcat 
tomcat7:undeploy clean install compile package tomcat7:deploy
 BimKart
 
 
 src/main/resources
 true
 
 
    org.apache.maven.plugins
 maven-compiler-plugin
 3.1
 
 ${project.java.version}
 ${project.java.version}
 org.apache.tomcat.maven
 tomcat7-maven-plugin
 2.2
 
 ${tomcat.deploy.context.path} true
 ${tomcat.manager.url}
 ${tomcat.username}
 ${tomcat.password} ${project.build.directory}/tmp/jetty-web.xml
org.apache.maven.plugins
 maven-war-plugin
 2.5

 ${basedir}/src/main/resources
 /Configuration
 
 **/*.properties

Java’da 2 hata türü vardır :

1:Compiler Error (Derleyici Hatası): 

Derleme öncesi yakalanan hatalardır. compiler

2:Runtime Exception(Çalışma zamanlı hatalar):

Exception Hiyerarşisi

Exception : ortaya çıkan istinai durumlardır.  Handle bu problemleri yönetmedir, Error ise exception’nın fırlattığı hatalardır, bu bölümde bunların kullanımını inceleyeceğim.

Bu hatalar çalışma zamanlı ortaya çıkan istisnalardır.  ör: NullPointerEx. , ArrayIndexOfEx…

package com.ozcan.exceptions;
 public class ExceptionHandler {
 public static void main(String[] args) throws Exception {
 NullPointerException nullPointerException = null;
 String[] arry = { "jsp", "jsf" };
 try {
 nullPointerException.equals("123");
 for (int i = 0; i < arry.length + 1; i++) {
 System.out.println(arry[i]);
 }
 } catch (ArrayIndexOutOfBoundsException e) {
 System.out.println("e1----" + e);
 }
 catch (Exception ne) {
 System.out.println("e2----" + ne);
 } finally {
 System.out.println("---every time it is runing");
 }
 }
 }

Try bloğu içindeki işlemlerin sırasını değiştirerek sırayla hataların çıktılarını alabilirsiniz.

e2----java.lang.NullPointerException
 ---every time it is runing
jsp
 jsf
 e1----java.lang.ArrayIndexOutOfBoundsException: 2
 ---every time it is runing

Checked ve Unchecked Exception

Bütün çalışma zamanlı exception’ar ve bütün hatalar  unchecked exception’dır.

checked exception vs unchecked exception in java

Java LinkedList (Bağlı Listeler)

Yayınlandı: Nisan 28, 2015 / Uncategorized

LikedList’ler diziler gibidir , Object yapısını  liste şeklinde tutabilirler, Datalar biribirine node yapıları ile bağlıdır, Node’lar bellek adresini işaret eder. buna bağlı olarak ardan bir eleman çıkarıldığı zaman node bir sonraki datayı gösterecektir.

ll2

LinkedList java.lang.Object java.util.AbstractCollection java.util.AbstractList java.util.AbstractSequentialList java.util.LinkedList LinkedList sınıfı List arayüzünü implemant eder.

public class LinkedList
extends AbstractSequentialList
implements List, Deque, Cloneable, Serializable

Dolayısıyla listelerle ilgili bütün metotları almış olur ve null dahil bütün öğelere izin verir. Özellikle get(), remove() ve insert() metotlarını listenin başına, sonuna veya ortasında bir yere uygulayabilir. Böylece bağlı listelerden, isteğe göre, stack (yığın -LIFO), queue (kuyruk -FIFO), deque (çifte sonlanmış kuyruk) yapıları elde edilebilir.

Java’da LinkedList sınıfı hem tek-bağlı hem iki-bağlı yapıdadır. Aşağıdaki örnekler, LinkedList sınıfı ile yapıabilen işlerden bazılarını göstermektedir. LİnkedLİst sınıfının iki tane kurucusu vardır: LinkedList() Boş bir bağlı-liste yaratır. LinkedList(Collection c) Parametrenin belirlediği koleksiyonu içeren bir bağlı-liste yaratır. Öğelerin sırası koleksiyonun iteratör’ünün (tekrarlayıcı) belirlediği sıradır.

LikedList’ler synchronized yapıdalar.

   List list = Collections.synchronizedList(new LinkedList(...));

LinkedList metodları :

boolean add(E e)

Appends the specified element to the end of this list.

voidadd(int index, E element)

Inserts the specified element at the specified position in this list.

booleanaddAll(Collection<? extends E> c)

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection’s iterator.

booleanaddAll(int index, Collection<? extends E> c)

Inserts all of the elements in the specified collection into this list, starting at the specified position.

voidaddFirst(E e)

Inserts the specified element at the beginning of this list.

voidaddLast(E e)

Appends the specified element to the end of this list.

voidclear()

Removes all of the elements from this list.

Objectclone()

Returns a shallow copy of this LinkedList.

booleancontains(Object o)

Returns true if this list contains the specified element.

Iterator<E>descendingIterator()

Returns an iterator over the elements in this deque in reverse sequential order.

Eelement()

Retrieves, but does not remove, the head (first element) of this list.

Eget(int index)

Returns the element at the specified position in this list.

EgetFirst()

Returns the first element in this list.

EgetLast()

Returns the last element in this list.

intindexOf(Object o)

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

intlastIndexOf(Object o)

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.

ListIterator<E>listIterator(int index)

Returns a list-iterator of the elements in this list (in proper sequence), starting at the specified position in the list.

booleanoffer(E e)

Adds the specified element as the tail (last element) of this list.

booleanofferFirst(E e)

Inserts the specified element at the front of this list.

booleanofferLast(E e)

Inserts the specified element at the end of this list.

Epeek()

Retrieves, but does not remove, the head (first element) of this list.

EpeekFirst()

Retrieves, but does not remove, the first element of this list, or returns null if this list is empty.

EpeekLast()

Retrieves, but does not remove, the last element of this list, or returns null if this list is empty.

Epoll()

Retrieves and removes the head (first element) of this list.

EpollFirst()

Retrieves and removes the first element of this list, or returns null if this list is empty.

EpollLast()

Retrieves and removes the last element of this list, or returns null if this list is empty.

Epop()

Pops an element from the stack represented by this list.

voidpush(E e)

Pushes an element onto the stack represented by this list.

Eremove()

Retrieves and removes the head (first element) of this list.

Eremove(int index)

Removes the element at the specified position in this list.

booleanremove(Object o)

Removes the first occurrence of the specified element from this list, if it is present.

EremoveFirst()

Removes and returns the first element from this list.

booleanremoveFirstOccurrence(Object o)

Removes the first occurrence of the specified element in this list (when traversing the list from head to tail).

EremoveLast()

Removes and returns the last element from this list.

booleanremoveLastOccurrence(Object o)

Removes the last occurrence of the specified element in this list (when traversing the list from head to tail).

Eset(int index, E element)

Replaces the element at the specified position in this list with the specified element.

intsize()

Returns the number of elements in this list.

Object[]toArray()

Returns an array containing all of the elements in this list in proper sequence (from first to last element).

 T[]toArray(T[] a)

Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.
Örnek için :
Node  sınıfını oluşturup içinde data ve node değişkenlerini tanımladık
package com.ozcan.llist;
public class Node {
public int data;
public Node nextNode;
public Node(int data) {
this.data = data;
}}

Daha sonra bu sınıfı kullanacak MyLinkedList class’ını oluşturup seneryoları ve ekleme (add) metodunu yazdık :

package com.ozcan.llist;
public class MyLinkedListTest {
 Node head;
 Node tail;
//node(data) -> node(data) -> node(data)
 //add
 //delete
 //find
public void add(Node node){
//scenario 1: linkedList is empty bu durumda gelen data il node'u oluşturacak
 //tail aynı zamanda ilk işaretçidir. gelen data (Node(5))
if( tail == null)
 {
 head = node;//ilk eleman olduğu için hem head hem tail node'u gösterdi.
 tail=node;
 }
 else{
 //scenario 2: lindekList is not empty bu durum için gelen data sona eklenip tail'e bağlanacaktır.
 //add Node(10) [Node(15)->Node(16)] Node(10)'u linkedliste'ye
 //ekleyecek olursak burda Node(16)'nın işaretçisi(tail) Node(10)'u gösterecektir.
 //Node(15)->Node(16)->Node(10)->
 tail.nextNode=node;
 tail = node;
}
 }
 }
 linkedList1
Ardından ne yaptığımızı test etmek için bir test sınıfı oluşturup Debug As ->Junit modunda çalıştırıp  node’lar ve gösterdikleri değerleri gördük.
llist2
package com.ozcan.llist;
import java.util.Iterator;
import org.junit.Test;
public class LinkedListTest {
@Test
 //org.junit.Test; kutuphanesınden bu anotation'u çektik.
 public void test(){
MyLinkedListTest linkedListTest= new MyLinkedListTest();
linkedListTest.add(new Node(5));
 linkedListTest.add(new Node(32));
 linkedListTest.add(new Node(20));
System.out.println("Fist data: " +linkedListTest.head.data +" Last Data: " + linkedListTest.tail.data);
}
}
 Test
LList3
devamı gelecek…

 Thread Giriş

Threadlar Javada aynı anda çalışaçak biren fazla procesi işlemci vasıtasyla sırayla yapmak için kullanılır. Thread’lerin çalışması JVM  nin kontrolü altındadır. bu durum JVM nin bir işletim sistemi gibi davrandığını gösterir.

yeni bir thread kullanmak için 2 yöntem vardır.  bu yöntemler  Thread Classını kalıtımla almak   Runnable İnterfacesi uygulamaya geçirmekle olur.

Run() metodunun kullanımı :

Parametre almayan Run() metodu thread tarafından çağrılıp  yeni bir parçaçık (stack) oluşturlur.

package com.ozcan.threads;
 public class C4Thread extends Thread { 
public void run() {
 System.out.println("Thread class"); 
} }

 package com.ozcan.threads;
 public class C4Runnable implements Runnable { 
     @Override public void run(){
          System.out.println("Runable interface");
 }
 }

Thread oluşturulmaya başlandığı zaman yeni instance oluşturma durumundadır.  start() metodu cagrıldığı zaman işlem durumuna geçer . run() metodu tamamlandiginda ise  zaman “dead” duruma gecer. Bu durumlarin kontrolu isAlive() ve getState() metotlari yardimi ile saglanabilir.

Thread sınıfı Runnable interfacesini uygulamaktadır. Runnable arabirimiz Run metoduna sahiptir. bu method start() ile başlatılır.

Bununla ilgili küçük bir örnek ve çıktısı çıktıya dikkat edilirse , rastgele bir üretim vardır.

package com.ozcan.threads;

public class C4Runnable implements Runnable {
 @Override
 public void run() {
 System.out.println("Runable interface");

 for (int i = 0; i < 5; i++) {
 String threadName = Thread.currentThread().getName();
 System.out.println("Process : " + i + "-> from "+threadName );
 }
 }
}

package com.ozcan.threads;

public class C4RunnableTest{
 
 public static void main(String[] args) {

 C4Runnable c4Runnable = new C4Runnable();
 Thread t4Start1 = new Thread(c4Runnable);
 Thread t4Start2 = new Thread(c4Runnable);
 Thread t4Start3 = new Thread(c4Runnable);
 t4Start1.setName("1th Thread");
 t4Start2.setName("2th Thread");
 t4Start3.setName("3th Thread");
 
 t4Start1.start();
 t4Start2.start();
 t4Start3.start();
 }
}

Runable interface
Runable interface
Process : 0-> from 3th Thread
Runable interface
Process : 1-> from 3th Thread
Process : 0-> from 1th Thread
Process : 2-> from 3th Thread
Process : 0-> from 2th Thread
Process : 3-> from 3th Thread
Process : 1-> from 1th Thread
Process : 4-> from 3th Thread
Process : 1-> from 2th Thread
Process : 2-> from 2th Thread
Process : 2-> from 1th Thread
Process : 3-> from 2th Thread
Process : 3-> from 1th Thread
Process : 4-> from 2th Thread
Process : 4-> from 1th Thread

Örnekte aynı kaynaktan çıktı için 3 thread oluşturup  ve bunları thread.setName() ile isimlendirip çalıştırdığımızda yukardaki gibi bir çıktı elde ettik bu çıktı JVM ‘nin o anki durumuna göre değişecektir.

aynı işlemi Run(); metodunu kullanarak yapalım :

 t4Start1.run();;
 t4Start2.run();
 t4Start3.run();

Runable interface
Process : 0-> from main
Process : 1-> from main
Process : 2-> from main
Process : 3-> from main
Process : 4-> from main
Runable interface
Process : 0-> from main
Process : 1-> from main
Process : 2-> from main
Process : 3-> from main
Process : 4-> from main
Runable interface
Process : 0-> from main
Process : 1-> from main
Process : 2-> from main
Process : 3-> from main
Process : 4-> from main

Burada Run metodu bir kez çalışıp  cıktıyı verdikten sonra 2.sine gecer aynı döngü burdada devam edip işi bitikten sonra 3.Run metodu başlar, sonuç bu kez sıralıdır. burada Thread Main thread’dan gelmektedir.

Thread Durumları

New: Start metodu çağrılmadan önceki tread halidir,  bu durumda thread objesi canlı durumda thread henüz başlatılmadığından cansız durumdadır.

Runnable: Start metodu çağırdığında thread burda ilk olarak runnable durumuna geçer daha sonraki işlemlerde wait , sleep’ten sonra tekrar runnable durumuna geçebilir.

Running : Bu durum olayların olduğu thread’ın çalışma durumudur bazı işlemlerden sonra tekrar runnable durumuna dönebilir.

Waiting : Thread’ın çalışmada olmadığı bekleme durumudur. diğer bir thread’ın iş yapmasını bekler, thread scheduler tarafından seçilmeyi bekler.

Blocked : senkronize bir block’a aynı anda sadece bir thread girebilir. İlgili objenin kilidine hangi thread sahipse o thread işini bitirene kadar diğer threadlar giriş yapamaz.

Terminated: Run metodu sonlandığında thread terminated durumuna geçer ve bir daha runnable olmaz.

Bazı Metodlar

t.sleep(1000) : metodu , hali hazirda calisan Thread’i, arguman olarak verilen belirtilmis sure kadar askiya alir(suspend)/uyutur.

t.yield():Bir cok JVM icin threadlerin priority degeri onemlidir. Birden fazla thread runnable durumundaysa yuksek oncelige(priority) sahip thread running durumuna gecirilmek icin tercih edilebilir. yield metodu cagrildiginda , hali hazirda calisan metot geri cekilir(runnable duruma) gecer ve yerini ayni priority degere sahip bir threade birakir.

join: Bir thread bitene kadar(run metodu sonlana kadar) diger threadlerin beklemesini sağlar.

   public final void join() throws InterruptedException 
   public final synchronized void join(long millis)
   public final synchronized void join(long millis, int nanos)


package com.ozcan.threads;

public class C4RunnableTest {

 public static void main(String[] args) throws InterruptedException {

 C4Runnable c4Runnable = new C4Runnable();
 Thread t4Start1 = new Thread(c4Runnable);
 Thread t4Start2 = new Thread(c4Runnable);
 Thread t4Start3 = new Thread(c4Runnable);

 t4Start1.setName("1th Thread");
 t4Start2.setName("2th Thread");
 t4Start3.setName("3th Thread");

 // t4Start1.setPriority(9);
 // t4Start2.setPriority(5);
 // t4Start3.setPriority(1);
 System.out.println("t4Start1.getState()-= " + t4Start1.getState());
 System.out.println("t4Start2.getState()-= " + t4Start2.getState());
 System.out.println("t4Start3.getState()-= " + t4Start3.getState());

 // t4Start1.yield();

 t4Start1.start();
 t4Start1.join();

 t4Start2.start();
 t4Start1.join();

 t4Start3.start();
 t4Start1.join();

 System.out.println("t4Start1.getState()-> " + t4Start1.getState());
 System.out.println("t4Start2.getState()-> " + t4Start2.getState());
 System.out.println("t4Start3.getState()-> " + t4Start3.getState());

 }
}

t4Start1.getState()-= NEW
t4Start2.getState()-= NEW
t4Start3.getState()-= NEW
Process : 0-> from 1th Thread
Process : 1-> from 1th Thread
Process : 2-> from 1th Thread
Process : 3-> from 1th Thread
Process : 4-> from 1th Thread
t4Start1.getState()-> TERMINATED
t4Start2.getState()-> BLOCKED
t4Start3.getState()-> RUNNABLE
Process : 0-> from 2th Thread
Process : 1-> from 2th Thread
Process : 2-> from 2th Thread
Process : 3-> from 2th Thread
Process : 4-> from 2th Thread
Process : 0-> from 3th Thread
Process : 1-> from 3th Thread
Process : 2-> from 3th Thread
Process : 3-> from 3th Thread
Process : 4-> from 3th Thread

Join kullanımı ile thread durumları yukarıda olduğu gibi birinin işi bittikten sonra başka biri devreye girer.

1.metot islem bitene kadar bekleyecektir. 2.metot verilen sure(milisaniye) kadar bekleyecektir. 3.metot da verilen sure(milisaniye+nanosaniye) kadar bekleyecektir.

Race Condition

Birden fazla thread , “ayni kaynaga” ulastiginda (read) problem olmaz.
Problem teskil edecek nokta ; birden fazla thread “ayni kaynaga”(instance variable), “ayni obje referansi” uzerinden ulasip degistirmeye calistiginda(write) ortaya cikabilir. bu duruma Race Condition denir.

Thread Synchronized

Thread safe yapısı  :Thread safe birden çok thread’ın aynı metoda eriştiğinde problem çıkmaması anlamına gelir. Java’da immutable objeler thread safe ozellige sahiptir.

Java Generics (Generikler)

Yayınlandı: Nisan 21, 2015 / Uncategorized

Genericler Giriş

Generic yapısı javada default olarak Class<T> şeklindedir. Bu kısımda dikkat edilirse class için T tipinde type kavramını tanımladık , aynı durum interface içinde geçerlidir.

Bu kullanım kodun tekrar kullanabilirliğini kolaylaştırıp  cast işlemlerine gerek bırakmaz.

Örnek kullanım için:

//Generic kullanmadan bir instance yaratalım 
List list = new ArrayList();
list.add("it isn't Generic");
String s = (String) list.get(0); //Zorunlu bir casting işlemi yaptık. 

//Aynı instance'yi generic kullanarak yaptık
List<String> list = new ArrayList<String>();
list.add("it is Generic");
String s = list.get(0);

Class<T> : Burda T için yapılan tanımlama ne ise nesne parametre olarak o tipten veri bekler bu Integer için İnt veri 

String için ise String bir veridir, aynı şekilde Obje için yada başka bir class için onun tipinde veri bekler.

Generic yapıları derleme zamanlı(CompileTime) denetleyici yapılardır.  çalışma zamanlı (RunTime) durumunda kodlar generic olmayan hali gibi çalışır.

package com.ozcan.generics;
import java.util.ArrayList;
import java.util.List;
 class ITmembers{
 List<String> listName = new ArrayList<String>(); 
}
 class SoftwareDeveloper extends ITmembers{
 
 }
public class Employees {
 public static void main(String[] args) {

 //Derleme Hatası
 List<ITmembers> developers = new ArrayList<SoftwareDeveloper>();
 //1.Genericer polimofik olarak bu yapıyı desteklemez .
 //2.Kullanılan generic tipi ile instance yaratılırken oluşturulan generic tipi aynı olmalıdır.
 ITmembers[] developer = new SoftwareDeveloper[5];
 //Generics kullanmadan bu haliyle tanımlayabiliriz
 
 }
}
Collection API Yapısı ve Genericler 

Collection Yapıları içersinde İnterfaceler aşağıdaki gibi  tanımlanmıştır.

public interface List<E> extends Collection<E> {}
 public interface Set<E> extends Collection<E> {}
 public interface Map<K,V> {}
 public class TreeSet<E> extends AbstractSet{

Api yapısında kullanılan bu default tipler şu şekilde düşünülmüştür.

E – Element, K – Key ,N – Number ,T – Type , V – Value

Devamı gelecek..

Java Collections

Yayınlandı: Mart 5, 2015 / Uncategorized

Collections-detail-1

Collection<T>

Benzer verileri aynı grupta tutmak ve onlarla işlem yapabilmek için javada collection yapıları kullanılır. Collection interfaceleri şu şekilde kullanılabilir.

List: verilerin liste şeklinde tutulmasında kullanılır.

Queue: kuyruk işlemleri için kullanılır .(verinin listeye girme sırasına göre çıkarılma işlemi (FIFO , LIFO) yapıları için kullanılır).

Set: her bir verinin yalnızca bir kez sette bulunma durumu için kullanılan yapılardır.

List<T> interface yapısına bağlı gruplar:

ArrayList<T>:Temel java programlarında ençok kullanılan esnek sade bir liste yapısıdır. aynı elemandan birden çok bulundurabilir.

Arraylist default 20 hanelik bir alan ayırır başlangıç olarak eleman sayısı 15’i geçtiğinde u alanı  bunu 2 katına yani 40 ‘a

çıkarıp bu şekilde dinamik bir yapı sağlar.arraylist

Vector<T>:Vector yapısını arrayListten ayıran özellikler farklı thread’ler le güvenli  senkronize bir yapıda çalışabiliyor olmasıdır. Senkron yapıya sahip olduğu için biraz daha yavaştır.

arrayList yerine  thraed Senkronize olması için vektor kullanılmalıdır.

Stack<T>:Vector sınıfından türemiştir ve yığın işlemleri için kullanılan yapılardır.

Linkedlist<T>:LinkedList özel bir yapıya sahiptir, veri yapılarının daha çok performans odaklı çözümleri için kullanılan birçok algoritma barındıran geniş bir çözüm kümesidir. List ve Queue yapılarını uygular ve bunlardan türemiştir.

Set<T> interface yapısına bağlı gruplar:

TreeSet<T>: İkili ağaç yapısını kullanır.

HashSet<T>:veri grupları için hash algoritmaları kullanır.

Küme mantığına sahiptir,

Aynı elemandan birden çok konulamaz dolayısıyla kümede en fazla 1 tane null değeri olur .

Elemanları kendine göre sıralar.

Java iki nesnenin eşitlik durumunu öğrenmek için equals ya da nesnenin hashCode‘nu kullanır

HashSet

Queue<T>  interface yapısına bağlı gruplar:

PriorityQueue<T> Öncelik durumuna göre kuyruk işlemi yapabilen bir sınıftır. LinkedList her yeni gelen veriyi bir öncekine bağlayarak kuyruk oluşturur

Map<K,V>  interface yapısına bağlı gruplar:

Anahtar(K) değer(V) ikilisine göre verileri işleyen bir yapıya sahiptir, collection interfacesinden bağımsızdır.

Map’ler Iteratable yapıya sahip değildir, dolayısıyla iterasyon gibi davranmaz ancak

HashMap<K,V>;

Anahtar Value değişkenlerine sahiptir.

Değerlere anahtar ile erişilir.

Her anahtar sadece 1 defa kullanılabilir.HashMAp Örnek

HashMap<integer,string> hMap = new HashMap<>();

hMap.put(1, “Spring”);
hMap.put(3, “Hibernate”);
hMap.put(4, “Servlet”);
hMap.put(2, “Maven”);

Set<Integer> keys = hMap.keySet();

for ( Integer key:keys) {
System.out.println(hMap.get(key));
}

HashTable<K,V>:

HashTable synchronized çalışırken HashMap synchronized değildir. Bundan dolayı performans olarak HashMap’in gerisinde kalır.

Null değerini hiç bir zaman kabul etmez NP ex. verir.

LinkedHashMap<K,V>;

TreeMap<K,V>

Web Servis – Web Services in Java

Yayınlandı: Ocak 29, 2015 / Uncategorized

Web Servis 

-Http protokolünü kullanarak haberleşen server client uygulamalarıdır.

-Veriler Xml dosya yapısında tutulur, Bu sayede farklı platformlar arası haberleşme sağlanır

-Web servis içindeki fonksiyonlar bu servisi kullanan uygulamalar içinde çağrılır.

Java’da 2 çeşit web servis oluşturma teknolojisi kullanılır.

1.JAX-WS (Java Xml Webservice)

-Bu servislerde mesajlar SOAP Protokolü ile xml formatta iletilir.

-Uzak metodlar server-client arasında çağrılır.

2.JAX-RS(Java RESTFul Webservice) 

-Representational state Transfer

-Veri transferi için belirli bir standart bulunmaz.

-JSON,Xml,HTML veya farklı formatlardaki veriler HTTP protokolü ile iletilir.

-Get,Put,Post,Delete => metodları clientte gelen isteklerin serverda nasıl işleneceğini belirtir.

Web Servis Oluşturma Yöntemleri 

1-Top-down

İlk olarak servisin ardından java kodunun  yazıldığı yöntemdir.

2-Buttom-Up

Öncelikli java iş mantığının daha sonra webservisin yazıldığı yöntemdir.

Java kod dokümantasyonunun nasıl kullanılabilirliği için JavaDoc yapısını inceleyiniz . Bu bağlamada büyük projelerde takım çalışması içersinde  kodda okuma kolaylığı nelerin ne zaman kimler tarafından oluşturulduğu/değiştrildiği hem zaman kaybını en aza indirmeaçısından hemde yazılımın anlaşılabilirğinden oldukça önemlidir.   javadoc’a özgü birkaç etiketi yazalım.

@param  : metodun parametrelerinin önüne konur .

@author   : kullanıcı adı

@since     : kodun yazıldığı tarih

@return    : geridönüş değerlerinde kullanılır.

@throws   :istisna durumları için. gibi ..

JavaDoc class, interface ,final..dan  önce, nesne ve sınıf değişkenlerinden önce /**  ……. …… .. */ syntax ı ile yazılır..

bunları daha iyi kavramak için aşağıdaki örneği inceleyelim .

package com.cjhs.global.me.education.dto;
import com.cjhs.framework.dto.BaseDto;
 /**
  * EducationCndDto
  * 
  * @author Ozcan
  * @since 2014. 08. 20
  * 
  */
 public class EducationCndDto extends BaseDto {
/**
  * serialVersionUID 5425945162131361520L
  */
  private static final long serialVersionUID = 5425945162131361520L;
  private String serverCode = null;
/**
  * @param serverCode
  * the serverCode to set
  */
  public void setServerCode(String serverCode) {
  this.serverCode = serverCode;
  }
/**
  * @return the serverCode 
  */
  public String getServerCode() {
  return serverCode;
  }
}

Dökümantasyon

Java Multi-Threaded nedir ?

Yayınlandı: Ağustos 29, 2014 / Uncategorized

Threadlar Javada aynı anda çalışaçak biren fazla procesi işlemci vasıtasyla sırayla yapmaya yarar:

bu işlemler javada 2 yontemle yapılabilir;

1.  extends Thread classını kullanarak

2.  implements Runnable interfacesi ile.

örneğimizde; 1. yöntem için MyThred, 2. yöntem için ise MyRunnable classlarını kullandık    MyMain classı ise bunların eşzamanlı tamamen işlemci heraketlerine göre random üretilen değer kadar kanal açmasını başlatır.

 

 MyThread MyRunnable  MyMain_result_