外文翻译 - 在本科自学java编程技能 初级编程课程_第1页
外文翻译 - 在本科自学java编程技能 初级编程课程_第2页
外文翻译 - 在本科自学java编程技能 初级编程课程_第3页
外文翻译 - 在本科自学java编程技能 初级编程课程_第4页
外文翻译 - 在本科自学java编程技能 初级编程课程_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

0外文文献AnEnvironmentforSelf-AssessingJavaProgrammingSkillsinUndergraduateFirstProgrammingCoursesAbstractInthispaperweproposeanewenvironmentforallowingstudentsofafirstprogrammingundergraduatecoursetotesttheirJavacode.ThisenvironmentallowsthestudenttolearnthebasicsoftheJavalanguagewithoutnecessarilyknowingtheobject-orientedfeaturesofthelanguageitself,andtheteachertoproposenewtestsbymakinguseofagraphicaltesteditor.Moreover,theclient-serverarchitectureoftheweb-basedversionoftheenvironmentisdesignedsothatthestudentdoesnotevenneedaJavavirtualmachineonitscomputingdevice,butonlyawebbrowser.ThislatterfeaturemakesourenvironmentausefultoolforubiquitoustestingofJavaprogrammingskills.1.IntroductionAcontinuouslygrowingnumberofundergraduatefirstprogrammingcoursesuseJavaasthefirstprogramminglanguage,recognizingthislanguagesroleinthedevelopmentofweb-basedsystemsandtheemergingprominenceoftheobject-orientedapproachtosoftwaredevelopment(see,forexample,4).Thereisnodoubtthattheprincipalfeaturesofobject-orientedprogrammingareofgreatbenefitwhenitcomestoconstructinglargesoftwaresystems,butitisalongjourneyfromthefirstprogrammingcoursetotheconstructionofsuchsystems.Forthisreason,severaleducatorsarguedthatitisbettertointroducestudentstostructuredprogrammingbeforeturningtoobject-orientedprogrammingandtootherapproachesthatarebeneficialforprogramminginthelarge(see,forexample,2).MotivatedbytheapparentlycontrastingdesireofusingJavaasthefirstprogramminglanguageandoffollowingthe“structuredprogrammingbeforeobject-orientedprogramming”approach,asimpleapplication,calledJavaMM(or,equivalently,Java-),hasbeendevelopedatthe1DepartmentofComputerScienceoftheUniversityofFlorence.ThisapplicationallowsthestudentstofamiliarizethemselveswiththebasicstructuresoftheJavaprogramminglanguageandwiththebasicnotionsofstructuredprogramming,withouthavingtobotherwithissuesrelatedtoobject-orientedprogrammingfromtheverybeginningofthecourse.AdetaileddescriptionofJava-(alongwithasurveyofexistingtoolsforteachingJava)canbefoundin1:TheapplicationitselfisfreelyavailablestartingfromtheJava-homepage(see9).Java-hasbeensuccessfullyusedsince2002withinthefirstprogrammingcourseofthedegreeprograminComputerScience:Inparticular,thetoolhasbeenusedduringthefirstmonthofthecourse,whilesuccessivelythestudentshavebeenintroducedtoamoresophisticatedIDE(suchasJCreatorLE10).Accordingtothesurveycompiledattheendofthecourse,thestudentsseemedtoappreciatethetool:OnlyonestudentoveralmostonehundredcomplainedaboutJava-,withoutspecifyingthereasonsofthecomplaint.Moreover,thenumberofstudentsthatpassedtheexamattheendofthefirsteditionofthecourse,inwhichJava-wasused,increasedbymorethan40%withrespecttothepreviousedition.Inthispaper,weproposeanextensionofJava-thatincludesaself-testexercisecomponent,whichallowsstudentstotesttheirknowledgeoftheJavalanguagebywritingandcheckingthecorrectnessofamethodperformingaspecificrequiredtask.Thisfilecontainsthespecificationofthemethodtobetested,thespecificationofacorrectimplementationofthemethod,andthespecificationofhowthetestinputhastobechosen.ThecheckerinterpretstheXMLfileinordertocomparetheresultofthesubmittedmethodwiththecorrectmethodonthespecifiedinput.Subsequently,itgenerateseitheranerrormessagespecifyingtheinputthatcausedtheerrororamessagestatingthatthetesthasbeenpassed.Fromtheteacherpointofview,wehavedevelopedagraphicaltoolthatallowstheusertoeasilygeneratenewtests,thatis,tocreatetheXMLfileassociatedwithatest(ofcourse,theteacherhastowriteandcompiletheJavacodecontainingthecorrectimplementationofthemethodtobetested).MostofthetextbooksonJavaprogrammingmakeuseofseveraldifferentkindsofself-testexercises.Moreover,severalauthoringprogramsenablesteacherstomake(Web-based)interactiveteachingmaterialsbasedontheseexercise-types:Anexampleofsuchprograms,available2bothforWindows-basedandforMacOS-basedcomputers,isthesetofHotPotatoesapplications(see8).However,asfarastheauthorsknow,notoolisavailabletogenerateJavacode-writingexercisesthatallowsthestudentstoverifythattheirsolutionsissemantically(notonlysyntactically)correct.In7atest-firstapproachtoprogrammingandtolearningisdescribed:Tothisaimtheauthorfirstusesanadhocframework,andthenusesJUnit.Hisextremeteachingapproach,however,isbasedontheassumptionthatobjectsreallyneedtocomefirst,while,aswesaidbefore,ourapproachassumesthatstructuredprogrammingcomesbeforeobject-orientedprogramming.Forthisreason,wedecidedtointegratetheJava-withtheself-testexercisecomponent(ofcourse,ourtoolcanbealsousedwithinaJavacoursewhereobjectsaretaughtfirst).Inthepaper,wealsoproposeaweb-basedclient-serverversionofJava-(includingtheself-testexercisecomponent)thatallowsthestudentstomakeuseofthistoolbymeansofbasicallyanywebbrowser,withoutevenneedingaJavavirtualmachine.Inparticular,theproposedenvironmentconsistsoftwomainingredients.Fromtheclientpointofview,therearestaticHTMLpages,whichallowstheusertowriteJavacode,tosubmitthecodetoaJavacompiler,toseeeitherthecompilationerrorsorthestandardoutputmessages,andtotesttheimplementationofaspecifiedmethod.Fromtheserverpointofview,thereisacollectionofservlets(foranintroductiontoservlets,see3),whichreceiveandcompileJavacodes,andgenerateeithererrororstandardoutputHTMLpages.Themainadvantageofthisapproachisthefactthattheclientsoftwarerequirementsareextremelylight,andbasicallyanycurrentlyavailablemobilecomputingdevicecanbeusedinordertoutilizetheJava-tool(ofcourse,standardcomputerscanalsobeused.).Inotherwords,thisenvironmentturnsouttobeausefultoolforubiquitousprogrammingandlearningJava.Thepaperisstructuredasfollows.InSection2,wedescribethestructureoftheXMLfilethatspecifiesatest,andwebrieflydescribethegraphicaltoolthatallowstogeneratethisXMLfile.InSection3,instead,wedescribethecomponentofJava-thatallowsthestudenttoexecuteonetest,whileinSection4weintroducethesoftwarearchitectureoftheweb-basedclient-serverversionofJava-.Finally,inSection5wepresentsomepreliminaryevaluationresultsregardingtheeffectivenessoftheJava-tool,whileinSection6weproposesomedirectionsforfutureresearchanddevelopments.32.ThetestspecificationEachtestinourframeworkconsistsofcheckingthecorrectnessofamethodimplementation.Thus,atestisdescribedbyspecifyingthesignatureofthemethod,thatis,thenameofthemethod,thetypeofitsreturnedvalue,andthelistofthetypesofitsparameters.Sinceourtargetistodeployaself-testtoolforundergraduatestudentsofafirstprogrammingcoursebasedonthe“structuredprogrammingbeforeobject-orientedprogramming”approach,inthefirstversionofourprogramwehavedecidedtoallowonlyasubsetofprimitivedatatypes,theStringclasstype,andarraysofthesetypes.Inparticular,thereturnedvaluesandtheinputparametercanbeint,double,char,boolean,String,oranarrayofanyoftheprevioustypes.Thedocumenttypedefinition(DTD)associatedwiththeXMLfilecontainingamethodspecificationisthefollowingone:Notethat,besidesthesignatureofamethod,theaboveDTDfilecontainssomemoreelements.Inparticular,atestdescriptionhastospecifythenameoftheclassthatcontainsthecorrectimplementationofthemethod,whichhasbeencodedandcompiledbytheteacher.Moreover,thetestcanbeperformedonfixedvaluesoftheparameters,onrandomvaluesoftheparameters,oronacombinationoffixedandrandomvalues:Inthecaseofrandomlychoseninputvalues,thetestdescriptionhastospecifytherangewithinwhichtherandomvalueshavetobechosen.Finally,inthecaseofrandomlychosenvalues,thetestcanspecifyhowmanytimesithastobeperformed.Asanexample,letussupposethatwewanttotestthe4implementationofamethodmaxBetweenTwo,whichissupposedtoreturnthemaximumbetweentwoinputintegernumbers:?10and10.Moreover,supposethatthecorrectimplementationofthismethodiscontainedintheclassMaximum.Then,theXMLfilespecifyingsuchatestisthefollowingone:1MaximumINTINT?10INT10TheXMLfilescontainingthespecificationofatestcanbemanuallycreatedbytheteacher:However,asimplegraphicalinterfacehasbeendevelopedinordertosupportthistask.Oncethetesthasbeenspecified,theteacherhastowriteandcompiletheclasscontainingthecorrectimplementationofthemethod.Inourexample,thisclassmightbethefollowingone:publicclassMaximum5publicintmaxBetweenTwo(inta,intb)returnab?a:b;Finally,theteachercanassociatewiththetestanaturallanguagedescriptionofthetestitself(tobeincludedinthefiledescription.txt)andacodetemplateofthemethodthatthestudenthastocode(tobeincludedinthefiletemplate.txt).Intheexampleofthemaximumbetweentwointegers,thedescriptionmightbe“Writeamethod,calledmaxBetweenTwo,that,giventwointegers,returnsthemaximumbetweenthem”,whilethecodetemplatemightbethefollowingone:intmaxBetweenTwo(inta,intb)3.ThetestexecutionFigure1showstheinterfacethroughwhichthestudentcanexecuteatest(alltheotherfunctionalitiesoftheJavaMMprogramaredescribedin1).Asshowninthefirstpicture,thestudentcanchooseonetestamongallthosethathavebeenspecifiedbytheteacher(inourcase,therearethreetestsavailable).Oncethestudenthaschosenatest,thecorrespondingcodetemplateanddescriptiontextareshowninthecodeandinthetestdescriptionpanel,respectively(asshowninthesecondandinthethirdfigure).Atthatpoint,thestudenthastowritethecodethatimplementsthemethod:ThiscodecanfinallybetestedbyclickingontheTestbutton.Iftheimplementationiscorrect(oratleastpassesthetest),aconfirmationmessageisshownintheOutputpanel,otherwiseafailuremessageisshowninthispanel(weareassumingthatthecodewrittenbythestudentissyntacticallycorrect,sinceotherwiseacompilationerrorwouldappearintheErrorspanel).Thefailuremessagealsospecifiesthenameofthemethod,thevalueoftheinputparameterthatcausedthefailure,theexpectedresult,andtheobtainedresult(see,forexample,thelastpictureofFigure1wherethetestfailureisduetothefactthatthebodyofthemethodmaxBetweenTwocontainedtheinstructionreturna13注意,除了方法的签名,上面的DTD文件包含更多的元素。特别是,一个测试描述指定类的名称,包含正确的实施方法,编码和编制的老师。此外,测试可以执行固定值的参数,参数的随机值,或固定和随机值的组合:在随机选择的输入值的情况下,测试描述指定的范围内随机值必须选择。最后,在随机选择的值的情况下,测试可以指定要执行多少次。作为一个例子,让我们假设我们想要测试的实现方法maxBetweenTwo,它应该返回两个输入之间的最大整数数字:?10和10。此外,假设的正确实现该方法包含在类最大。然后,XML文件指定这样的测试是下列之一:1MaximumINTINT?10INT10XML文件包含测试的规范可以手动创建老师:但是,一个简单的图形界面开发为了支持这项任务。一旦测试已指定,老师必须编写和编译的类包含正确的实现方法。在我们的例子中,这个类可能是下列之一:publicclassMaximumpublicintmaxBetweenTwo(inta,intb)returnab?a:b;最后,老师可以与测试测试本身的自然语言描述(包含在文件description.txt)和一个代码模板的方法,学生必须代码(包含在文件template.txt)。在两个整数之间的最大的例子中,描述可能“编写一个方法,称为maxBetweenTwo,给定两个整数,返回它们之间的最大”,而代码模板可能是下列之一:intmaxBetweenTwo(inta,intb)143.测试执行图1显示了界面,学生可以通过执行测试(JavaMM项目的所有其他功能1中描述)。第一张图片所示,学生可以选择一个测试在所有那些被老师指定的(在我们的例子中,有三个测试可用)。学生选择一个测试后,对应的代码模板和描述文本中所示的代码和测试描述面板,分别(第二和第三图所示)。在这一点上,学生必须写代码实现方法:这段代码最终可以通过单击Test按钮进行测试。如果实现是正确的(或至少通过测试),确认消息输出所示面板,否则失败消息显示在这个面板(我们假定代码写的学生在语法上是正确的,因为否则编译错误出现在错误面板)。失败消息还指定方法的名称,输入参数的值导致失败,预期的结果,获得的结果(见,例如,最后画的图1测试失败是由于身体的方法maxBetweenTwo指令返回一个包含ab?a:b,)。除了编译的代码写的学生(JavaMM应用程序的一部分),测试的执行基本上由两个步骤组成,两个传送特定的Java编程语言的特点。第一步是XML文件,描述了测试的解释:这一目标我们利用org.xml代码。sax包,让我们来解析XML文件和提取元素包含在测试规范(参见上一节)。第二步,相反,由调用方法写的学生和老师的类中包含的方法和检查是否两个调用返回相同的值:为了执行这个任务,我们的代码使用Java反射特性,也就是说lang.reflect.package.图1测试接口的执行3.1通过Java反射自动测试JavaReflectionAPI是一个强大的工具,它允许在运行时检查的结构类:特别是可以收集、对象的方法,在一个类中定义的方法签名。这种方式,我们能够动态检查产生的类文件编译的代码写的学生并检查它是否满足测试的要求,即,是否实现了相同的方法签名的一个老师:15Classparamtypes=teachermethod.getParameterTypes();Methodstudentmethod=null;trystudentmethod=studentclass.getDeclaredMethod(methname,paramtypes);catch(NoSuchMethodExceptionme)if(!teachermethod.getReturnType().equals(studentmethod.getReturnType()Java反射还允许创建新的对象从特定类的实例对象和动态调用方法检索前一个对象自省。这样,如果学生类正确实现请求的方法签名(如检查以前的代码片段),我们可以测试学生的方法返回相同的结果是否作为老师的方法在相同的输入:Objectteacherobject=teacherclass.newInstance();Objectstudentobject=studentclass.newInstance();Objectres1=teachermethod.invoke(teacherobject,args);Objectres2=studentmethod.invoke(studentobject,args);if(!(res1.equals(res2)else/KO:wrongresults我们希望观察到反射代码在这里(在一个简化的形式)实际上并不取决于JavaMM;实际上它可以作用于任何Java类文件。因此,它可以用来执行自动测试也发达Java编程课程。事实上,它可以很容易地扩展为了测试更多的需求,例如,”实现一个类继承自某个类或实现一个特定的接口”、“实现一个类,它定义了一个内部类”,等等。4.Web的环境在前面的部分中,我们描述了如何执行测试执行中JavaMM计划:在这种情况下,测试规范文件包含在本地文件系统上的一个目录中。然而,这种方法要求学生正在支持java的电脑,这电脑上所有的测试已经上传。为了让学生们任何计算机上执行测试,只需使用一个web浏览器,我们实现了一个WWW-based客户机-服务器版本的Java-。在客户端,学生访问servlet开始生成一个HTML页面包含可用演习的列表。一旦学生有选择的一个练习,测试的描述和代码模板加载。代码写在一个文本字段属于一个HTML表单,它可以发送到服务器以编译执行,或测试(后者行动之后才启用的选择练习)。在服务器端,相反,基于servlet环境中允许服务器编译代码,如果它是必要的,以执行测试遵循相同的步骤在前一节中描述。JavaMM的本地版本之间的主要区别和基于web的客户机-服务器版本的服务器可能诉讼IEEE高级学习技术国际会议(中国“04)0-76952181-218120.00美元9/04IEEE被迫管理多个编译或测试执行过程在同一时间。此外,测试的执行代码或可能需要很长一段时间。学生可以通过一个HTML页面,其中包含监控执行的状态执行,输出消息和错误信息产生的过程。直到终止执行这个页面刷新后由客户指定的秒数。当进程终止执行,客户端将通报终止

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论