Java a bit of a pen question "2016-04-13"

Source: Internet
Author: User

The first part, Java Test Questions

1 , Enumeration Java the eight basic data types ( 8 ).

Int, short, long, float, char, Byte, double, Boolean

2 , create a class, declare properties, and define methods according to the following description, creating an instance object of the class, calling the method ( the ).

Set up a car vehicle class, including the number of tires tirenum, car colors color, body weight weight, speed and other member variables. and create an instance from different construction methods. Minimum requirements: The car can speed up the speedup, slow down the slowdown, stop.

public class vehicle{

private int tirenum;

Private String Color;

Private double Weight;

private int speed;

Public vehicle{

Tirenum = 4;

Weight = 1000.00;

}

Public Vehicle (int tirenum, String Color, double Weight, int. speed) {

This. Tirenum= Tirenum;

This. Color=color;

This. Weight=weight;

This.speed=speed;

}

public int speedup{

return 1;

}

public int slowdown{

return 1;

}

public int stop{

return 1;

}

public static void Main (string[] args) {

Vehicle v = new Vehicle ();

V.speedup ();

V.shutdown ();

V.stop ();

}

}

3 , define the interface, class, and implementation method according to the following description, create an instance object of the class, invoke the method ( - ).

Create an interface called vehicle, and add two methods with one parameter start () and stop () to the interface. Implement the vehicle interface in two classes named bike and bus. Create a class named Test, create the bike and bus objects in the test's main () method, and access the start () and Stop () methods.

public interface Vehicle () {

public void start (int startnum);

public void Stop (int stopnum);

}

public class Bike Implement Vehicle () {

public void start (int startnum) {

System.out.println ("Startnumbike:" +startnum);

}

public void Stop (int stopnum) {

System.out.println ("Stopnumbike:" + stopnum);

}

public static void Main (string[] args) {

}

}

public class Bus Implement Vehicle () {

public void start (int startnum) {

System.out.println ("Startnumbus:" +startnum);

}

public void Stop (int stopnum) {

System.out.println ("Stopnumbus:" + stopnum);

}

public static void Main (string[] args) {

}

}

public class test{

public static void Main (string[] args) {

Bike Bike = new Bike ();

Bus bus = new bus ();

Bike.start ();

Bike.stop ();

Bus.start ();

Bus.stop ();

}

}

4 , according to the following description, programming to achieve the content of the file read and write ( - ).

Store the file under the D:\test folder and use IO stream to copy the file to the D-packing directory.

Import Java.io.FileInputStream;

public class iofile{

public static void Main (string[] args) {

try{

Filrwrite FW = new FileWriter ("D:/test/client.java");

Fw.flush ();

Fw.close ();

FileInputStream fis = new FileInputStream ("D:/test/client.java");

FileOutputStream fis = new FileOutputStream ("D:/client.java" ");

Byte[] B = new byte[1024];

while ( -1!=fis.read (b))

{

Fos.write (b);

}

Fos.flush ();

Fos.close ();

Fis.close ();

}

catch (Ioception e) {

E.printstacktrace ();

}

}

}

5 , complete the string String Common Operations ( 7 ).

Write a method to check if the input string is a palindrome (data symmetry)?

public class Stringreversedemo {

public static void Main (string[] a) {

string s = "a man,a plan,a canal, Panama";//String given

SYSTEM.OUT.PRINTLN (S + "is palindromes?" + (Ispalindromes (s) = = true? "True": "false"));

}

Judging if it's a palindrome.

public static Boolean ispalindromes (String s) {

boolean bool = false;

String S1 = S.tolowercase (). ReplaceAll ("[\\W\\s]", "");

Char[] C = S1.tochararray ();

StringBuffer sb = new StringBuffer ();

for (int i = c.length-1; I >= 0; i--) {

Sb.append (C[i]);

}

String s2 = sb.tostring ();

if (s1.equals (S2)) {

BOOL = true;

}

return bool;

}s

}

6 , brief description Set and the List difference, ArrayList and the LinkedList the difference, HashMap and the HashTable The difference ( Ten ).

Both the set and list inherit from the collection interface

Set inner elements are not sequential, list inner elements are ordered

ArrayList is sequential storage, and LinkedList is chained storage.

Hashtable synchronous, and HashMap is not synchronous, the efficiency is higher than Hashtable.
HashMap allows null key values, while Hashtable does not allow

Part II, MySQL Test Questions

7 , according to the following requirements, complete the operation ( - ).

Database design:

Employee Information Sheet:

Table name

Empinfo

Chinese table name

Employee information

Serial number

Field name

Field description

Type

Number of digits

Note

1

EmpID

Employee number

Int

4

Primary key

2

EmpName

Employee Name

varchar

10

3

Empbirth

Date of birth

Datetime

4

DeptID

Department number

Int

4

FOREIGN key

5

Empsex

Gender

Int

1

1: Male, 0: female, Default: 1

6

Empevaluate

Evaluation of tenure

varchar

Default: ' Good performance '

Department Table:

Table name

Deptinfo

Chinese table name

Department Name

Serial number

Field name

Field description

Type

Number of digits

Note

1

DeptID

Department number

Int

4

Primary key

2

Deptname

Department Name

varchar

50

The operating instructions are as follows:

    • Create a data base employee
    • Create Data tables (table structure as above, note primary foreign key relationships and default values)
    • Write SQL words to achieve the following functions

L Write SQL statements to add at least three statements to each table

• Number of female enquiries

L Query All information (employee label, employee name, department number, department name, date of birth, gender)

L Query the oldest employee information (name, age, department number, department name, cognitive evaluation)

L Statistics of personnel information (name, date of birth, gender)

1, create database employee;

2. CREATE TABLE empinfo{

empId Int (4) Primary key;

EmpName varchar (10);

Empbirth datetime;

DeptID Int (4) Reference Deptinfo (Dddeptid) foreign key;

Empsex Int (1) enum (1,0) default 1;

Empevaluate varchar Default ' performance is good ';

}

Create table Deptinfo {

DeptID Int (4) primary key;

Deptname varchar (50);

}

3. Insert into Empinfo values (1, ' name1 ', to_date (' 1990-10-10 ', ' yyyy-mm-ddhh24:mi:ss '), 11, 1, ' can ');

Insert into Empinfo values (2, ' name2 ', to_date (' 1991-10-10 ', ' yyyy-mm-ddhh24:mi:ss '), 12, 0,);

Insert into Empinfo values (3, ' Name3 ', to_date (' 1920-10-10 ', ' yyyy-mm-ddhh24:mi:ss '), 13, 1,);

Insert into deptinfo values (one, ' Tiyu ');

Insert into Deptinfo values ("Yingyu");

Insert into deptinfo values (13s, ' Shuxue);

4. Select A.empid,a.empname,a.empbirth,a.deptid,a.empsex,b.deptname

From Empinfo a joins Deptinfo B on A.deptid=b.deptid;

5. Select a. Empname,sysdate ()-a.empbirthas age, A.deptid,a.empevaluate

From Empinfo A

Where RowNum < 2

Order by Empbirth

6. Select Empname,empbirth,empsex

From Empinfo

Where empbirth>=to_date (' 1900-01-01 ', ' yyyy-mm-ddhh24:mi:ss ')

Java a bit of a pen question "2016-04-13"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.