Java EE----IOC

Source: Internet
Author: User

Software 152 Wu Wenxin

Made up of compter plus udisk and related configurations:

The Compter section code is as follows:

public class Computer1

{

@Autowired

@Qualifier ("Udisk")

Private USB Mpdevice;

Public Computer1 () {}//cannot construct USB device here

public void SaveData (String data)//methods for implementing smart devices

{//insert,write,pop

Mpdevice.insert ();

Mpdevice.write (data);

Mpdevice.pop ();

}

Assembling a USB device to a computer

public void Setmpdevice (USB U1) {

TODO auto-generated Method Stub

MPDEVICE=U1;

}

}

The Udisk section code is as follows:

public class Udisk implements USB

{

public void Insert () {

SYSTEM.OUT.PRINTLN ("read-in USB drive");

}

Public String Read () {

SYSTEM.OUT.PRINTLN ("read data:");

return "Data";

}

public void Write (String s) {

System.out.println ("Write Data");

}

public void Pop () {

SYSTEM.OUT.PRINTLN ("Eject USB flash drive");

}

}

ApplicationContext Configuration and test code are as follows:

<bean id= "U1" class= "Cqvie.com.UDisk" >
</bean>
<bean id= "U2" class= "Cqvie.com.UDisk" >
</bean>
<bean id= "Thecomputer" class= "Cqvie.com.Computer" >

</bean>

public static void Main (string[] args) {

Computer c=new computer ();

USB u=new Udisk ();

C.setusbdevice (U);

ApplicationContext CTX = new Classpathxmlapplicationcontext (

"Applicationcontext.xml");

Computer c= (computer) Ctx.getbean ("Thecomputer");

C.savedata ("personal resume");

}

}

Operation Result:

Summary: Mentality can be successful. Learn Java method: Java learning, first of all to do before class, after-Class review and preview, to keep a sober mind at all times, and students to communicate with each other, learn from each other, learn to help others or others to help themselves. Learning Java, it is true to learn a lot of things, like the students mentioned. Java is not as big as the. NET family, Java's prosperity lies in the vast open source community, which also brings too many branches of the problem, how to choose a good learning route, for beginners, is indeed a very confused. In fact, no matter how many Java things, there are always rules to follow. The experience of Learning Java Foundation is to do more, think more, basic knowledge of learning can not superficial understanding, to trace the essence of the problem. So as to extrapolate, by point and face. All of Java's programming ideas are "object-oriented" programming. So we must lay a good foundation before the development of the higher realm, the foundation is the kingly way. Our foundation should be solid and solid. The so-called Foundation is not meant to be familiar with all Java code. To understand the structure of Java. Class,methode,object, a variety of import,extend let oneself in the structure of Java has a three-dimensional and overall understanding.

Learn Java must not impetuous. Speaking of impetuous, this is also a very worthy of my deep-thinking problem. I think I myself have this tendency, not only me, but the majority of people have this problem. Always like to talk about what language is best and what language is powerful. There's nothing wrong with this discussion, but when it comes to learning, it can make you lose a lot. In the course of learning, I worked very hard to keep myself calm, starting from the basics and even some seemingly unnecessary foundations.

Students to solid, step by step gradually learn, do not think of a step

Days.

Java EE----IOC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.