23 Åžubat 2012 | Etiketler: ,

Good code design should provide below features.

1. Reliability

2. Flexibilty

3. Segregation of Concern:

TransferMoney(){

Validation

Exception

Cache

Log

.

MainWork

}

In above example Validation,Exception,Cache and Log are not main tasks of TransferMoney function.Good designer should isolate diffrent task from each other.

4.Modularity : Your design should work dynamically.(Reflaction)

5. Mantability: Your design should be stable.(Open-Close Principle)

 

7 Aralık 2011 | Etiketler:

REST(Representational State Transfer) architecture relies on client-server communications.REST uses HTTP  for communcation between machines.It is not complex like RPC,SOAP.. etc.It uses HTTP for CRUD operations.

REST is not a standard.

REST is a lightweight alternative for Web Services.

REST is platform and language independent.

Soap message example:

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
 <soap:body pb="http://www.acme.com/phonebook">
  <pb:GetUserDetails>
   <pb:UserID>12345</pb:UserID>
  </pb:GetUserDetails>
 </soap:Body>
</soap:Envelope>

REST exmple:

http://www.acme.com/phonebook/UserDetails/12345

It is just a url, sending GET request over HTTP protocol.

  • Web Services often create SOAP/HTTP request and send it, then parse the SOAP response.
  • REST needs only a network connection.
With REST you are using postcard, but with soap envolpe is used.Postcards are easy to handle,and it has short content.
Rest is secure as SOAP. REST can be carried over HTTPS by sending encyrpted messages.

 Lets try to acess service restful with curl, in php language:

       $service_url = 'http://example.com/rest/user/';
       $curl = curl_init($service_url);
       $curl_post_data = array(
            "user_id" => 42,
            "emailaddress" => 'lorna@example.com',
            );
       curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
       curl_setopt($curl, CURLOPT_POST, true);
       curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
       $curl_response = curl_exec($curl);
       curl_close($curl);

       $xml = new SimpleXMLElement($curl_response);
2 Aralık 2011 | Etiketler: , ,

When a new class created from existing class it’s called inheritance.

Advantage of inheritence:

  • Reuse code
  • Accessbility
  • Easy to understand large program
  • Saves memory and user time.(result of reusing code.)
Disadvantage of inheritence:
  • Subclasses and parent classes become tightly-coupled.
2 Aralık 2011 | Etiketler: , ,

Encapsulation:

Encapsualtion uses for protecting class proporties or methods:

There are 3 types of protection:

   1. Private: Except itself, no class can access  proporties or methods of class.

   2. Public: All classes can access public methods and proporties.

   3. Protected: Only child class can access protected methods or properties.

 

Think about simple shopping senerio.Cutomer gives money to seller from his/her wallet.But seller can not reach the wallet directly.İt’s encapsulated from seller by cutomer.

29 Kasım 2011 | Etiketler: , ,

Last days i take some questions about “when java and when php?

So i did some search for server-side programming and decide to share some of  my studies with you.

Php:

Php is actually great platform for web applications.

In php each page is a script,so php is fine for dynamic web pages.

Java:

Heavy applications neeads java platform.For example transactions, distributed objects.. needs application server.

 

 

25 AÄŸustos 2011 | Etiketler: , ,

Very good tools to test regular expressions.

http://www.spaweditor.com/scripts/regex/index.php

 

http://gskinner.com/RegExr/

9 AÄŸustos 2011 | Etiketler: , , , ,
FacesContext facesContext = FacesContext.getCurrentInstance();
String aa = (String) facesContext.getExternalContext().getRequestParameterMap().get("category");
9 AÄŸustos 2011 | Etiketler: ,
//JSF
<h:outputLink value="login.xhtml">
	<h:outputText value="Login" />
	<f:param name="name" value="value" />
</h:outputLink>

//HTML
<a href="login.xhtml?name=value">Login</a>
3 AÄŸustos 2011 | Etiketler: , ,
Lets say “ byteImage” is your image in byte[] format.If you want to read it, you can use below code.
InputStream in = new ByteArrayInputStream(byteImage);
BufferedImage image= ImageIO.read(in);
21 Temmuz 2011 | Etiketler: ,

Persistence.xml is a standard configuration file for jpa.You should locate this file in META-INF folder that is under the WEB-INF.Apperance should be like below.

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
	xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
        http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
	<persistence-unit name="baglantiBir" transaction-type="RESOURCE_LOCAL">
		<provider>org.hibernate.ejb.HibernatePersistence</provider>
		<properties>
			<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
			<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
			<property name="hibernate.connection.password" value="" />
			<property name="hibernate.connection.username" value="root" />
			<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/eticaret" />
			<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
			<property name="hibernate.hbm2ddl.auto" value="update" />
			<property name="hibernate.show_sql" value="true" />
			<property name="hibernate.format_sql" value="true" />
			<property name="hibernate.connection.autocommit" value="true" />

		</properties>
	</persistence-unit>
</persistence>