Friday, September 14, 2012

Simple Java Application

 This is the most simple Java Application. The Spring Framework will base on this later. Purpose of this app is to test the environment.

Environment:
Jdk1.7.07
Maven 3.0.4
Spring Source Tools Suits(STS) 3.0

Download Source code here
To open the source code:
File --> Import --> Maven --> Existing Maven Projects

If you are new to Maven, please visit  Maven Tutorial.








HelloApp
package org.sample;

import org.sample.service.BeanService;
import org.sample.service.impl.BeanServiceImpl;


public class HelloApp {
 public static void main(String[] args) throws Exception {

  BeanService beanService = new BeanServiceImpl("Good morning");

  beanService.sayGreeting();
 }
}

BeanService.java

package org.sample.service;

public interface BeanService {
  public void sayGreeting();
}

BeanServiceImpl .java
package org.sample.service.impl;

import org.sample.service.BeanService;

public class BeanServiceImpl implements BeanService {
  private String greeting;

  public BeanServiceImpl() {}

  public BeanServiceImpl(String greeting) {
    this.greeting = greeting;
  }

  public void sayGreeting() {
    System.out.println(greeting);
  }

  public void setGreeting(String greeting) {
    this.greeting = greeting;
  }
}

pom.xml

  4.0.0

  org.sample
  app0100
  1.0
  jar

  app0100
  http://maven.apache.org



Result:

Good morning

No comments:

Post a Comment