SCJP Ch10 Development and Deployment.doc_第1页
SCJP Ch10 Development and Deployment.doc_第2页
SCJP Ch10 Development and Deployment.doc_第3页
SCJP Ch10 Development and Deployment.doc_第4页
全文预览已结束

下载本文档

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

文档简介

SCJP Study Notes: Chapter 10 DevelopmentChapter 10 Development1. Using the javac and java Commands1.1 Compiling with javacIn the exam, you need to understand classpath and d option javac options source files javac -help -classpath optionjavac -classpath com:. -g Foo.java Bar.java-d option (assume no package statement)MyClass.classcurrent directoryjavac -d classes source/MyClass.java tell the compiler to put the .class file to classes dir = d (destination)-d option with package statementcurrent directorypackage com.wickedlysmart;public class MyClass javac -d ./classes com/wickedlysmart/MyClass.java If com/wickedlysmart not exist, the -d option will build it. But if classes dir not exist = ERROR1.2 Launching Applications with java java options class argsjava -DmyProp=myValue MyClass x 1 Create a system property called myProp and set its value to myValue the value pair is retrieved in System.getProperties( )java -DcmdProp=cmdVal take 2 TestProps/ if the value contain spaceCommand Line ArgumentsLegal Declaration:static public void main(String args) public static void main(String. x) static public void main(String bang_a_gong)args0, args1, if access args1 without the actual arg = ArrayIndexOutofBound1.3 Searching for Other ClassesBoth java and javac use the same search algorithm1. the first place they look at the directory come standard with J2SE2. the second place is the directory defined by classpath3. classpath can be defined in OS env var or in command line in java and javac4. command line override the env vare.g. classpath /com/foo/acct:/com/fooo the search path is separated by “:”, “/” means root directoryo noted that subdirectory, e.g. /com will NOT be searchedo in windows, use “;” and “”o can use -cpe.g. -classpath /com/foo/acct:/com/foo:.“.” = search also the current directoryPackages and Searchingpackage com.foo;public class MyClass public void hi( ) import com.foo.MyClass;import com.foo.*;public class Anothervoid go( ) MyClass m1 = new MyClass( );/ alias namecom.foo.Myclass m2 = new com.foo.MyClass( );/ full nameRelative and Absolute Pathse.g. -cp dirB:dirB/dirCo dirB and dirB/dirC are relative paths (they dont start with a slash /).o when the current directory is dirA, dirB and dirC will be searched, but not dirAo when the current directory is root, since dirB is not a direct subdirectory of root, no directories will be searchedo when the current directory is dirB, no directory will be searchede.g. -cp /dirB:/dirA/dirB/dirCo current directory is dirA, root? dirB? both paths in the classpath are absolute, it doesnt matter what is the current directory, /dirB is invalid since it is not a direct subdir of root, the ans is ONLY dirC2. JAR Files* You dont need to know how to make JAR files for the examo jar command create META-INF directory and MANIFEST.MF file automaticallyo jar command wont place any of your files in META-INF/Finding a JAR file using a classpath is similar to finding a package file in a classpath. The difference is that when you specify a path for a JAR file, you must include the name of the JAR file at the end of the pathjavac -classpath ws/myApp.jar UseStuff.javajavac -classpath ws UseStuff.java put JAR files into the ext subdirectory, java and javac can find them3. Using Static Importso What import statements do are just they save typing and make code easier to reado static import can import classs static member, static object and static membero if import both Integer and Long class and refer to MAX_VALUE = ERRORBefore static import:System.out.println(Integer.MAX_VALU

温馨提示

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

最新文档

评论

0/150

提交评论