Java语言进阶实验指导书文档格式.docx
- 文档编号:21105818
- 上传时间:2023-01-27
- 格式:DOCX
- 页数:10
- 大小:90.13KB
Java语言进阶实验指导书文档格式.docx
《Java语言进阶实验指导书文档格式.docx》由会员分享,可在线阅读,更多相关《Java语言进阶实验指导书文档格式.docx(10页珍藏版)》请在冰豆网上搜索。
EextendsComparable<
E>
>
Emax(E[][]list)
三、实验要求:
1、认真执行每一个步骤的,并作好记录。
2、实验报告中给出配置的详细步骤和重要的截图。
四、实验学时:
2学时
五、实验步骤:
1、编写程序练习List集合的基本使用:
1)创建一个只能容纳String对象名为names的ArrayList集合;
2)按顺序往集合中添加5个字符串对象:
“张三”、“李四”、“王五”、“马六”、“赵七”;
3)对集合进行遍历,分别打印集合中的每个元素的位置与内容;
4)首先打印集合的大小,然后删除集合中的第3个元素,并显示删除元素的内容,然后再打印目前集合中第3个元素的内容,并再次打印集合的大小。
代码如下:
packagezhoupeili;
importjava.util.*;
publicclassL1{
publicstaticvoidmain(String[]args){
Listnames=newArrayList();
names.add("
张三"
);
李四"
王五"
马六"
赵七"
for(inti=0;
i<
names.size();
i++){
System.out.println("
第"
+(i+1)+"
条数据为:
"
+names.get(i));
}
System.out.println("
集合大小为:
+names.size());
names.remove
(2);
第3条数据为:
+names.get
(2));
}
}
运行上述代码,观察并记录运行结果。
2.设计学生管理相应类,比较与上一段代码的重要区别。
实验二Multithreading多线程
1.理解多线程的原理和机制
2.掌握Java内置多线程编程接口和相关的类
_dgd﷽﷽﷽﷽﷽﷽﷽﷽﷽opasssumbyref-________________________________________________________________________________________________
1.Writeaprogramthatlaunches1000threads.Eachthreadadds1toavariablesumthatinitiallyis0.Youneedtopasssumbyreferencetoeachthread.Inordertopassitbyreference,defineanIntegerwrapperobjecttoholdsum.Runtheprogramwithandwithoutsynchronizationtoseeitseffect.
2..分析代码并解释
1.Writeaprogramthatlaunches1000threads.Eachthreadadds1toavariablesumthatinitiallyis0.Youneedtopasssumbyref-erencetoeachthread.Inordertopassitbyreference,defineanIntegerwrapperobjecttoholdsum.Runtheprogramwithandwithoutsynchroniza-tiontoseeitseffect.
2.dgd﷽﷽﷽﷽﷽﷽﷽﷽﷽opasssumbyref-_________________________________________________________________________________________________运行下列代码,记录结果,并分析死锁的原因
//Exercise29_11.java:
Demonstratedeadlock
publicclassExercise29_11{
privateObjectobject1=newObject();
privateObjectobject2=newObject();
Exercise29_11test=newExercise29_11();
publicExercise29_11(){
newThread1().start();
newThread2().start();
classThread1extendsThread{
publicvoidrun(){
synchronized(object1){
//dosomething
try{
Thread.sleep(100);
catch(InterruptedExceptionex){
System.out.println("
Attempttoacquirealockonobject2"
synchronized(object2){
classThread2extendsThread{
Attempttoacquirealockonobject1"
synchronized(object1){
实验三Networking网络编程
1.理解基于流与基于数据包的网络编程方式
2.掌握应用socket建立CS应用程序的相关类的应用
Writeaprogramthatenablestwouserstochat.Implementoneuseras
theserver(Figure30.24(a))andtheotherastheclient(Figure30.24(b)).The
serverhastwotextareas:
oneforenteringtextandtheother(noneditable)for
displayingtextreceivedfromtheclient.WhentheuserpressestheEnterkey,
thecurrentlineissenttotheclient.Theclienthastwotextareas:
oneforreceiving
textfromtheserver,andtheotherforenteringtext.Whentheuser
pressestheEnterkey,thecurrentlineissenttotheserver.Nametheclient
Exercise30_12ClientandtheserverExercise30_12Server.
给定如下客户端的代码,请完成服务器端代码的编写。
//Exercise30_12Client.java
importjava.io.*;
import.*;
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
importjavax.swing.border.*;
publicclassExercise30_12ClientextendsJFrame{
//Textareaforenteringservertext
privateJTextAreajtaServer=newJTextArea();
//Textareafordisplayingclienttext
privateJTextAreajtaClient=newJTextArea();
privatePrintWriteroutput;
newExercise30_12Client();
publicExercise30_12Client(){
//Placetextareaontheframe
setLayout(newGridLayout(2,1));
JScrollPanejScrollPane1=newJScrollPane(jtaServer);
JScrollPanejScrollPane2=newJScrollPane(jtaClient);
jScrollPane1.setBorder(newTitledBorder("
Server"
));
jScrollPane2.setBorder(newTitledBorder("
Client"
add(jScrollPane2,BorderLayout.CENTER);
add(jScrollPane1,BorderLayout.CENTER);
jtaServer.setWrapStyleWord(true);
jtaServer.setLineWrap(true);
jtaClient.setWrapStyleWord(true);
jtaClient.setLineWrap(true);
//jtaClient.setEditable(false);
setTitle("
Exercise30_12Client"
setSize(500,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
//Centertheframe
setVisible(true);
//Itisnecessarytoshowtheframehere!
//Createaserversocket
SocketconnectToServer=newSocket("
localhost"
8000);
output=new
PrintWriter(connectToServer.getOutputStream());
newSendThread(connectToServer).start();
newReceiveThread(connectToServer).start();
catch(IOExceptionex){
System.err.println(ex);
jtaServer.addKeyListener(newKeyAdapter(){
publicvoidkeyPressed(KeyEvente){
if(e.getKeyCode()==e.VK_ENTER){
output.print(jtaServer.getText());
});
classSendThreadextendsThread{
SendThread(Socketsocket){
//Keepsendingtotheclient
classReceiveThreadextendsThread{
ReceiveThread(Socketsocket){
//Keepreceivingfromtheclient
实验四MVCinGUI(GUI中的MVC模式)
1.掌握MVC设计模式的概念。
2.掌握应用MVC模式开发图形用户界面应用程序的方法。
(Creatingastudenttable)Createatableforstudentrecords.Eachrecordconsists
ofname,birthday,classstatus,in-state,andaphoto,asshowninFigure1.ThenameisoftheStringtype;
birthdayisoftheDatetype;
classstatusisoneofthefollowingfivevalues:
Freshman,Sophomore,Junior,Senior,orGraduate;
in-stateisabooleanvalueindicatingwhetherthestudentisaresidentofthestate;
andphotoisanimageicon.Usethedefaulteditorsforname,birthday,andin-state.Supplyacomboboxascustomeditorforclassstatus..
代码d_﷽﷽﷽﷽﷽﷽﷽﷽﷽报﷽一个重要信报___________________________________________________________________________________________________________Figure1.
(请给出详细代码,并加入代码注释,注释是成绩高低和判定是否抄袭的一个重要依据。
)
实验五JDBCProgramming(JDBC数据库编程)
掌握应用JDBC技术访问数据库的方法。
(AccessingandupdatingaStafftable)WriteaJavaapplicationthatviews,inserts,
andupdatesstaffinformationstoredinadatabase,asshowninFigure1.
TheViewbuttondisplaysarecordwithaspecifiedID.TheStafftableiscreated
asfollows:
createtableStaff(
idchar(9)notnull,
lastNamevarchar(15),
firstNamevarchar(15),
michar
(1),
addressvarchar(20),
cityvarchar(20),
statechar
(2),
telephonechar(10),
emailvarchar(40),
primarykey(id)
Figure1.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 语言 进阶 实验 指导书
![提示](https://static.bdocx.com/images/bang_tan.gif)