本文系投稿,作者:林杰。

作者寄语:十年hello world,写的是人生,每一段代码代表每一年和人生的过程。

欢迎点击阅读原文,跳转作者博客围观。

知音专栏

Javaweb练手项目源码

常用设计模式完整系列篇

技术自媒体探讨交流圈子

【强化编程功底】算法文摘


//LinJie
//Ten years Hello world,actually writing is life !
//Original

//First year
public class LinJie{
 public static void main(String[] args) {
   //hello world
   System.out.println("hello world");
 }
}

//Second years
public class LinJie{
 public static void main(String[] args) {
   //hello world
   LinJie obj = new LinJie();
   obj.toString();
 }

 /* (non-Javadoc)
  * @see java.lang.Object#toString()
  */
 @Override
 public String toString() {
   return "hello world";
 }
}

//The third year
public class LinJie{
 private static LinJie instance;
 public static LinJie getInstance() {
   if(instance == null)
     instance = new LinJie();
   return instance;
 }
 /* (non-Javadoc)
  * @see java.lang.Object#toString()
  */
 @Override
 public String toString() {
   return "hello world";
 }
 
 public static void main(String[] args) {
   //hello world
   LinJie obj = LinJie.getInstance();
   obj.toString();
 }
}

//Fourth years
public class LinJie{
 private final String a; //required
 private final String b; //required
 
 private final String c; //optional
 private final String d; //optional
 
 //Builder
 public static class Builder{
   //required
   private final String a;
   private final String b;
   //optional
   private String c;
   private String d;
   
   public Builder(String a,String b) {
     this.a = a;
     this.b = b;
   }
   public Builder c(String val)
     { c = val; return this; }
   public Builder d(String val)
     { d = val; return this; }
   
   public LinJie build() {
     return new LinJie(this);
   }
 }
 
 private LinJie(Builder builder) {
   a = builder.a;
   b = builder.b;
   c = builder.c;
   d = builder.d;
 }

 /* (non-Javadoc)
  * @see java.lang.Object#toString()
  */
 @Override
 public String toString() {
   return c+" "+d;
 }
 
 public static void main(String[] args) {
   //hello world
   LinJie obj = new LinJie.Builder("lin", "jie").
       c("hello").d("world").build();
   System.out.println(obj.toString());
 }
}

//Fifth years
/*
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd">
 <bean id="linjie" class="com.linjie.LinJie"></bean>
</beans>
*/
public class LinJie{
 @Test
 public void test() {
   //hello world
   ApplicationContext context = new ClassPathXmlApplicationContext
               ("applicationContext.xml");
   LinJie obj = (LinJie) context.getBean("linjie");
   obj.hello_world();
 }
 public void hello_world() {
   System.out.println("hello world");
 }
}

//Sixth years
/*
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-4.0.xsd">
   <!-- 扫描 -->
 <context:component-scan base-package="com.linjie.aop">
   </context:component-scan>  
</beans>
*/
@Component("linjie")
public class LinJie{
 @Test
 public void test() {
   //hello world
   ApplicationContext context = new ClassPathXmlApplicationContext
               ("applicationContext.xml");
   LinJie obj = (LinJie) context.getBean("linjie");
   obj.hello_world();
 }
 public void hello_world() {
   System.out.println("hello world");
 }
}

//Seventh years
/*
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.0.xsd">
 <context:component-scan base-package="com.linjie.aop">
   </context:component-scan>  
 <aop:aspectj-autoproxy></aop:aspectj-autoproxy>  
</beans>
*/
/*
@Component("arithmetic")
public class Arithmetic {
 public void hello_world() {}
}
*/
@Aspect
@Component("linjie")
public class LinJie{
 @Test
 public void test() {
   //hello world
   ApplicationContext context = new ClassPathXmlApplicationContext
               ("applicationContext.xml");
   LinJie obj = (LinJie) context.getBean("linjie");
   obj.hello_world();
 }
 @Before("execution(* com.linjie.aop.Arithmetic.*(..))")
 public void Before_Loggin() {
   System.out.println("hello world");
 }
}

//Eighth years fail

//Ninth years fail

//Tenth years
public class LinJie {
 public static void main(String[] args) {
   String grow       = "hello world";
   String grow_up    = "hello world";
   String grow_up_up = "hello world";
   if(grow.equals(grow_up) && grow.equals(grow_up_up))
     System.out.println(grow);
 }
}