2.2 Compile the Java class............................... 5
- 格式:pdf
- 大小:282.60 KB
- 文档页数:41
【Java】class.jar和sources.jar及javadoc.jar三种jar包⼀、普及jar包知识 例如(举例⼦解释)类⽂件(.class) test-java-1.0-SNAPSHOT.jar⽂档包(API) test-java-1.0-SNAPSHOT-javadoc.jar资源包(code) test-java-1.0-SNAPSHOT-sources.jar⼆、使⽤⽅法1.类⽂件(.class) test-java-1.0-SNAPSHOT.jar 反编译,最暴⼒直接的⽅法,将jar包拖进IDEA⾥查看2.⽂档包(API) test-java-1.0-SNAPSHOT-javadoc.jar 解压该⽂件,打开index.html查看3.资源包 test-java-1.0-SNAPSHOT-sources.jar 拖进IDEA直接查看⼆、⽣成⽅法1.类⽂件(.class) test-java-1.0-SNAPSHOT.jar 直接使⽤maven打包⽣成即可2.⽂档包(API) test-java-1.0-SNAPSHOT-javadoc.jar 使⽤ maven-javadoc-plugin 插件⽣成javadoc.jar3.资源包 test-java-1.0-SNAPSHOT-sources.jar 使⽤ maven-source-plugin 插件⽣成sources.jar完整pom⽂件如下:1<?xml version="1.0" encoding="UTF-8"?>2<project xmlns="/POM/4.0.0"3 xmlns:xsi="/2001/XMLSchema-instance"4 xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd">5<modelVersion>4.0.0</modelVersion>67<groupId>com.test</groupId>8<artifactId>test-java</artifactId>9<version>1.0-SNAPSHOT</version>10<dependencies>11<dependency>12<groupId>junit</groupId>13<artifactId>junit</artifactId>14<version>4.12</version>15<scope>compile</scope>16</dependency>17</dependencies>1819<build>2021<plugins>22<plugin>23<!-- Maven 编译插件24指定maven编译的jdk版本,如果不指定,25 maven3默认⽤jdk 1.5 maven2默认⽤jdk1.3 -->26<groupId>org.apache.maven.plugins</groupId>27<artifactId>maven-compiler-plugin</artifactId>28<version>3.8.1</version>29<configuration>30<!-- ⼀般⽽⾔,target与source是保持⼀致的,但是,有时候为了让程序能在其他版本的jdk中运⾏(对于低版本⽬标jdk,源代码中不能使⽤低版本jdk中不⽀持的语法),会存在target不同于source的情况 --> 31<source>1.8</source><!-- 源代码使⽤的JDK版本 -->32<target>1.8</target><!-- 需要⽣成的⽬标class⽂件的编译版本 -->33<encoding>UTF-8</encoding><!-- 字符集编码 -->34<verbose>true</verbose>35<showWarnings>true</showWarnings>36<fork>true</fork><!-- 要使compilerVersion标签⽣效,还需要将fork设为true,⽤于明确表⽰编译版本配置的可⽤ -->37<executable><!-- path-to-javac --></executable><!-- 使⽤指定的javac命令,例如:<executable>${JAVA_1_4_HOME}/bin/javac</executable> -->38<compilerVersion>1.3</compilerVersion><!-- 指定插件将使⽤的编译器的版本 -->39<meminitial>128m</meminitial><!-- 编译器使⽤的初始内存 -->40<maxmem>512m</maxmem><!-- 编译器使⽤的最⼤内存 -->41<!-- <compilerArgument>-verbose -bootclasspath ${java.home}\lib\rt.jar</compilerArgument><!– 这个选项⽤来传递编译器⾃⾝不包含但是却⽀持的参数选项 –>-->42</configuration>43</plugin>4445<!-- ⽣成javadoc⽂档包的插件 -->46<plugin>47<groupId>org.apache.maven.plugins</groupId>48<artifactId>maven-javadoc-plugin</artifactId>49<version>3.2.0</version>50<executions>51<execution>52<id>attach-javadocs</id>53<goals>54<goal>jar</goal>55</goals>56</execution>57</executions>58</plugin>5960<!-- ⽣成sources源码包的插件 -->61<plugin>62<groupId>org.apache.maven.plugins</groupId>63<artifactId>maven-source-plugin</artifactId>64<version>3.2.1</version>65<configuration>66<attach>true</attach>67</configuration>68<executions>69<execution>70<!-- 在package阶段之后会执⾏源代码打包 -->71<phase>package</phase>72<goals>73<goal>jar-no-fork</goal>74</goals>75</execution>76</executions>77</plugin>78</plugins>79</build>8081</project>配置好插件后,使⽤maven package命令既能在target⽬录中查看到三个jar包 命令:mvn package如果要把三种jar包安装到本地仓库 命令:mvn install如果要把三种jar包发布到远程仓库 命令:mvn deploy。
maven增量编译最近由于不清楚maven(2.2.x)增量编译的机制,导致应⽤出现了⼀个当时觉得⾮常诡异的⼀个问题。
先描述⼀下问题。
背景是应⽤A有⼀个公⽤的base包,版本为1.6.6-SNAPSHOT,应⽤B依赖于这个公⽤的base包。
我在base包中修改了⼀个字符串变量的值,该变量是⼀个缓存的key(如下⾯代码的Constants类,中的CACHE_KEY)。
然后使⽤mvn deploy 命令把base包上传到中⼼库中。
出现的问题是应⽤B打包部署,应⽤上线后,使⽤后台功能删除"cache.key.new"对应的缓存值,提⽰删除成功。
但是前台展⽰的还是⽼的值(前台展⽰取的数据是从缓存取出的,简化代码后,参考下⾯的CategoryManager的showCategory()⽅法,根据key在缓存中取出值,然后前台展⽰)。
public Interface Constants{public interface Cache{String CACHE_KEY = “cache.key.new”;//旧值为"cache.key"}}public Class CategoryManager{private static Map<int, String> keyMaps = new HashMap<String, String>();static {keyMaps.put(1, Constants. Cache. CACHE_KEY);//把缓存的key存到map中.........}public Object showCategory(){return cacheManager.get(keyMaps.get(1));//在缓存中获取数据}}⼀开始怀疑是包没有成功deploy到中⼼库中,然后在中⼼库中把1.6.6-SNAPSHOT的源码包拉了下来,发现⾥⾯的代码是新的。
idea class 编译
IDEA是一款流行的Java集成开发环境,提供了丰富的功能用于编写和调试Java 程序。
在IDEA中进行class编译是开发过程中的重要步骤,通过编译可以将Java源代码转换为字节码文件,以便在Java虚拟机上运行。
本文将介绍在IDEA中进行class编译的方法和注意事项。
编译Java Class文件:
在IDEA中编译Java Class文件非常简单,只需在项目中找到需要编译的Java文件,右键点击选择“Compile Java Class”即可开始编译。
IDEA会自动检查代码并生成相应的字节码文件,如果存在语法错误会在编译过程中提示。
编译过程中的注意事项:
1. 确保项目配置正确:在进行class编译前,要确保项目的依赖和配置正确,包括Java SDK版本、编译输出路径等。
2. 检查代码质量:编译前应该检查代码的质量,避免语法错误和逻辑问题导致编译失败。
3. 处理依赖关系:如果项目有依赖其他库或模块,要确保这些依赖正确引入并配置。
总结:
IDEA提供了便捷的class编译功能,开发者可以通过简单的操作完成编译过程,同时要注意项目配置和代码质量,以确保编译成功并生成可运行的字节码文件。
在开发过程中,熟练掌握IDEA的编译功能可以提高开发效率和代码质量。
java二级考试历年真题及答案1. 以下哪个选项是Java中关键字?A. classB. publicC. intD. all of the above答案:D2. 在Java中,哪个关键字用于定义一个类?A. classB. structC. interfaceD. enum答案:A3. Java程序的执行入口是?A. main方法B. run方法C. start方法D. init方法答案:A4. 以下哪个数据类型是Java中的原始数据类型?A. StringB. intC. ArrayListD. HashMap答案:B5. 在Java中,哪个关键字用于声明一个方法?A. methodB. functionC. defD. void答案:D6. Java中用于定义一个接口的关键字是?A. interfaceB. classC. structD. abstract class答案:A7. 在Java中,哪个关键字用于声明一个抽象方法?A. abstractB. virtualC. overrideD. final答案:A8. Java中用于抛出异常的关键字是?A. throwC. exceptionD. error答案:B9. 在Java中,哪个关键字用于声明一个私有方法?A. privateB. publicC. protectedD. default答案:A10. Java中用于声明一个静态方法的关键字是?A. staticB. finalC. constD. synchronized答案:A11. 在Java中,哪个关键字用于声明一个常量?A. finalB. constC. staticD. volatile答案:A12. Java中用于创建一个对象实例的关键字是?B. createC. instanceD. clone答案:A13. 在Java中,哪个关键字用于声明一个同步方法?A. synchronizedB. threadC. mutexD. lock答案:A14. Java中用于声明一个线程安全的类,应该使用哪个关键字?A. synchronizedB. thread-safeC. volatileD. immutable答案:D15. 在Java中,哪个关键字用于声明一个单例类?A. singletonB. uniqueC. finalD. none of the above答案:D请注意,以上题目及答案仅供示例,实际的Java二级考试内容可能会有所不同。
Java基础常见英语词汇(共70个) ['ɔbdʒekt]['ɔ:rientid]导向的['prəʊɡræmɪŋ]编程OO: object-oriented ,面向对象OOP: object-oriented programming,面向对象编程[dɪ'veləpmənt][kɪt]工具箱['vɜːtjʊəl]虚拟的JDK:Java development kit, java开发工具包JVM:java virtual machine ,java虚拟机['dʒɑːvə][mə'ʃiːn]机器[kəm'paɪl]Compile:编绎Run:运行['veərɪəb(ə)l] [ɒpə'reɪʃ(ə)n] [pə'ræmɪtə]variable:变量operation:操作,运算parameter:参数['fʌŋ(k)ʃ(ə)n]function:函数member-variable:成员变量member-function:成员函数[dɪ'fɔːlt] ['ækses] ['pækɪdʒ] [ɪm'pɔːt] ['stætɪk]default:默认access:访问package:包import:导入static:静态的[vɔid] ['peər(ə)nt] [beɪs] ['sjuːpə]void:无(返回类型) parent class:父类base class:基类super class:超类[tʃaɪld] [di'raivd] [əʊvə'raɪd] [əʊvə'ləʊd] child class:子类derived class:派生类override:重写,覆盖overload:重载['faɪn(ə)l] ['ɪmplɪm(ə)nts]final:最终的,不能改变的implements:实现[rʌn'taim] [æriθ'metik][ik'sepʃən]Runtime:运行时ArithmeticException:算术异常[ə'rei]['indeks] [baundz][ik'sepʃən] [nʌl] ['pɔintə]指针ArrayIndexOutOfBoundsException:数组下标越界异常Null Pointer Exception:空引用异常ClassNotFoundException:类没有发现异常['nʌmbə]['fɔ:mæt]NumberFormatException:数字格式异常(字符串不能转化为数字)[θrəuz]Throws: (投掷)表示强制异常处理Throwable:(可抛出的)表示所有异常类的祖先类[læŋ]['læŋɡwidʒ][ju'til] [,dis'plei] [ə'rei] [list]Lang:language,语言Util:工具Display:显示ArrayList:(数组列表)表示动态数组[hæʃ][mæp]HashMap: 散列表,哈希表[swiŋ] ['æbstrækt] ['windəu] ['tu:lkit]Swing:轻巧的Awt:abstract window toolkit:抽象窗口工具包[freim] ['pænl] ['leiaut] [skrəul] ['və:tikəl] Frame:窗体Panel:面板Layout:布局Scroll:滚动Vertical:垂直['hɔri'zɔntəl] ['leibl] [tekst] ['fi:ld]Horizontal:水平Label:标签TextField:文本框['εəriə] ['bʌtən] [tʃek] [bɔks]TextArea:文本域Button:按钮Checkbox:复选框['reidiəu] ['kɔmbəu] ['lisənə]Radiobutton:单选按钮Combobox:复选框Listener:监听['bɔ:də] [fləu] [ɡrid] ['menju:] [bɑ:]Border:边界Flow:流Grid:网格MenuBar:菜单栏['menju:] ['aitəm] ['pɔpʌp]Menu:菜单MenuItem:菜单项PopupMenu:弹出菜单['daiəlɔɡ] ['mesidʒ] ['aikɔn] [nəud]Dialog:对话框Message:消息Icon:图标Node:节点['dʒa:və]['deitəbeis] [,kɔnek'tivəti]Jdbc:java database connectivity :java数据库连接[draivə] ['mænidʒə] [kə'nekʃən] ['steitmənt]DriverManager:驱动管理器Connection:连接Statement:表示执行对象[pri'peəd] [ri'zʌlt]Preparedstatement:表示预执行对象Resultset:结果集['eksikju:t] ['kwiəri]executeQuery:执行查询Jbuilder中常用英文(共33个)[kləuz] [ik'sept] [peinz]Close all except…:除了..全部关闭Panes:面板组[bi:n] ['prɔpətiz] [meik] [bild] [,ri:'bild]Bean:豆子Properties:属性Make:编绎Build:编绎Rebuild:重编绎[ri'freʃ] ['prɔdʒekt] [di'fɔ:lt]Refresh:刷新Project properties:项目属性Default project properties:默认的项目属性[di:'bʌɡ] ['prefərənsiz] [kən'fiɡə] ['laibrəriz] Debug:调试Preferences:参数配置Configure:配置Libraries:库JSP中常用英文[,ju:ni'və:səl] [ri'sɔ:s] [ləu'keiʃən]URL: Universal Resource Location:统一资源定位符['intənet] [ik'splɔ:rə] ['dʒa:və] ['sə:və] [peidʒ]IE: Internet Explorer 因特网浏览器JSP: java server page:java服务器页面['mɔdəl] [kən'trəulə] ['tɔmkæt]Model:模型C:controller:控制器Tomcat:一种jsp的web服务器['mɔdju:l] ['sə:vlet][i'niʃəlaiz] ['sta:tʌp] WebModule:web模块Servlet:小服务程序Init: initialize,初始化Startup:启动['mæpiŋ][pə'ræmitə] ['seʃən] [,æpli'keiʃən] Mapping:映射Getparameter:获取参数Session:会话Application:应用程序['kɔntekst] [,ri:di'rekt] [dis'pætʃ] ['fɔ:wəd]Context:上下文redirect:重定向dispatch:分发forward:转交['ætribju:t] ['kɔntent] [taip]setattribute:设置属性getattribute:获取属性contentType:内容类型[tʃɑ:] [in'klu:d] [tæɡ][lib]charset:字符集include:包含tag:标签taglib:标签库[ik'spreʃən] ['læŋɡwidʒ][skəup] ['empti] EL:expression language,表达式语言Scope:作用域Empty:空['stændəd][tæɡ] ['laibrəri]JSTL:java standard tag library :java标准标签库[di'skripʃən] [kɔ:]TLD:taglib description,标签库描述符Core:核心Foreach:表示循环[va:(r)] ['vεəriəbl] ['steitəs] ['aitəm]Var:variable,变量Status:状态Items:项目集合['fɔ:mæt] [filtə]Fmt:format,格式化Filter:过滤器(报错英文['strʌktʃəz]Data Structures 基本数据结构['dikʃənəriz]Dictionaries 字典[prai'ɔrəti] [kju:z]Priority Queues 堆[ɡrɑ:f] ['deɪtə] ['strʌktʃəz]Graph Data Structures 图[set] ['deɪtə]['strʌktʃəz]Set Data Structures 集合[tri:s]Kd-Trees 线段树[nju:'merikəl] ['prɔ:bləms]Numerical Problems 数值问题[sɔlviŋ] ['liniə] [i'kweiʃənz]Solving Linear Equations 线性方程组['bændwidθ] [ri'dʌkʃən]Bandwidth Reduction 带宽压缩['meitriks] [,mʌltipli'keiʃən]Matrix Multiplication 矩阵乘法[di'tə:minənt] ['pə:mənənt]Determinants and Permanents 行列式[kən'streind] [ʌnkən'streɪnd] [,ɔptimai'zeiʃən]Constrained and Unconstrained Optimization 最值问题['liniə] ['prəuɡræmiŋ]Linear Programming 线性规划['rændəm] ['nʌmbə] [,dʒenə'reiʃən]Random Number Generation 随机数生成['fæktərɪŋ] [prai'mæləti] ['testɪŋ]Factoring and Primality Testing 因子分解/质数判定['ɑːbɪtrərɪ][prɪ'sɪʒən][ə'rɪθmətɪk]Arbitrary Precision Arithmetic 高精度计算['næpsæk] ['prɒbləm]Knapsack Problem 背包问题[dɪ'skriːt] ['fʊriər][træns'fɔːm]Discrete Fourier Transform 离散Fourier变换Combinatorial Problems 组合问题Median and Selection 中位数Generating Permutations 排列生成Generating Subsets 子集生成Generating Partitions 划分生成Generating Graphs 图的生成Calendrical Calculations 日期Job Scheduling 工程安排Satisfiability 可满足性Graph Problems -- polynomial 图论-多项式算法Connected Components 连通分支Topological Sorting 拓扑排序Minimum Spanning Tree 最小生成树Shortest Path 最短路径Transitive Closure and Reduction 传递闭包Matching 匹配Eulerian Cycle / Chinese Postman Euler回路/中国邮路Edge and Vertex Connectivity 割边/割点Network Flow 网络流Drawing Graphs Nicely 图的描绘Drawing Trees 树的描绘Planarity Detection and Embedding 平面性检测和嵌入Graph Problems -- hard 图论-NP问题Clique 最大团Independent Set 独立集Vertex Cover 点覆盖Traveling Salesman Problem 旅行商问题Hamiltonian Cycle Hamilton回路Graph Partition 图的划分Vertex Coloring 点染色Edge Coloring 边染色Graph Isomorphism 同构Steiner Tree Steiner树Feedback Edge/Vertex Set 最大无环子图Computational Geometry 计算几何Convex Hull 凸包Triangulation 三角剖分V oronoi Diagrams V oronoi图Nearest Neighbor Search 最近点对查询Range Search 范围查询Point Location 位置查询Intersection Detection 碰撞测试Bin Packing 装箱问题Medial-Axis Transformation 中轴变换Polygon Partitioning 多边形分割Simplifying Polygons 多边形化简Shape Similarity 相似多边形Motion Planning 运动规划Maintaining Line Arrangements 平面分割Minkowski Sum Minkowski和Set and String Problems 集合与串的问题Set Cover 集合覆盖Set Packing 集合配置String Matching 模式匹配Approximate String Matching 模糊匹配Text Compression 压缩Cryptography 密码Finite State Machine Minimization 有穷自动机简化Longest Common Substring 最长公共子串Shortest Common Superstring 最短公共父串DP——Dynamic Programming——动态规划recursion ——递归)报错英文第一章:JDK(Java Development Kit) java开发工具包JVM(Java Virtual Machine) java虚拟机Javac 编译命令java 解释命令Javadoc 生成java文档命令classpath 类路径Version 版本static 静态的String 字符串类JIT(just-in-time) 及时处理第二章:第三章:OOP object oriented programming 面向对象编程Object 对象Class 类Class member 类成员Class method 类方法Class variable 类变量Constructor 构造方法Package 包Import package 导入包第四章:Base class 基类Super class 超类Overloaded method 重载方法Overridden method 重写方法Public 公有Private 私有Protected 保护Static 静态Abstract 抽象Interface 接口Implements interface 实现接口第五章:RuntimeExcepiton 运行时异常ArithmeticException 算术异常IllegalArgumentException 非法数据异常ArrayIndexOutOfBoundsException 数组索引越界异常NullPointerException 空指针异常ClassNotFoundException 类无法加载异常(类不能找到)NumberFormatException 字符串到float类型转换异常(数字格式异常)IOException 输入输出异常FileNotFoundException 找不到文件异常EOFException 文件结束异常InterruptedException (线程)中断异常throws 投、掷、抛print Stack Trace() 打印堆栈信息get Message()获得错误消息get Cause()获得异常原因method 方法able 能够instance 实例Byte (字节类)Character (字符类)Integer(整型类)Long (长整型类)Float(浮点型类)Double (双精度类)Boolean(布尔类)Short (短整型类)Digit (数字)Letter (字母)Lower (小写)Upper (大写)Space (空格)Identifier (标识符)Start (开始)String (字符串)length (值)equals (等于)Ignore (忽略)compare (比较)sub (提取)concat (连接)trim (整理)Buffer (缓冲器)reverse (颠倒)delete (删除)append (添加)Interrupted (中断的)第七章:toString 转换为字符串GetInstance 获得实例Util 工具,龙套Components 成分,组成Next Int 下一个整数Gaussian 高斯ArrayList 对列LinkedList 链表Hash 无用信息,杂乱信号Map 地图Vector 向量,矢量Collection 收集Shuffle 混乱,洗牌RemoveFirst 移动至开头RemoveLast 移动至最后lastElement 最后的元素Capacity 容量,生产量Contains 包含,容纳InsertElementAt 插入元素在某一位置第八章:io->in out 输入/输出File 文件isFile 是文件isDirectory 是目录getPath 获取路径getAbsolutePath 获取绝对路径lastModified 最后修改日期Unicode 统一的字符编码标准, 采用双字节对字符进行编码FileInputStream 文件输入流FileOutputStream文件输出流IOException 输入输出异常fileobject 文件对象available 可获取的BufferedReader 缓冲区读取FileReader 文本文件读取BufferedWriter 缓冲区输出FileWriter 文本文件写出flush 清空close 关闭DataInputStream 二进制文件读取DataOutputStream二进制文件写出EOF 最后encoding 编码Remote 远程release 释放第九章:JBuider Java 集成开发环境(IDE)Enterprise 企业版Developer 开发版Foundation 基础版Messages 消息格Structure 结构窗格Project 工程Files 文件Source 源代码Design 设计History 历史Doc 文档File 文件Edit 编辑Search 查找Refactor 要素View 视图Run 运行Tools 工具Window 窗口Help 帮助Vector 矢量addElement 添加内容Project Winzard 工程向导Step 步骤Title 标题Description 描述Copyright 版权Company 公司Aptech Limited Aptech有限公司author 作者Back 后退Finish 完成version 版本Debug 调试New 新建ErrorInsight 调试第十章:JFrame 窗口框架JPanel 面板JScrollPane 滚动面板title 标题Dimension 尺寸Component 组件Swing JA V A轻量级组件getContentPane 得到内容面板LayoutManager 布局管理器setVerticalScrollBarPolicy 设置垂直滚动条策略AWT(Abstract Window Toolkit)抽象窗口工具包GUI (Graphical User Interface)图形用户界面VERTICAL_SCROLLEARAS_NEEDED 当内容大大面板出现滚动条VERTICAL_SOROLLEARAS_ALWAYS 显示滚动条VERTICAL_SOROLLEARAS_NEVER 不显示滚动条JLabel 标签Icon 图标image 图象LEFT 左对齐RIGHT 右对齐JTextField 单行文本getColumns 得到列数setLayout 设置布局BorderLayout 边框布局CENTER 居中对齐JTextArea 多行文本setFont 设置字体setHorizontalAlignment 设置文本水平对齐方式setDefaultCloseOperation 设置默认的关闭操作add 增加JButton 按钮JCheckBox 复选框JRadioButton单选按钮addItem 增加列表项getItemAt 得到位置的列表项getItemCount 得到列表项个数setRolloverIcon 当鼠标经过的图标setSelectedIcon 当选择按钮的图标getSelectedItem 得到选择的列表项getSelectedIndex 得到选择的索引ActionListener 按钮监听ActionEvent 按钮事件actionPerformed 按钮单击方法(编程词汇A2A integration A2A整合abstract 抽象的abstract base class (ABC)抽象基类abstract class 抽象类abstraction 抽象、抽象物、抽象性access 存取、访问access level访问级别access function 访问函数account 账户action 动作activate 激活active 活动的actual parameter 实参adapter 适配器add-in 插件address 地址address space 地址空间address-of operator 取地址操作符ADL (argument-dependent lookup)ADO(ActiveX Data Object)ActiveX数据对象advanced 高级的aggregation 聚合、聚集algorithm 算法alias 别名align 排列、对齐allocate 分配、配置allocator分配器、配置器angle bracket 尖括号annotation 注解、评注API (Application Programming Interface) 应用(程序)编程接口app domain (application domain)应用域application 应用、应用程序application framework 应用程序框架appearance 外观append 附加architecture 架构、体系结构archive file 归档文件、存档文件argument引数(传给函式的值)。
使用Java混淆工具yguard在某些情况下,java开发者可能希望保护自己的劳动成果,防止自己编写的源代码被竞争对手或者其他组织和个人轻易获取而危害自己的利益,最简单有效的办法就是对编译后的java类文件进行混淆处理。
本文介绍一款这样的工具yguard。
yGruard是一个功能比较强大的java类文件的混淆工具,特别适合与ant工具集成使用。
本文对yguard的基本元素做一些简单的介绍,并列举了一些简单的ant任务例子,在实际工程项目中可以参考这些样例。
1. 安装2. 创建初始ant任务我们从经典的helloworld示例入手,逐步学习使用yguard混淆器工具。
2.1.编写helloword程序2.2.创建ant任务2.3.执行ant任务3. 第一个混淆任务3.1.执行混淆任务4.Obfuscate元素Obfuscate是整个混淆任务定义的元素,下面我们对它及其子元素进行详细的介绍。
4.1.Obfuscate元素在当前版本中,Obfuscate元素有如下一些属性,●mainclass:简写你的应用的主程序类名,主类的类名和它的主方法名都会被修改。
你可能想仅仅暴露主方法(main),如果你的jar文件描述文件中MANIFEST.MF包含了Main-Class属性,yguard将会自动调整成混淆后的主类名。
●logfile:混淆过程产生的日志文件名称,这个日志文件包含了混淆过程的任何警告信息和映射信息。
●conservemanifest:(取值为boolean类型-true/false),表示混淆器是否应改保持jar包的manifest清单文件不变。
缺省值为false,表示这个清单文件将会被混淆器修改用来反映新的信息摘要。
replaceClassNameStrings:(也是一个boolean属性值),设定yguard 是否需要取代某些硬编码的字符串。
(本文英文水平有限,这个属性没有理解清楚)。
JAVA集成开发环境----IntellijIDEA操作总结IDEA 全称 IntelliJ IDEA,是款优秀的 java语⾔开发的集成环境。
本⽂是对 IDEA 中常⽤配置的整理。
开始前需先准备环境,并激活。
本⽂基于:IntelliJ IDEA 2020.3.1(Ultimate Edition)注意IDEA 中没有⼯作空间 workspace 这个概念,IDEA 的设置分两类:默认配置 VS 当前项⽬配置默认配置:顶部导航栏 -> File -> New Projects Settings -> Settings for new projects / Structure for new projects当前项⽬配置:顶部导航栏 -> File -> Settings / Project Structure⼀. 项⽬结构配置File -> Project Structure)是 IDEA 中最重要的设置项,关乎到项⽬的运⾏1.1 Project Settings -> ProjectProject name:定义项⽬的名称;Project SDK:设置该项⽬使⽤的JDK,也可以在此处新添加其他版本的JDK;Project language level:这个和JDK的类似,区别在于,假如你设置了JDK1.8,却只⽤到1.6的特性,那么这⾥可以设置语⾔等级为1.6,这个是限定项⽬编译检查时最低要求的JDK特性;Project compiler output:项⽬中的默认编译输出总⽬录,实际上每个模块可以⾃⼰设置特殊的输出⽬录(Modules - (project) - Paths -Use module compile output path),所以这个设置有点鸡肋。
1.2 Project Settings -> ModulesIDEA 每个项⽬默认开⼀个窗⼝,即单⼦项⽬的形式。
Java2实用教程第六版知识点汇总1.引言本文档旨在对Ja va2实用教程第六版涉及的主要知识点进行全面的汇总和总结。
通过学习该教程,读者将能够全面掌握Ja va2编程的核心概念和技巧,为日后的J av a开发工作打下坚实的基础。
2.数据类型J a va2实用教程第六版详细介绍了Ja va中的各种数据类型及其使用方法。
以下是一些关键的知识点:2.1基本数据类型J a va的基本数据类型包括整型、浮点型、字符型和布尔型。
本教程提供了详细的介绍和示例代码,帮助读者理解这些数据类型的特点和用法。
2.2引用数据类型除了基本数据类型外,J av a还提供了多种引用数据类型,如数组、类、接口等。
教程中的例子演示了如何声明和使用这些引用数据类型,帮助读者熟悉它们的基本概念和操作。
3.控制流程控制流程是编程中的重要概念,决定了程序的执行顺序和逻辑。
J a va2实用教程第六版涵盖了常见的控制流程语句,包括条件语句和循环语句。
3.1条件语句条件语句用于根据条件的真假来选择性地执行不同的代码块。
本教程提供了i f语句、swi t ch语句等条件语句的详细说明和示例,让读者明白如何正确运用它们。
3.2循环语句循环语句用于重复执行某段代码,直到满足退出条件为止。
Ja v a2实用教程第六版介绍了三种循环语句:f or循环、w hi le循环和d o-wh il e循环。
读者将学会如何正确选择和使用不同类型的循环语句,以解决各种实际问题。
4.类与对象面向对象编程是J ava的核心思想之一。
J a va2实用教程第六版详细讲解了类与对象的概念、属性和方法的定义与使用等内容。
4.1类的定义与使用教程中提供了清晰的例子,介绍了如何定义类、声明对象、调用类的方法等操作。
读者将了解到如何通过类和对象来构建复杂的应用程序。
4.2构造方法与析构方法构造方法用于在创建对象时进行初始化操作,而析构方法则在对象销毁时执行清理工作。
本教程详细说明了构造方法和析构方法的特点和使用方法,帮助读者正确地管理对象的生命周期。
上海德邦物流股份有限公司招聘java面试真题一、选择题(20) [含多选]。
(请在正确的答案上打”√”)Question 1)Which of the following statements are true?1) An interface can only contain method and not variables2) Interfaces cannot have constructors3) A class may extend only one other class and implement only one interface4) Interfaces are the Java approach to addressing its lack of multiple inheritance, but require implementing classes to create the functionality of the Inter faces.Question 2)Which of the following statements are true?1) The garbage collection algorithm in Java is vendor implemented2) The size of primitives is platform dependent3) The default type for a numerical literal with decimal component is a float.4) You can modify the value in an Instance of the Integer class with the setValue methodQuestion 3)Which of the following are true statements?1) I/O in Java can only be performed using the Listener classes2) The RandomAccessFile class allows you to move directly to any point a file.3) The creation of a named instance of the File class creates a matching file in the underlying operating system only when the close method is called.4) The characteristics of an instance of the File class such as the directoryseparator, depend on the current underlying operating systemQuestion 4)What will happen when you attempt to compile and run the following codeclass Base{public void Base(){System.out.println(“Base”);}}public class In extends Base{public static void main(String argv[]){In i=new In();}}1) Compile time error Base is a keyword2) Compilation and no output at runtime3) Output of Base4) Runtime error Base has no valid constructorQuestion 5)You have a public class called myclass with the main method defined as follows public static void main(String parm[]){System.out.println(parm[0]);}If you attempt to compile the class and run the program as followsjava myclass helloWhat will happen?1) Compile time error, main is not correctly defined2) Run time error, main is not correctly defined3) Compilation and output of java4) Compilation and output of helloQuestion 6)Which of the following statements are NOT true?1) If a class has any abstract methods it must be declared abstract itself.2) When applied to a class, the final modifier means it cannot be sub-classed3) All methods in an abstract class must be declared as abstract4) transient and volatile are Java modifiersQuestion 7)What will happen when you attempt to compile and run the following class?class Base{Base(int i){System.out.println(“Base”);}}class Severn extends Base{public static void main(String argv[]){Severn s = new Severn();}void Severn(){System.out.println(“Severn”);}}1) Compilation and output of the string ”Severn”at runtime2) Compilation and no output at runtime3) Compile time error4) Compilation and output of the string ”Base”Question 8)Which of the following statements are true?1) Static methods cannot be overriden to be non static2) Static methods cannot be declared as private3) Private methods cannot be overloaded4) An overloaded method cannot throw exceptions not checked in the base class Question 9)Which of the following statements are true?1) The automatic garbage collection of the JVM prevents programs from ever running outof memory2) A program can suggest that garbage collection be performed but not force it3) Garbage collection is platform independent4) An object becomes eligible for garbage collection when all references denoting it are set to null.Question 10)Given the following codepublic class Sytch{int x=2000;public static void main(String argv[]){System.out.println(“Ms”+argv[1]+”Please pay $”+x);}}What will happen if you attempt to compile and run this code with the command linejava Sytch Jones Diggle1) Compilation and output of Ms Diggle Please pay $20002) Compile time error3) Compilation and output of Ms Jones Please pay $20004) Compilation but runtime errorQuestion 11)You need to read in the lines of a large text file containing tens of megabyt es of data. Which of the following would be most suitable for reading in sucha file1) new FileInputStream(“”)2) new InputStreamReader(new FileInputStream(“”))3) new BufferedReader(new InputStreamReader(new FileInputStream(“”)));4) new RandomAccessFile raf=new RandomAccessFile(“myfile.txt”,”+rw”);Question 12)Which of the following statements are true?1) Constructors cannot have a visibility modifier2) Constructors are not inherited3) Constructors can only have a primitive return type4) Constructors can be marked public and protected, but not privateQuestion 13)Which statement is true?1)An anonymous inner class may be declared as final.2)An anonymous inner class can be declared as private.3)An anonymous inner class can implement multiple interfaces .4)An anonymous inner class can access final variables in any enclosing scope.5)Construction of an instance of a static inner class requires an instance of t he enclosing outer class.Question 14)public class Foo{public static void main(String sgf[]){StringBuffer a = new StringBuffer(“A”);StringBuffer b = new StringBuffer(“B”);operate(a,b);System.out.println(a+”,”+b);}static void operate(StringBuffer x,StringBuffer y){x.append(y);y=x; }}What is the result?1)The code compiles and prints “A.B”.2)The code compiles and prints “A.A”.3)The code compiles and prints “B.B”.4)The code compiles and prints “AB.B”.5)The code compiles and prints “AB.AB”.Question 15)Which of the following thread state transitions are valid?1) From ready to running.2) From running to ready.3) From running to waiting.4) From waiting to running.5) From waiting to ready.6) From ready to waiting.Question 16)What is the result of attempting to compile and run the following program?public class Test {private int i = j;private int j = 10;public static void main(String args[]) {System.out.println((new Test()).i);}}1) Compiler error complaining about access restriction of private variables of Te st.2) Compiler error complaining about forward referencing.3) No error - The output is 0;4) No error - The output is 10;Question 17)Which two cannot directly cause a thread to stop executing?1)exiting from a synchronized block2)calling the wait method on an object3)calling the notify method on an object4)calling a read method on an InputStream object5)calling the setPriority method on a thread objectQuestion 18)Which of the following are correct, if you compile the following code?public class CloseWindow extends Frame implements WindowListener {public CloseWindow() {addWindowListener(this); // This is listener registrationsetSize(300, 300);setVisible(true); }public void windowClosing(WindowEvent e) {System.exit(0); }public static void main(String args[]) {CloseWindow CW = new CloseWindow(); } }1) Compile time error2) Run time error3) Code compiles but Frames does not listen to WindowEvents4) Compile and runs successfullyQuestion 19)Which statements describe guaranteed behavior of the garbage collection and finali zation mechanisms?1) Objects are deleted when they can no longer be accessed through any reference.2) The finalize() method will eventually be called on every object.3) The finalize() method will never be called more than once on an object.4) An object will not be garbage collected as long as it is possible for an active part of the program to access it through a reference.5) The garbage collector will use a mark and sweep algorithm.Question 20)A class design requires that a member variable should be accessible only by sam e package,which modifer word should be used?1) protected2) public3) no modifer4) private二.简答题。
Java (programming language)From Wikipedia,the free encyclopediaJava is a programming language originally developed by James Gosling at Sun Microsystems (which has since merged into Oracle Corporation)and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low—level facilities. Java applications are typically compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM)regardless of computer architecture. Java is a general-purpose,concurrent,class-based,object-oriented language that is specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere," meaning that code that runs on one platform does not need to be edited to run on another. Java is currently one of the most popular programming languages in use, particularly for client—server web applications,with a reported 10 million users.[10][11] The original and reference implementation Java compilers,virtual machines, and class libraries were developed by Sun from 1995。
Speeding up Java Programs by calling native methodsStudienarbeitInstitut für elektrische NachrichtentechnikRWTH-AachenFelix EngelMatrikelnummer:222750Betreuer:Holger CrysandtJuly21,2004Contents1Introduction42The Java Native Interface52.1Declare a Java method as native (5)2.2Compile the Java class (5)2.3Create a C-headerfile from the compiled Java Class (6)2.4Implement the functions declared in the headerfile (6)2.5Create a shared library (7)2.6Load the library into the Java class (7)3Test Procedure83.1Tests involved (8)4Analysing Test Results104.1Description of the plots (10)4.2Represantative cases (11)4.2.1Worst case order n:copy (11)4.2.2Best case order n:dot (12)4.2.3Order n2:gemv (12)4.2.4Order n3:gemm (13)5Conclusions20 References20A Test routines22B Hardware configurations242CONTENTS3Chapter1IntroductionThe popularity and widespread use of the Java Programming Language are constantly increasing. The main reasons for this development are:•Cross platform availability•Pure object Orientation•A garbage collector which autmatically frees memory that is not being referenced anymore •A wide set of tested“off the shelf“libraries for a vast number of tasks are provided by the Java Runtime Environment(JRE)and third party vendors.However,Java bytecode cannot be as performant as highly optimized C or FORTRAN code. Especially for numerical computations,hardware vendors like SUN Microsystems[1],Intel[2] and Silicon Graphics provide libraries which generally include the“Basic Linear Algebra Sub-programs“(BLAS)[3].The BLAS standardize FORTRAN subroutines and functions for basic vector and matrix operations.Java specifies an interface to call native methods written in any language from within Java classes,using the“Java Native Interface“(JNI)[4].In order to benefit from the availability of vendor supplied libraries and thereby speed up numerical computations in Java,the use of the JNI is a promising approach.In this paper,an analysis of the potential speed gain which can be achieved by calling opti-mized BLAS routines via the Java Native Interface will be done.A similar analysis has been done by Bik and Gannon[5]in1997.This paper will show, that due to the rapid developement the Java platform has experienced since then,their results are outdated by now.4Chapter2The Java Native InterfaceThe Java specification by SUN Microsystems includes the“Java Native Interface“,a C/C++API1 to•Call native methods from within Java classes•Load a Java virtual machine into a running C-Program and thereby call Java software from C-CodeIn this paper,thefirst option is used:Calling native methods from java.In this chapter the steps necessary to call native code from a Java class are described.2.1Declare a Java method as nativeBy using the keyword native a method is declared as native and its body is not implemented. public static final native void scal(int n,float alpha, float[]x,int off_x,int inc_x);2.2Compile the Java classTo compile the class,a command like the following can be used:javac de/smurflord/BlasJNI/BlasL1.javaThis command has to be called from the toplevel directory,otherwise the linker cannot properly resolve the name of the native methods.6T HE J AVA N ATIVE I NTERFACE 2SDK:S oftware D evelopement K it2.5C REATE A SHARED LIBRARY7Chapter3Test Procedure3.1Tests involvedIn order to evaluate the factors which contribute to the total execution time of JNI wrapped functions,benchmarks were run on seven BLAS routines.The tested routines were nrm2,copy, scal,axpy and dot from the Level1BLAS,gemv from the Level2BLAS and gemm from the Level3BLAS.Time measurements were done by saving the system time before and after the calls to an operation and then taking the difference.Since most architectures do not contain a high precision clock,the Level1BLAS timings were taken for800iterations,while the Level2and Level3 timings were taken for1iteration.The corresponding code samples are listed infigure A.1and A.2.For all tested functions the following execution times were taken:•A native function call to a vendor supplied library.No Java code is used here.•The operation written in pure Java•The native function from a vendor supplied library called via the JNI•A function which only copies the routines from the JVM’s heap to C memory and back (seefigure A.3).For the Level2and3BLAS(GEMV and GEMM)the following additional timings were measured:•A pure C implementation(Fig.A.4and A.5)83.1T ESTS INVOLVED9Chapter4Analysing Test Results4.1Description of the plotsFor each test the results are plotted in a diagram combining four test series for the scalar functions and six for the Level2and3BLAS(tables4.1and4.2).Since the results were the same for different members of the same architecture(for example AMD and Intel Processors)and for different operating systems on the same machine,only a few representative cases are discussed here.The complete set of results is given in the appendix.Note that the scalar functions are plotted using a logarithmic scale on both axes,whereas gemm and gemv are plotted using a linear scale on the vector size axis and a logarithmic scale on the time axis.TitleJavaAn optimized library called from CJNIThe time it takes to copy the data from4.2R EPRESANTATIVE CASES11DescriptionA naive Java implementationNative CThe native C algorithm wrapped via the JNILibraryAn optimized library called from JA V AJNI to C copythe JVM to C memory and back(if necessary)Table4.2:Test series plotted for Level2and3BLASFunction Complexityn2n2n2n3nn+n24n212A NALYSING T EST R ESULTS 1SIMD:S ingle I nstruction M ultiple D ata4.2R EPRESANTATIVE CASES1314A NALYSING T EST R ESULTSI NSTITUT FÜR N ACHRICHTENTECHNIK4.2R EPRESANTATIVE CASES1516A NALYSING T EST R ESULTSI NSTITUT FÜR N ACHRICHTENTECHNIK4.2R EPRESANTATIVE CASES1718A NALYSING T EST R ESULTSI NSTITUT FÜR N ACHRICHTENTECHNIK4.2R EPRESANTATIVE CASES19Chapter5ConclusionsThe tests have shown,that invoking native functions always imposes a overhead because the native code works on copies of the original data.These copies have to be synchronised with the original data,which is an expensive operation.Furthermore,for the straightforward operations tested,Java code has proven to be slower than native code by only a factor1.5−2.As long as the complexity of the calculation is the same as the order of copy operations that have to be done, this speed advantage is consumed by the copy operations and the best choice is to use a Java method.In the case where the complexity of the operation itself is higher than the complexity of the copy operation,a speed gain in the magnitude of approximately1.5−3can be obtained by replacing Java methods with calls to native methods.A notable speed gain in order of a magnitude could,however,only be achieved for the matrix-matrix multiplication,a calculation where the main speedup can be attributed to algorithms which provide reduced complexity.These results demonstrate the rapid improvement the Java platform has undergone since Bik and Gannon[5]did their tests in1997.The speed of the Java platform has greatly improved.The advantages provided by the Java environment,most notably the excellent portability,will be lost, if the Java Native Interface is used.Due to the comparably small speedup for most calculations, the Java Native Interface should be used with care.In most cases the better solution will be to provide efficient algorithms in Java.20Bibliography[1]Sun Performance Library,/prodtech/cc/reference/docs/index.html(06/2003)[2]Intel Math Kernel Library,/software/products/mkl,June2003[3]Blas Quick Reference GuideUniversity of Tennesse,Oak Ridge National Laboratory,Numerical Algorithms Group Ltd.,May11, 1997[4]SUN Microsystems:Java Native Interface Specification/j2se/1.3/docs/guide/jni/spec/jniTOC.doc.html,May16,1997[5]Aart J.C.Bik,Dennis B.Gannon:A Note on Native Level1BLAS in JAVA,Inidana University,Computer Science Department,1997[6]Jack J.Dongarra,Jeremy Du Croz,Sven Hammarling,Richard J.Hanson:An Extended Set of Fortran Basic Linear Algebra Subprograms,Argonne National Laboratory,Math-ematics and Computer Science Division,September1986[7]V olker Strassen:Gaussian Elimination is not Optimal,Numerische Mathematik,13(1969)354-35621Appendix ATest routineslong start=System.currentTimeMillis();for(int i=0;i<m_Schleifen;i++){scal((int)m_Vektorgroesse,alpha,vector,0,1);}long end=System.currentTimeMillis();long dauer=end-start;Figure A.1:Java source code to measure CPU time start=clock();int inc=1;for(i=0;i<Schleifen;i++){dscal_(&VektorGroesse,&alpha,Vector,&inc);}free(Vector);stop=clock();dauer=((stop-start)*1000)/CLOCKS_PER_SEC;Figure A.2:C source code to measure CPU time2223Appendix BHardware configurationsThe following hardware/software configurations were tested:•Sun Ultra10,300MHz Ultra Sparc II Processor,192MB RAM,16Kb L1Instruction Cache,16Kb L1Data Cache,512Kb L2Cache.SunOS5.7,gcc2.95.2•Intel Pentium III,450MHz Processor,386MB SDRAM,16Kb L1Instruction Cache, 16Kb L1Data Cache,512Kb L2Cache.Linux2.4.18,gcc2.95.3•AMD Duron,1.3GHz Processor,512MB DDR RAM,64Kb L1Instruction Cache64Kb L1Data Cache.Linux2.4.18,gcc2.95.4.•AMD Duron,1.3GHz Processor,512MB DDR RAM,64Kb L1Instruction Cache64Kb L1Data Cache.Windows XP Professional,gcc2.95.3,cygwin(creating a native dll).24Appendix CResults2526R ESULTSI NSTITUT FÜR N ACHRICHTENTECHNIKC.1R ESULTS FOR THE U LTRA102728R ESULTSI NSTITUT FÜR N ACHRICHTENTECHNIKC.1R ESULTS FOR THE U LTRA102930R ESULTSI NSTITUT FÜR N ACHRICHTENTECHNIKC.2R ESULTS FOR THE P ENTIUM III3132R ESULTSI NSTITUT FÜR N ACHRICHTENTECHNIKC.2R ESULTS FOR THE P ENTIUM III3334R ESULTSI NSTITUT FÜR N ACHRICHTENTECHNIKC.3R ESULTS FOR THE AMD RUNNING LINUX3536R ESULTSI NSTITUT FÜR N ACHRICHTENTECHNIKC.3R ESULTS FOR THE AMD RUNNING LINUX3738R ESULTSI NSTITUT FÜR N ACHRICHTENTECHNIKC.4R ESULTS FOR THE AMD RUNNING W INDOWS3940R ESULTSI NSTITUT FÜR N ACHRICHTENTECHNIKC.4R ESULTS FOR THE AMD RUNNING W INDOWS41。