Works System的笔试

来源:互联网 发布:量化数据分析 股票 编辑:程序博客网 时间:2024/06/02 05:23

第一次参加笔试,心情当然不一样!虽然结果在意料之中,但是学到了很多有用的东西!

Java笔试采用全英文,考的内容很基础,也有几题难度较大的编程。

有几题是这样的:

用Java编写一个关于TCP协议的Server与Cilent的程序、说说你对Struts中MVC框架的理解、

写一个Java Bean,必须包含三个members

程序题就这些;还有些选择回答之类的:

显示www.google.com 的IP,用什么命令、什么是SNMP、VPN等。

看来我自己所了解的东西还是很少,前方的路啊,还是伸手不见五指的!

解答:

ipconfig :使用它来显示计算机中网络适配器的IP地址、子网掩码和默认网关。

                    可以带参数 /all 、/batch 、/release N 、/renew N

基于TCP的网络编程:

先定义一个Server类

Server.java

import  java.io.*;

import  java.net.*;

class  Server{

        public  static  void  main(String  arg[])  throw  Exception

                          {  ServerSocket  Serv=new ServerSocket(1999);

                              System.out.println("Detect  the 1999 of  this  computer");

                              Socket  Clin;

                              Clin=Serv.accept();

                              System.out.println("One customer have connected this computer");

                              InputStream  in=Ciln.getInputStream();

                              OutputStream  out=Ciln.getOutputStream();

                              //将原始数据流封装

                              BufferedReader  br=new BufferedReader( new  InputStreamReader(in) );

                              PrintStream  ps=new  PrintStream(out);

                              String msg;

                              while(  ( msg=br.readline() )!=null ){

                                         System.out.println("Server recieved :" + msg);

                                         ps.println( msg );  //输出到客户端Clin

                                         if( msg.equals("quit") ) {  //如果客户端发送quit信息,则退出

                                                    System.out.println("Server program end");

                                                    break;

                                          }

                                }

                                in.close();

                                out.close();

                                Clin.close();

              }

 }

接着定义一个Client类 

Client.java

import java.io.*;

import java.net.*;

class Client{

            public static void main(String arg[])   throws Exception

            {  Socket Clin=new Socket("127.0.0.1",1999);

               System.out.println("Client have connected the Server ");

               InputStream in=Clin.getInputStream();

               OutputStream out=Clin.getOutputStream();  

                BufferedReader br1=new BufferedReader(new InputStreamReader(in));

                PrintStream ps=new PrintStream(out); 

                BufferedReader br2=new BufferedReader(new InputStreamReader(System.in));

                String msg;

                while((msg=br2.readLine())!=null) {

                          ps.println(msg);

                          System.out.println("Sent to Server:"+msg);

                          System.out.println("Client recieved the new:"+br1.readLine());

                          if(msg.equals("quit")){

                                    System.out.println("Client is end");

                                    in.close();

                                    out.close();

                                    Clin.close();

                                     break;

                            }

              }

        }

原创粉丝点击