04 October 2009

Java early Basics



//Console commands
$ javac hello.java //compiles hello.java file and produces hello.class
$ java hello //runs hello class
$ java hello xyz //runs hello class with parameter, send parameters to java main method which must be created with the syntax
public class Hello {
public static void main (String[] args){
//is start method of a java class and not requires return value so it
//is void, static so it is kept on the ram memory, and also static
//methods not requires to create an object to call.
System.out.println("Hello"+args[0]); //arg[0] gets first parameter which is xyz at command line
}
}

Creating an object
public class Xyz{ //class name must start with the capital letter
public void methodX(){ //method name should start with small letter, this method is not static so for to call this method requres to create Xyz object.
System.out.println("written X"); // for eclipse easy way to write System.out.println is just type "syso" and press shift+space
}
public static void main (String args[]){ // init method of Xyz class
Xyz xyz = new Xyz(); // which means create an object with the name of control xyz from Xyz
xyz.methodX(); // call method X over the xyz control
}
}

//javadoc
//creates referance document from comments in the class which written in /** blablabla */
//for to create javadoc just type $ javadoc classname
@see //referances javadoc to another java class or method. @see classname#methodname
@version //versionNr defines version of the document
@return //defines return description of method for javadoc

objects and assignment
class Number {
int i;
}
public class Assignment{
public static void main (String[] args){
Number nr1 = new Number(); //creates nr1 object
Number nr2 = new Number(); //creates nr2 object
nr1.i = 1; //assign 1 to nr1 object i value
nr2.i = 0; //assign 0 to nr2 object i value
nr1 = nr2; //assign
//referenced object of nr2 to nr1. important point is that just reference
//point is changed, nr1 value which is 1 is still on the memory but nr1
//is now pointing the object which nr2 points. nr1 = 0 and nr2 = 0
nr1 = 2;
// now nr1 and nr2 is pointing same object and when we assing a value
//to nr1 it also change the value of nr2 because they using and calling
//same object. nr1 = 2 and also important point is that also nr2 = 2
}
// now what about the object which used to nr1 and contains 1 value? it is not used so garbage collector will destroy it.
}
Objects comparations
public class comparation{
public static void main (String[] args){
Integer o1 = new Integer(100)
Integer o2 = new Integer(100)

o1 == o2; //false - because it says object o1 is referencing same object with object o2 NO
o1 != 02; //true - opposite of first case

}
}

