亲身经历讲述:没有基础怎么学Java

Python017

亲身经历讲述:没有基础怎么学Java,第1张

没有编程基础的定义是没有写过程序,没有学过相关的课程,之前没有深入了解相关的概念。并不是说对计算机一窍不通。如果,你对计算机一窍不通,那么建议你先搞懂计算机,再来考虑是否学习Java从事Java程序开发最好是大学毕业生,不管是大专还是本科都比较合适,理工科的学生是最合适的;英语专业的也比较合适,纯粹文科的如果有兴趣,也可以。不爱钻研、坐不住,凡是3分钟热度,或者对计算机不敢兴趣等的不适合学习JAVA,即使一时努力,上了JAVA培训机构,要么结不了业,要么半途而废,不能在Java路上走得更远。首先是兴趣。兴趣是学习的最好老师其实最大的困难是在于克服自己。只要你有恒心,学好JAVA并不难。就算你没有基础,没有经验,没有任何概念。可是即使是发明JAVA的人,发明计算机的人在起初也是一张白纸。他们也是不断琢磨,不断学习和实践才出结果的。所有的JAVA高手都是从什么也不会学到什么都会的。兴趣很重要,只要你有兴趣,就会发现学习JAVA和打篮球一样简单。其次要努力。古语说的好:只要功夫深铁杵磨成针中国人做事就怕有怕认真。只要有恒心,你会发现学好JAVA兼职是小菜一碟,比老婆婆用铁杵磨针要简单多了。当然你会说你没有基础,那么你就在学JAVA之前,拿出3个月学计算机基础,怎么样!3个月不够,半年够不够。我想,只要坚持、努力,有恒心,要不了1年,就能学好JAVA。甚至半年就够了。方法很重要。技方法很重要,可以尝试看视频学习方法很重要,要找到有效的学习方法,这样学起来会如鱼得水的。比如,现在许多人看基础免费视频,学起来就比以前看书快很多,而且也更简单。避免被骗。如果决定上培训机构,“合适最好、谨慎小心、以防被骗”什么叫合适最好,就培训机构并不是越出名、学费越贵就一定越好。其实,好多培训机构广告打的猛,其实教学水平未必是最好的。Java培训费用动辄上万,骗子培训机构也非常多,所以要遵循“合适最好、谨慎小心、以防被骗”。可走捷径。可以考虑考虑上培训班其实,现在很多JAVA培训班已经具备比较成熟的教学方法,有经验实力的知名培训机构培训出来的学生更能受用人单位的认可。当然,不同培训机构对学员准入要求不一样,有的培训机构要求有基础的,有的零基础的都可以,学习的深浅也不一,时间也不一样。这个需要结合自己实际情况来做决定。

@Required注解测试 其只检查属性是否已经设置

首先我们需要在程序里面加上注解

<span style="font-size:18px">@Required

public void setProduct(Product product) {

this.product = product

}</span>

注意@Required只能设置在setter方法上

接着我们需要在 配置文件中加上这样一句话

<span style="font-size:18px"><bean class="org.springframework.beans.factory.annotation.

RequiredAnnotationBeanPostProcessor"/></span>

这是Spring的一个处理器用于检查

如果Spring的版本是2.5或以上,我们可以直接用下列方式来配置

<span style="font-size:18px"><beans

xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:p="http://www.springframework.org/schema/p"

<span style="color: rgb(255, 0, 0)">xml

扩展资料

@Required注释为为了保证所对应的属性必须被设置,@Required 注释应用于 bean 属性的 setter 方法,它表明受影响的 bean 属性在配置时必须放在 XML 配置文件中,否则容器就会抛出一个 BeanInitializationException 异常。下面显示的是一个使用 @Required 注释的示例。直接的理解就是,如果你在某个java类的某个set方法上使用了该注释,那么该set方法对应的属性在xml配置文件中必须被设置,否则就会报错!!!

例子如下:

Studnent.java

package com.how2java.w3cschool.required

import org.springframework.beans.factory.annotation.Required

public class Student {

private Integer age

private String name

public Integer getAge() {

return age

}

@Required //该注释放在的是set方法中,如果没有在xml配置文件中配置相关的属性,就会报错

public void setAge(Integer age) {

this.age = age

}

public String getName() {

return name

}

@Required

public void setName(String name) {

this.name = name

}

}

MainApp.java

package com.how2java.w3cschool.required

import org.springframework.context.ApplicationContext

import org.springframework.context.support.ClassPathXmlApplicationContext

public class MainApp {

public static void main(String[] args) {

ApplicationContext context = new ClassPathXmlApplicationContext("beanrequired.xml")

Student student = (Student) context.getBean("student")

System.out.println("Name:" + student.getName())

System.out.println("age:" + student.getAge())

}

}

第一次的xml如下:

<?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:tx="http://www.springframework.org/schema/tx"

xmlns:context="http://www.springframework.org/schema/context"

xsi:schemaLocation="

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-3.0.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<context:annotation-config/>

<!-- student bean的定义 -->

<bean id = "student" class="com.how2java.w3cschool.required.Student">

<property name = "name" value="派大星"/>

</bean>

</beans>

应该和注意到Student.java中的@Required注释应用在了两个set方法上,但是此时在xml的bean中只设置了一个属性,因此从报错,“ Property 'age' is required for bean 'student' ”

将对应的属性设置加上后的xml如下

<?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:tx="http://www.springframework.org/schema/tx"

xmlns:context="http://www.springframework.org/schema/context"

xsi:schemaLocation="

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-3.0.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<context:annotation-config/>

<!-- student bean的定义 -->

<bean id = "student" class="com.how2java.w3cschool.required.Student">

<property name = "name" value="派大星"/>

<property name = "age" value="5"/>

</bean>

</beans>