- 浏览: 73173 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (74)
- core Java (14)
- html (2)
- javascript (5)
- database (6)
- Design Patterns (4)
- spring (6)
- XML (0)
- other (1)
- application (1)
- Linux (Fedora 14) (1)
- Hibernate (6)
- tools (5)
- JBoss7 (1)
- J2EE (1)
- Concurrency (5)
- Linux (5)
- CSS (1)
- English (1)
- Python/Go/Shell (1)
- Container (1)
- Cloud (0)
- Kubernetes (1)
- Mac (1)
- Golang (1)
最新评论
-
MySSH:
但是我是用的eclipse-SDK-3.5.2的,里面没有or ...
jQuery 工具安装-jqueryWTP -
2022228:
废话,浪费资源
Runnable and Thread
Eclipse会检查serialVersionUID,其实定义private static final long serialVersionUID = 1L; 就可以。
serialVersionUID只是序列化转换时的一个判别符(判别类是否改变)。
附件为代码。
public class Address implements Serializable { private static final long serialVersionUID = 1L; String street; String country; public void setStreet(String street) { this.street = street; } public void setCountry(String country) { this.country = country; } public String getStreet() { return this.street; } public String getCountry() { return this.country; } @Override public String toString() { return new StringBuffer(" Street : ").append(this.street).append(" Country : ").append(this.country).toString(); } } public class WriteObject { public static String fileName = "f:\\address.ser"; public static void main(String args[]) { Address address = new Address(); address.setStreet("Xi Dan"); address.setCountry("China"); try { FileOutputStream fout = new FileOutputStream(fileName); ObjectOutputStream oos = new ObjectOutputStream(fout); oos.writeObject(address); oos.close(); System.out.println("Done"); } catch (Exception ex) { ex.printStackTrace(); } } } public class ReadObject { public static void main(String args[]) { Address address; try { File file = new File(WriteObject.fileName); if (!file.exists()) WriteObject.main(null); FileInputStream fin = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(fin); address = (Address) ois.readObject(); ois.close(); System.out.println(address); } catch (Exception ex) { ex.printStackTrace(); } } }
输出结果为:Street : Xi Dan Country : China
但如果修改serialVersionUID为2L, 那么就会报错,因为serialVersionUID不同。
From:http://www.mkyong.com/java-best-practices/understand-the-serialversionuid/
- serial.zip (1.3 KB)
- 下载次数: 0
发表评论
-
Security / SSL
2016-08-30 17:31 486https://www.ssllabs.com/ssltest ... -
Java Shift Operator (signedLeftShift, signedRightShift, unsignedRightShift)
2015-03-11 11:33 488Java Shift Operator ( << ... -
File.separator vs File.pathSeparator
2014-02-24 16:51 804See: http://stackoverflow.com/ ... -
InheritableThreadLocal & ThreadLocal
2014-01-07 12:11 2596InheritableThreadLocal比Thread ... -
Java Concurrency In Practice Contents
2013-12-24 17:35 0Chapter 1 - Introduction 1 1. ... -
[转] Explain Java Encapsulation & Polymorphism & Inheritance
2013-11-01 15:02 1205Encapsulation - Hiding the i ... -
Java Create Instance Method
2013-10-22 19:04 686Java Create Instance Method ... -
Object Methodes: equals and hashCode
2013-09-10 17:31 703今天看了Object的equals() and hashC ... -
StringBuffer And StringBuilder
2011-12-08 12:00 695StringBuilder是在1.5版本时出现的,是Strin ... -
Eclipse Tools
2011-10-13 22:55 5061. Eclipse New 菜单配置 Window --& ... -
笔试题笔记
2011-07-27 23:50 3381. 请说出DOM和SAX的技术异同点 DOM先要生成DOM ... -
转载:Java程序员需要注意的十项
2010-11-07 16:03 0From: 10 Commandments for Java ... -
temp
2010-05-30 01:40 0Dojo -------------------------- ... -
练习BigDecimel and Regular Expression
2010-05-18 17:11 1220程序需求:http://joezxy.iteye.com/bl ... -
fillter in web.xml
2009-09-14 18:48 0参考文献: http://javaworld.com.tw/ ... -
Java Collections
2009-09-06 11:00 0资料来源于网上。 结构图: -
Java Collections(一): Set/List/Map
2009-09-05 20:24 0Collection: public interfac ... -
JSTL 版本选择 2.4&2.3
2009-08-25 12:01 3542JSTL与Servlet版本对映 整 ... -
java note from web
2007-08-11 15:55 6531.什么是模式?什么是框架? 模式,即pattern。其实就 ... -
Runnable and Thread
2009-07-29 15:30 5625今天看了源码,总算多少理解一点,对Runnable 和 Thr ...
相关推荐
### Java面试大全:序列化、流操作、Core Java与线程安全 在Java技术领域,面试不仅是对求职者基础知识的考验,更是对其实际工作经验和技术深度的一次全面考察。本篇文章将围绕“序列化”、“流操作”、“Core Java...
- **Core Container**:包含了核心的IoC(控制反转)和DI(依赖注入)功能。 - **Data Access**:提供了与数据库的集成。 - **Web模块**:支持构建Web应用程序。 - **AOP模块**:实现了面向切面编程。 - **...
private static final long serialVersionUID = -1755418011767535342L; // ... getters and setters } ``` #### 2.2 异常处理 `NotFoundException` 类是自定义异常,用于表示找不到特定用户的情况。它可以被 ...
private static final long serialVersionUID = 1L; @Override public void init() throws ServletException { SpringFactory.init(); } } ``` 3. **SpringFactory类**:用于初始化Spring上下文。 ```...
- struts2-core-2.0.11.2.jar、struts2-spring-plugin-2.0.11.2.jar(Struts 2核心与Spring插件) - xwork-2.0.5.jar(Struts 2的核心组件之一) 3. **编写实体Bean**:为了更好地管理和操作数据库中的数据,需要...
确保项目中包含必要的Struts2库,比如struts2-core、struts2-convention-plugin等。这些库可以通过Maven或者直接下载添加到项目中。 3. **编写上传文件界面**: - 创建一个JSP页面,用于用户选择要上传的文件和...
private static final long serialVersionUID = 1L; private int userId; private String userName; private String password; // getter and setter methods } ``` - **字段说明**: - `userId`:用户ID...
private static final long serialVersionUID = 1L; @TableId(value = "user_id", type = IdType.AUTO) private Integer userId; private String userName; private String userPwd; @TableField(...
- `struts2-core-2.0.11.jar`:提供Struts2核心功能。 - `struts2-spring-plugin-2.0.11.jar`:用于实现Struts2与Spring的整合。 - `xwork-2.0.4.jar`:为Struts2提供底层支持。 - `freemarker-2.3.8.jar`:用于页面...
import javax.ws.rs.core.MediaType; @Path("/textfiles") public class TextFileResource { @POST @Consumes(MediaType.TEXT_PLAIN) public String handleTextFilePost(String textContent) { // 处理接收到...
private static final long serialVersionUID = 8275037592609082750L; private String buildID; private DataCenter dataCenter; // getter and setter @Override public int hashCode() { return super....
-libraryjars libs/Core.jar -libraryjars libs/yht.BASE64Decoder.jar -dontskipnonpubliclibraryclassmembers -dontskipnonpubliclibraryclasses -optimizations !code/simplification/arithmetic,!field/*,!...
在MyEclipse8之前,开发者需要手动引入Struts2的jar文件,包括`struts2-core`、`xwork`、`ognl`、`freemarker`、`commons-logging`以及`commons-fileupload`等依赖库。此外,还需要编写Struts2配置文件`struts.xml`...
- struts2-core-2.3.8.jar - xwork-2.3.8.jar - javassist-3.11.0.GA.jar - ... * src + com - action - IndexAction.java 其中,WEB-INF文件夹中包含了web.xml文件和lib文件夹,lib文件夹中包含了...
5. **保持序列化兼容性**:如果实体类实现了`Serializable`接口,混淆时要确保序列化ID(`serialVersionUID`)不变,以保持序列化兼容性。 6. **测试与调试**:混淆后,应进行充分的测试,确保所有功能正常。如果遇到...
private static final long serialVersionUID = 1L; public BBSServlet() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, ...