//Controls
while (x<y){ ... }
do { ... }while(x
for (int i = 0, int j = 1; i<20 && j > 10; i++, j--) { ... } // we can use 2 variable in a for loop
if (method1() || method2()) { ... } else if (method1() < method2()){ ... }
switch (x) { case 1: .... break; case 2: ... break}

labelxxx:
for(int i = 0; i<10; i++){
for(int j = 0; j<10; j++){
...
break labelxxx;
}
}
continue;
return;

//Constructor
class ExampleClassForConstructor {
public ExampleClassForConstructor(){ //same name with class name, starts with capital character
...
}
}
public class ExampleClassConstructorCaller {
public static void main (String[] args){
new ExampleClassForConstructor();
}
}

System.gc();

Fi



14 August 2008

Simple JSF Login application in 8 step

This example simple JSF login application that takes username and password from user, if username and password equals "a", program directs browser to "success" jsp page, if not equals directs browser to "failure" page.
You can download
Netbeans Project folder/codes in rar format

Required platform: Netbeans with JSF plugin (optional- I have explained the way with the netbeans 6.1), Java platform, Glassfish, Tomcat etc.

1. Open Netbeans IDE and create web application project with JSF

2. For application we need 3 jsp page login.jsp (our JSF page), fail.jsp, and success.jsp .

3. Create login.jsp . This jsp page include jsf codes to get username and password from the user.

<%@ page contentType="text/html"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>

<f:view>
<html>
<head><title>JSF Simple Login Example</title></head>

<body>
<h:form>
<table>
<tr>
<td><h:outputText value="Enter Login ID: "/></td>
<td><h:inputText id="loginname" value="#{SimpleLogin.loginname}" /></td>
</tr>
<tr>
<td><h:outputText value="Enter Password: " /></td>
<td><h:inputSecret id="password" value="#{SimpleLogin.password}" /></td>
</tr>
<tr>
<td> </td>
<td><h:commandButton value="Login" action="#{SimpleLogin.CheckValidUser}" /></td>
</tr>
</table>
</h:form>
</body>
</html>
</f:view>

4.Create fail.jsp that simply displays "fail!" text on the the browser.

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h2>Fail!</h2>
</body>
</html>

5. Create success.jsp
that simply displays "success!" text on the the browser.

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h2>Success!</h2>
</body>
</html>

6. Now we are creating SimpleLogin.java class. This class processing username and password variables and according to result returns "success" or "fail".

package ebuz;

/**
*
* @author emrah dayioglu
*/
public class SimpleLogin {

String loginname;
String password;

public SimpleLogin() {
}

public String getLoginname() {
return loginname;
}

public void setLoginname(String loginname) {
this.loginname = loginname;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String CheckValidUser() {
if (loginname.equals("a") && password.equals("a")) {
System.out.println("chandan");
return "success";
} else {
return "fail";
}
}
}

7. Now we are creating/modifying faces-config.xml file as;

<?xml version='1.0' encoding='UTF-8'?>

<!-- =========== FULL CONFIGURATION FILE ================================== -->
<faces-config version="1.2"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<managed-bean>
<managed-bean-name>SimpleLogin</managed-bean-name>
<managed-bean-class>ebuz.SimpleLogin</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/login.jsp</from-view-id>
<navigation-case>
<from-action>#{SimpleLogin.CheckValidUser}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/faces/success.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{SimpleLogin.CheckValidUser}</from-action>
<from-outcome>fail</from-outcome>
<to-view-id>/faces/fail.jsp</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>

8. Finally we are creating/modifying web.xml file as;

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>com.sun.faces.verifyObjects</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.validateXml</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/login.jsp</welcome-file>
</welcome-file-list>
</web-app>

This application is just demonstrate JSF functionality to create user login application. For real project aplication requires session, and database connectivity.

07 July 2008

Use Cases

Use cases
Use cases represent functionality of the system.
an use case description includes;
------------------------------
Title:
Short Description:
Pre condition:
Description of the procedure:
Effects:
Comments:
------------------------------
An use case must be simplified, generalized, abstract, technology independent, implementation independent.

An example of use case:

University Calender
---------------------------
Title: Insert Lecture
Short description: Lecturers types room, time and title of the lectures and inserts it.
Pre Condition: There is not any Lecture of that title yet
Description of procedure:
- check whether title already exist
- check whether room is free at the given time
- if first is false and second is true insert new lecture
- again display data of the lecture
Effects: Lecture is inserted or error message
--------------------------

Developing Business Application

System Analysis
System analysis is made on these approaches, Structured analysis and object oriented analysis. It requires requirement specification from customer and target specification form developer.

System Analysis Problem
  • Conflicting views
  • Unclear aim of the system
  • high complexity of the tasks
  • communication and language problems
  • change of requirements
Requirements
There are two types of requirements
  • functional requirements defines actions and expected result
  • Non functional requirements defines technical, ergonomics and quality of service
Requirement specification documents includes;
  • goals
  • general descriptions
  • definitions
  • product environment
  • functional and non functional requirements
  • approval criteria
good requirement must be;
  • not have incomplete processes descriptions
  • not have implicit assumptions
  • not have illegal universal quantifier
  • not have incomplete conditions
  • not have unclear processes
  • not have semantically weak verbs
Then Developing activity requires
  • Use cases
  • Use case diagram
  • Class diagram
  • Activity diagram

Model Driven Developement ( MDD )

What is MDD?
For MDD we can say new generation programming. Before MDD, we were programming with low level machine language (10100111) this is 1st generation, then assembly code programming (mov al, 61h) 2nd generation, then Programming languages C, Java, Pascal, Basic more understandable languages are 3th generation. MDD makes these 3th generation programming techniques more understandable and abstract. MDD is a UML based programming, UML is a modeling standard and you are desingning and constructing abstract prototype of your program with symbols instead of coding. MDD is a technique to generation code from an UML model.

What are benefits of MDD?
  • less development time
  • high software quality
  • high maintainability
  • reusability
  • high manageability of complexity thought abstraction
  • interoperability
  • up-to-date documentation
Cornerstones of MDD
  • Domain analysis
  • Meta modeling
  • Model driven software generation
  • Template Languages
  • Domain driven framework design
  • Principle of Agile Software development
  • Development and use of open source infrastructure
MDD infrastructure
  • Modeling Language (meta model, concrete syntax)
  • Generator
  • Destination Platforms

Software Developement Processes

Waterfall Model
Waterfall model is a sequential developments model, its phases are Requirements, Design, Implementation, Verification, and Meintenance. In this model passing to following step is only possible when the current step is fully completed. It is applicable for large software projects, but this model not flexible to changes and not iterative.

Spiral Model
It is combination of prototyping model and waterfall model. It is more adaptable than Waterfall model because it has iteration.

V Model
Its concept not to much different than Waterfall model but in V model each step related with test phase.

Unified Process
It is more iterative model, each phases these are Inception, Elaboration, Construction, Transition have iteration on it and each iteration results executable system. It is use case driven model so use cases important in this model.

Agile Software development Model
It is fast, iterative and not so much strict model. Social factors are taken into account in this model. It is more suitable for research project but it has high risk.

Extreme programming (XP)
This model separate tasks and each team is responsible their own tasks. Before the coding input and output of tasks must be defined then it will be filled. After completion of tasks each testing is made. Working small results are combined together and after each addition whole test is made. But in this model working groups must use common coding rules.

Top-Down
In this technique programmer separate the task into small tasks. Then he writes main function, then sub functions.

Buttom-Up
This technique is opposite of Top-down, first sub functions are written then main function is written.

06 July 2008

Model Driven Development ( MDD )


MD(S)D - Model Driven Software Development
MDE - Model Driven Engineering
OMG - Object Management Group
MOF - Meta Object Facility
UML - Unified Modeling Language
MDA - Model Driven Architecture
ADM - Architecture Driven Modernization (reverse engineering)

Goals of MDD
  • Reducing development times
  • Rapid prototypes for presentation to customer
  • Easier change to new technologies
  • decoupling platform and domain knowledge
  • model-code coherency
  • well defined software architecture
  • up to date documentation
MDD infrastructure basic is established on three aspect these are modelling language, generator and destination platform.

There are three different codes parts in MDD
  • Generic code parts
  • Schematically repeated code parts
  • Individual code parts
What are benefits of MDD?
  • It increase development speed
  • It depends on a software architecture so it has high quality
  • Reusability of model
  • manageability of complexity through abstraction
  • Productive environment
  • Interoperability
for more information download pdf file that explain MDD in details.

05 July 2008

Software Engineering

Software Development Processes
  • Waterfall model
  • Spiral model
  • V model
  • Unified Process
  • Agile Software Development
  • Extreme Programming (XP)
  • Top-down and Bottom-Up design
What is MDD?
Model Driven Design. It converts from model to program with generator. What is the advantage of MDD?
  • Reduce development times
  • Rapid prototypes for customer presentation
  • easier change to new technologies and platforms
  • Decoupling of domain and platform knowledge so software developers require less technical knowledge
  • Model-code coherency
  • Well defined software architecture
  • Up to date software documentation
What is MDA?
Model Driven Architecture is an approach to develop platform independent model to Platform specific models to computer run such as domain specific languages C, Java etc. In this topic I will explain AndroMDA, it is a Model driven architecture generator. It converts UML to programming language codes. There are four layers background of this generation;
  • Presentation Layer (Struts, JSF)
  • Business Layers (Java Beans, Spring)
  • Data Access Layer (Hibernate)
  • Data Stores (MySQL)
First of all I will explain software development processes;

Unified Process (Rational unified Process - RUP)
RUP is iterative incremental model and in this model Use Cases are important so it requires detailed use cases. It has four phases;
  • Inception: This step related with business case, project scope, use cases, architecture and risk analysis.
  • Elaboration: This step related with the elaboration of cases in Inception step and defining the architecture of program.
  • Construction: this step is development step and takes more effort than other steps. During the development all divided tasks have iteration and each iteration gives executable result.
  • Transition: Deployment of project and finalizing the project.
Agile Software Development
Agile requires more communication among group members because it has general plan for long term, and it requires detailed planning for short term. This way gives more flexibility for project so this method easy adaptable to changes. It suitable with research project that have high risks.

Extreme Programming (XP)
It is a simple programming methodology, in this method whole program is divided in small parts and tested each part before implementation and after implementation. Every programmer responsible for own part but also can modify other files. It finish with the integration of the whole part. But during the developments step it requires common coding rules.

Software quality features
  • Functionality: Are the required functions available in the software? Accuracy, suitability, interoperability, compliance, security.
  • Reliability: How reliable is the software? Maturity, recoverability, fault tolerance.
  • Usability: Is the software easy to use? learnability, understandability, operateability, attractiveness.
  • Efficiency: How efficient is the software? time and resource behavior.
  • Maintainability: How easy is it modify the software? Stability, analysability, ,changeability, testability.
  • Portability: How easy is the transfer of the software to another environment. installability, replaceability, adaptability, coexistence.
All these quality features are tested by quality standard ISO/IEC 9126.

What are the software quality conflicts?
  • Lack of quality awareness: All involved person to develop software have to be informed about quality criteria.
  • Different interest of involved persons: User focuses on usability of the software but at the other side developer focuses on maintainability.
  • Time and cost: Accuracy of required times and efficiency.
Why does software development require model?
  • Modeling is necessary to meet requirements of clients with to-be and as-is analysis and also use cases.
  • Modeling is helpful in correct design of software. Modeling and programming language is on different levels. Models says how to do, but programming language says how to do it.
  • Modeling is helpful to acquire the appearing the structures. Structural aspects can be well represented using visual modeling languages.
  • Modeling are used to documentation.



22 June 2008

Simple Session Bean - Entity Bean

This example shows how is working and how is interaction
between Session Bean and Entity Bean

//Session bean - Converter
package ejb;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Stateless
public class ConverterBean implements ConverterLocal {

@PersistenceContext
private EntityManager em;

public void storeTransaction (int amount, int rate) {
EuroToDollar rec = new EuroToDollar();
rec.setAmount(amount);
rec.setRate(rate);
em.persist(rec);
}

public int EuroToDollar (int amount, int rate) {
this.storeTransaction(amount,rate);
return amount*rate;
}

public void persist (Object object) {
em.perisist (object);
}
}

---------------

//Entity Bean - EuroToDollar
package ejb;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GeneratedType;
import javax.peristence.ID;

@Entity
public class euroToDollar implements Serializable {
private int id;
private int amount;
private int rate;

public void setId(int id){
this.id = id
}

@Id
@GeneratedValue (strategy = GenerationType.AUTO)
public integer getId(){
return id;
}

public integer getAmount(){
return this.amount;
}

public integer setAmount(integer amount){
this.amount = amount;
}

public integer getRate(){
return this.rate;
}

public integer setRate(integer rate){
this.rate = rate;
}
}

21 June 2008

Simple JSP - Servlet - Session Bean

This example shows how is simple structure of JSP, Servlet, Session Bean and interaction among them.


-------------------------
// index.jsp
// here is simple html structure
form name="convert" action="convert" method="post"
input name="money" type="text"
input value="Submit" type="submit"
// close codes with simple html structure

-----------------

// servlet convert.class

import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.ejb.EJB;
import ejb.converterlocal;

public class convert extends HttpServlet {
@EJB
private converterLocal ConverterBean;
protected void processRequest (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException

Printwriter out = response.getWriter();
String amount = request.getParameter("money");
Double amountMoney = new Double(amount);
double result = converterBean.euroToDollar(amountMoney.doubleValue());
out.println(result);
out.close;
}

--------------------------

// EJB session bean - ConverterLocal

package ejb;

import javax.ejb.Local;

@Local
public interface converterLocal {
double euroToDollar (double amount);
}

-------------------------

//EJB session bean - ConverterBean

package ejb;

import javax.ejb.stateless;

@Stateless
public class converterBean implements ejb.ConverterLocal {
double euroRate = 1,5;

public double euroToDollar (double amount){
return amount*euroRate;
}
}

These codes are not error checked so it is possible to face some small errors but all these errors are typing errors and easy to find. General srtucture of jsp-servlet-ejb is working.

15 June 2008

Comparison of Selected Business Process Modeling Tools


There are lots of BPM (Business Process Modeling) tools but each of them is looking to models from different perspective so selection process of the BPM programs is difficult. This resource includes selection criteria of BPM programs with three exampel which are Visual Architect, Borland Together and Bonapart. Each of them has different perspective, advantages, disadvantages, different tools and usage areas. This academic research will help to solve several questions on your mind. Download research

14 June 2008

Request document for software project proposal


This document is a example RFP document. It may help and be idea to create a RFP document. Download RFP

Real Estate J2EE software project final report


Here you can find simple project report that explain final status of a J2EE real estate project. Download report

01 June 2008

Erp consulting


ERP-Enterprise Resource Planning is core of all business processes in an enterprise. This system is difficult to install, manage and operate so requires broad knowledge. Most of the IT departments have not enough knowledge about ERP system, as a result of these, for migration to ERP system and operation of the ERP system enterprises require consultant who has experienced in this field. What does ERP consultant? What are they doing? These are important questions and in this research all these questions are answered.
For English version of the research
For German version of the research

25 May 2008

Second Life Marketing Research


There are a lots of research about Second Life but all researches are looking from Second Life side. Actually, is Second Life promising good future for marketers? This research is answering this question. And also other important questions, what does marketers in Second Life? Why are they need Second Life marketing? What are marketing areas and competitors of Second Life? You can find all answers for these questions at the given link. download pdf

24 May 2008

This site ebuz.org....



This site ebuz.org has been created to collect and share my notes which are obtained during master study in FH-Fulda about e-business and its related fields. I have published ebuz.org because all data (now I am adding content when I find free time...) lying in my hard disk pointlessly. And also I will translate these data to other languages which are German and Turkish as far as possible.