java杂碎问题

1. 关于类型
long最大值是9223372036854775807
long的写法是:long l = 9223372036854775806L;
http://zhidao.baidu.com/question/23167819.html

JAVA中常用数据类型转换函数
虽然都能在JAVA API中找到,整理一下做个备份。
string->byte
Byte static byte parseByte(String s)
byte->string
Byte static String toString(byte b)
char->string
Character static String to String (char c)
string->Short
Short static Short parseShort(String s)
Short->String
Short static String toString(Short s)
String->Integer
Integer static int parseInt(String s)
Integer->String
Integer static String tostring(int i)
String->Long
Long static long parseLong(String s)
Long->String
Long static String toString(Long i)
String->Float
Float static float parseFloat(String s)
Float->String
Float static String toString(float f)
String->Double
Double static double parseDouble(String s)
Double->String
Double static String toString(Double)

2.获取时间String
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String dateTimeString = sdf.format(new Date());

3.com.sun.image.codec.jpeg.JPEGCodec包找不到的问题
在Eclipse中处理图片,需要引入两个包:
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
报错:
Access restriction: The type JPEGImageEncoder is not accessible due to restriction on required library C:\Java\jre1.6.0_07\lib\rt.jar

此时解决办法:
Eclipse 默认把这些受访问限制的API设成了ERROR。只要把Windows-Preferences-Java-Complicer- Errors/Warnings里面的Deprecated and restricted API中的Forbidden references(access rules)选为Warning就可以编译通过。

4.
生成一个json对象(可以添加不同类型的数据):

JSONObject jsonObject = new JSONObject();
jsonObject.put("a", 1); jsonObject.put("b", 1.1);
jsonObject.put("c", 1L);
jsonObject.put("d", "test");
jsonObject.put("e", true);
System.out.println(jsonObject);
//{"d":"test","e":true,"b":1.1,"c":1,"a":1}

生成一个json对象(可以添加不同类型的数据):

JSONObject jsonObject = new JSONObject();
jsonObject.put("a", 1); jsonObject.put("b", 1.1);
jsonObject.put("c", 1L);
jsonObject.put("d", "test");
jsonObject.put("e", true);
System.out.println(jsonObject);
//{"d":"test","e":true,"b":1.1,"c":1,"a":1}

解析一个json对象(可以解析不同类型的数据),getJSONObject(String str):

jsonObject = getJSONObject("{d:test,e:true,b:1.1,c:1,a:1}");
System.out.println(jsonObject);
//{"d":"test","e":true,"b":1.1,"c":1,"a":1}
System.out.println(jsonObject.getInt("a"));
System.out.println(jsonObject.getDouble("b"));
System.out.println(jsonObject.getLong("c"));
System.out.println(jsonObject.getString("d"));
System.out.println(jsonObject.getBoolean("e"));

http://yelang2009.iteye.com/blog/400052
http://akalius.iteye.com/blog/201929
http://kb.cnblogs.com/a/1429304/

5. JTextArea不要滚动条
应将JTextArea置于JScrollPanel中
若要使只有垂直滚动条而没有水平滚动条,使用JTextArea.setLineWrap(true),自动换行。
http://dongdong1314.blog.51cto.com/389953/79599
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值