锘??xml version="1.0" encoding="utf-8" standalone="yes"?> The default This statement registers the class path that was used for loading the class of the object that You can register a directory name as the class search path. For example, the following code adds a directory The search path that the users can add is not only a directory but also a URL: This program adds "http://www.javassist.org:80/java/" to the class search path. This URL is used only for searching classes belonging to a package Furthermore, you can directly give a byte array to a The obtained If you do not know the fully-qualified name of the class, then you can use The users can extend the class search path. They can define a new class implementing
]]>
jdk蹇偣鍑哄惂lambdba鎶婏紝涓鐩寸敤op4j鍜宭ambdbaj榪欎簺jar鍖呭緢铔嬬柤銆傘?br />
]]>
]]>
Integer.toHexString(int i)
鍗佽繘鍒惰漿鎴愬叓榪涘埗
Integer.toOctalString(int i)
鍗佽繘鍒惰漿鎴愪簩榪涘埗
Integer.toBinaryString(int i)
鍗佸叚榪涘埗杞垚鍗佽繘鍒?nbsp;
Integer.valueOf("FFFF",16).toString()
鍏繘鍒惰漿鎴愬崄榪涘埗
Integer.valueOf("876",8).toString()
浜岃繘鍒惰漿鍗佽繘鍒?nbsp;
Integer.valueOf("0101",2).toString()
鏈変粈涔堟柟娉曞彲浠ョ洿鎺ュ皢2,8,16榪涘埗鐩存帴杞崲涓?0榪涘埗鐨勫悧?
java.lang.Integer綾?nbsp;
parseInt(String s, int radix)
浣跨敤絎簩涓弬鏁版寚瀹氱殑鍩烘暟錛屽皢瀛楃涓插弬鏁拌В鏋愪負(fù)鏈夌鍙風(fēng)殑鏁存暟銆?nbsp;
examples from jdk:
parseInt("0", 10) returns 0
parseInt("473", 10) returns 473
parseInt("-0", 10) returns 0
parseInt("-FF", 16) returns -255
parseInt("1100110", 2) returns 102
parseInt("2147483647", 10) returns 2147483647
parseInt("-2147483648", 10) returns -2147483648
parseInt("2147483648", 10) throws a NumberFormatException
parseInt("99", throws a NumberFormatException
parseInt("Kona", 10) throws a NumberFormatException
parseInt("Kona", 27) returns 411787
榪涘埗杞崲濡備綍鍐欙紙浜岋紝鍏紝鍗佸叚錛変笉鐢ㄧ畻娉?nbsp;
Integer.toBinaryString
Integer.toOctalString
Integer.toHexString
渚嬩簩
public class Test{
public static void main(String args[]){
int i=100;
String binStr=Integer.toBinaryString(i);
String otcStr=Integer.toOctalString(i);
String hexStr=Integer.toHexString(i);
System.out.println(binStr);
}
渚嬩簩
public class TestStringFormat {
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("usage: java TestStringFormat <a number>");
System.exit(0);
}
Integer factor = Integer.valueOf(args[0]);
String s;
s = String.format("%d", factor);
System.out.println(s);
s = String.format("%x", factor);
System.out.println(s);
s = String.format("%o", factor);
System.out.println(s);
}
}
鍏朵粬鏂規(guī)硶錛?nbsp;
Integer.toHexString(浣犵殑10榪涘埗鏁?;
渚嬪
String temp = Integer.toHexString(75);
杈撳嚭temp灝變負(fù) 4b
//杈撳叆涓涓?0榪涘埗鏁板瓧騫舵妸瀹冭漿鎹㈡垚16榪涘埗
import java.io.*;
public class toHex{
public static void main(String[]args){
int input;//瀛樻斁杈撳叆鏁版嵁
//鍒涘緩杈撳叆瀛楃涓茬殑瀹炰緥
BufferedReader strin=new BufferedReader(new InputStreamReader(System.in));
System.out.println("璇瘋緭鍏ヤ竴涓殑鏁存暟錛?);
String x=null;
try{
x=strin.readLine();
}catch(IOException ex){
ex.printStackTrace();
}
input=Integer.parseInt(x);
System.out.println ("浣犺緭鍏ョ殑鏁板瓧鏄細(xì)"+input);//杈撳嚭浠庨敭鐩樻帴鏀跺埌鐨勬暟瀛?nbsp;
System.out.println ("瀹冪殑16榪涘埗鏄細(xì)"+Integer.toHexString(input));//鐢╰oHexString鎶?0榪涘埗杞崲鎴?6榪涘埗
]]>
]]>Class search path
ClassPool
returned by a static method ClassPool.getDefault()
searches the same path that the underlying JVM (Java virtual machine) has. If a program is running on a web application server such as JBoss and Tomcat, the ClassPool
object may not be able to find user classes since such a web application server uses multiple class loaders as well as the system class loader. In that case, an additional class path must be registered to the ClassPool
. Suppose that pool
refers to aClassPool
object:pool.insertClassPath(new ClassClassPath(this.getClass()));
this
refers to. You can use any Class
object as an argument instead ofthis.getClass()
. The class path used for loading the class represented by that Class
object is registered./usr/local/javalib
to the search path:ClassPool pool = ClassPool.getDefault(); pool.insertClassPath("/usr/local/javalib");
ClassPool pool = ClassPool.getDefault(); ClassPath cp = new URLClassPath("www.javassist.org", 80, "/java/", "org.javassist."); pool.insertClassPath(cp);
org.javassist
. For example, to load a class org.javassist.test.Main
, its class file will be obtained from:http://www.javassist.org:80/java/org/javassist/test/Main.class
ClassPool
object and construct a CtClass
object from that array. To do this, use ByteArrayClassPath
. For example,ClassPool cp = ClassPool.getDefault(); byte[] b = a byte array; String name = class name; cp.insertClassPath(new ByteArrayClassPath(name, b)); CtClass cc = cp.get(name);
CtClass
object represents a class defined by the class file specified by b
. The ClassPool
reads a class file from the given ByteArrayClassPath
if get()
is called and the class name given to get()
is equal to one specified by name
.makeClass()
in ClassPool
:ClassPool cp = ClassPool.getDefault(); InputStream ins = an input stream for reading a class file; CtClass cc = cp.makeClass(ins);
makeClass()
returns the CtClass
object constructed from the given input stream. You can use makeClass()
for eagerly feeding class files to the ClassPool
object. This might improve performance if the search path includes a large jar file. Since a ClassPool
object reads a class file on demand, it might repeatedly search the whole jar file for every class file. makeClass()
can be used for optimizing this search. The CtClass
constructed by makeClass()
is kept in the ClassPool
object and the class file is never read again.ClassPath
interface and give an instance of that class to insertClassPath()
inClassPool
. This allows a non-standard resource to be included in the search path.
import java.io.File;
import java.lang.reflect.Field;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javassist.ClassClassPath;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
import javassist.CtNewMethod;
import javassist.bytecode.DuplicateMemberException;
import org.apache.commons.lang3.StringUtils;
public class Struts2GetterSetterGen {
private static ClassPool pool = ClassPool.getDefault();
public static void init() throws Exception {
URL url = Struts2GetterSetterGen.class.getResource("/");
List<File> resultList = new ArrayList<File>();
FileSearcher.findFiles(url.getFile(), "*Action.class", resultList);
for (File object : resultList) {
String className = StringUtils.substringBetween(object.toString(),
"classes\\", ".class").replaceAll("\\\\", ".");
CtClass ct = null;
pool.insertClassPath(new ClassClassPath(Class.forName(className))); //鍦╯ervlet瀹瑰櫒涓惎鍔?/span>
ct = pool.get(className);
Field[] fs = Class.forName(className).getDeclaredFields();
for (Field f : fs) {
genGetter(ct, f);
genSetter(ct, f);
}
ct.writeFile(url.getPath()); // 瑕嗙洊涔嬪墠鐨刢lass鏂囦歡
}
}
private static void genGetter(CtClass ct, Field field) throws Exception {
String string = "public " + field.getType().getName() + " get"
+ StringUtils.capitalize(field.getName()) + "() {return "
+ field.getName() + "; }";
CtMethod m = CtNewMethod.make(string, ct);
try {
ct.addMethod(m);
} catch (DuplicateMemberException e) {
}
}
private static void genSetter(CtClass ct, Field field) throws Exception {
String string = "public void set"
+ StringUtils.capitalize(field.getName()) + "("
+ field.getType().getName() + " " + field.getName() + "){this."
+ field.getName() + " = " + field.getName() + "; }";
CtMethod m = CtNewMethod.make(string, ct);
try {
ct.addMethod(m);
} catch (DuplicateMemberException e) {
}
}
}
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/xxx