www.fatihkabakci.com

Personal Website and Computer Science TUR EN

JAVA JCF ALGORITMALAR(ALGORITHMS)

Last update: 10/3/2014 6:31:00 PM

Yazan:Fatih KABAKCI

Java koleksiyon mimarisine programatik olarak kolaylık ve esneklik getiren algoritmalar(algorithms), JCF içerisindeki nesneler arasında dönüşüm, elemanların sıralanması, nesneler içerisinde arama işlemleri gibi işlemleri sunan yapılardır.

Çalışma zamanında JCF nesnelerinin syncronized versiyonlarının elde edilmesi, checked tipli dinamik tip kontrolü sağlayan metotlar gibi daha bir çok işlevler JCF algoritmaları sayesinde programcılara sunulmuştur. Aşağıda programda basitçe koleksiyon mimarisinde sıklıkla kullanılan metotlar verilmektedir.




Programın kaynak kodu

Yukarıdaki programda ilk olarak 2,1,3,0,6,4 elemanlarından oluşan bir bağlı liste oluşturulmaktadır. 30.satırdaki Collection.sort(Collection) metodu bir koleksiyon içerisindeki elemanları küçükten büyüğe doğru sıralar. sort() metodunun bir de aşırı yüklenmiş versiyonu olan Comparator nesnesi ile kullanımı bulunur. Bu versiyonu ile sıralamaya kullanıcılar karar verir.

33. satırdaki Collections.binarySearch(Collection,data); metodu bir koleksiyon içerisinde aranan elemanın indeksini döndürür. Bunu da ikili arama algoritması kullanarak yapar.

36. satırdaki Collections.max(Collection); ise bir koleksiyon içerisindeki en büyük elemanı döndürür. Bunun minimumu bulan min() adında başka bir static metodu da mevcuttur.

Collections.shuffle(Collection); koleksiyonu karıştırmaktadır. Bunun anlamı koleksiyon elemanlarının yerini rastgele değiştirir.

Bir koleksiyon kullanılmadan önce mutlaka initialize edilmek zorundadır. Bunun anlamı new operatörü ile nesnenin yaratılmış olması veya daha önceden oluşturulmuş bir referansa ait olmasıdır. 40. satırdaki Collections.emptySet(); metodu boş bir Set nesnesi oluştururken, 41. satırda bu nesneye bir eleman eklenmeye çalışılırsa Java UnsupportedOperationException fırlatır. Boş liste tabiri bir JCF nesnesine null değeri atamak gibi düşünülebilir. Ancak boş liste vurgusu önemlidir ve koleksiyon akışını programın devamında yönlendirir, performans artışı sağlar ve kullanıcıya nesnenin boş olduğunu yapısal olarak hatırlatır.

Yukarıdaki programın ekran çıktısı aşağıda verilmektedir.



JCF içerisinde yukarıdaki programda bulunmayan bir çok metot bulunmaktadır. İhtiyaca göre çeşitli örneklendirmeler arttırılabilir.

JCF algoritmaları ile koleksiyon sisteminizi kolaylıkla yönetebilir, verilerinizi ekstra kodlar yazmadan kontrol edebilirsiniz.
There has been no comment yet

Name:


Question/Comment
   Please verify the image




The Topics in Computer Science

Search this site for





 

Software & Algorithms

icon

In mathematics and computer science, an algorithm is a step-by-step procedure for calculations. Algorithms are used for calculation, data processing, and automated reasoning.

Programming Languages

icon

A programming language is a formal constructed language designed to communicate instructions to a machine, particularly a computer. It can be used to create programs to control the behavior of a machine. Java,C, C++,C#

Database

icon

A database is an organized collection of data. The data are typically organized to model aspects of reality in a way that supports processes requiring information.

Hardware

icon

Computer hardware is the collection of physical elements that constitutes a computer system. Computer hardware refers to the physical parts or components of a computer such as the monitor, memory, cpu.

Web Technologies

icon

Web development is a broad term for the work involved in developing a web site for the Internet or an intranet. Html,Css,JavaScript,ASP.Net,PHP are one of the most popular technologies. J2EE,Spring Boot, Servlet, JSP,JSF, ASP

Mobile Technologies

icon

Mobile application development is the process by which application software is developed for low-power handheld devices, such as personal digital assistants, enterprise digital assistants or mobile phones. J2ME

Network

icon

A computer network or data network is a telecommunications network that allows computers to exchange data. In computer networks, networked computing devices pass data to each other along data connections.

Operating Systems

icon

An operating system is software that manages computer hardware and software resources and provides common services for computer programs. The OS is an essential component of the system software in a computer system. Linux,Windows

Computer Science

icon

Computer science is the scientific and practical approach to computation and its applications.A computer scientist specializes in the theory of computation and the design of computational systems.