Java (4), java (2)

Source: Internet
Author: User

Java (4), java (2)

  • Can abstract methods be both static, native, and synchronized?

Abstract methods cannot be static, because abstract methods must be implemented by the quilt class, but static and subclass cannot be connected!

Abstract methods cannot be native. native methods indicate that the method must be implemented in another platform-dependent programming language. Therefore, it cannot be abstract or mixed with abstract. For example, the FileOutputSteam class needs hardware, and the underlying implementation uses the api implementation related to the operating system. For example, if the C language is used in windows, view the jdk source code, we can see that the open method of FileOutputStream is defined as follows:

private native void open(String name) throws FileNotFoundException;

If we use java to call C language functions written by others, we cannot directly call them. We need to write a C language function according to java's requirements, in addition, we use this C language function to call other C language functions. Since our C language functions are written according to java requirements, we can connect this C language function with java, the connection method of java is to define the method corresponding to our c function. The corresponding method in java does not need to write specific code, but the native should be declared before.
Abstract methods cannot be synchronized. I have never seen this situation during my years of study and development. In addition, I think synchronized should be used in a specific method to make sense. In addition, synchronized synchronization on the method uses the synchronization Lock Object this, while the abstract method cannot determine what this is.

  • Super. getClass () method call

What is the output result of the following program?

import java.util.Date;  public  class Test extends Date{      public static void main(String[] args) {          new Test().test();      }           public void test(){          System.out.println(super.getClass().getName());      }  }

In the test method, call the getClass (). getName () method directly and return the Test class name.

Because getClass () is defined as final in the Object class, the subclass cannot overwrite this method. Therefore, call getClass () in the test method (). the getName () method is actually calling the getClass () method inherited from the parent class, which is equivalent to calling super. getClass (). getName () method, so, super. getClass (). the getName () method also returns Test.
If you want to get the name of the parent class, use the following code: getClass (). getSuperClass (). getName ();

  • There is a return statement in try {}, so will the code in finally {} following this try be executed? When will it be executed, before or after return?

Maybe your answer is before return, but to be more detailed, my answer is to execute in the middle of return. Please refer to the running result of the following program code:

public  class Test {  public static void main(String[] args) {        System.out.println(new Test().test());;  }    static int test()  {          int x = 1;      try{          return x;      }      finally{          ++x;      }  }     }

The running result is 1. Why? The process in which the main function calls the subfunction and obtains the result is like preparing an empty jar for the primary function. When the subfunction returns the result, it first places the result in the jar, then return the program logic to the main function. The so-called return is the sub-function. If I don't run it, you can continue to run the main function. There is no result. The result is put into the jar before you say this.

  • What is the difference between error and exception?

Error indicates that recovery is not a serious problem that is impossible but difficult. For example, memory overflow. It is impossible to expect the program to handle such a situation. In other words, when an error occurs, the running program is terminated and the virtual machine exits. There is no way (try-catch) to bring the program back to the normal track. For example, the following code:

ublic class Outer{      public static void main(String[] args){          try{              int[] i=new int[1000000000];          }catch(Exception e){              System.out.println("aaa");          }      }  }

Running result:

Exception in thread "main" java.lang.OutOfMemoryError : Java heap space    at hr.test.Outer.main(Outer.java:7)

Exception indicates a design or implementation problem. That is to say, it indicates that if the program runs normally, it will never happen. However, if an exception occurs during running (such as ArrayIndexOutOfBoundsException) or an exception (such as FileNoFindException) needs to be checked, you can use try-catch to continue running the program.

Note: The only difference between an exception during running and an exception needing to be checked is that the former does not need to sign the method and then declares the exception type, while the latter must declare the exception. Both error and exception inherit Throwable, so they can be thrown.

Exceptions are exceptions or errors that occur when java programs are running (not compiled). They are similar to events in real life, events in real life can contain information such as the time, location, character, and plot of an event. They can be represented by an object. Java uses an object-oriented method to handle exceptions, it encapsulates every exception in the program into an object, which contains the exception information.
Java classifies exceptions. Different types of exceptions are represented by different Java classes. The root classes of all exceptions are java. lang. throwable and Throwable are derived from two subclasses: Error and Exception. Error indicates a serious problem that the application itself cannot overcome and restore. The program only has dead parts. Exception indicates that the program can also overcome and recover the problems, including system exceptions and Common exceptions. system exceptions are caused by Software defects, that is to say, software developers cannot overcome and restore the problems caused by weeks of consideration. However, in this case, the software system can continue to run or let the software die. For example, array script out of bounds (ArrayIndexOutOfBoundsException), null pointer exception (NullPointerException), Class conversion exception (ClassCastException); normal exceptions are caused by changes in the runtime environment or exceptions, it is a problem that users can overcome, such as network disconnection and insufficient hard disk space. After such an exception occurs, the program should not die.
I am the dividing line of tiantiao

 

 

Reference: http://hxraid.iteye.com/blog/749507


What are the written questions of Java development engineers?

Interview Questions of Qingtian Technology

1. Nine built-in JSP objects and their functions.
2. Differences between EJB and JavaBean.
3. For an SQL question, find the repeated elements in the table and then delete it.
Jiangsu rongdian financial payment system Co., Ltd. Interview Questions
1. Differences between abstract classes and interfaces;
2. Differences between Vector and Arraylis;
3. Collector and Conllecton?
4. How can I keep the stateless Http protocol unchanged?
5. Write the base number of-in JAVA;
6. JSP knowledge;
7. Knowledge of EJB;
8. Framework knowledge;

Suyuan high-level questions

J2EE development (4 optional)
Question 1: What is MVC? Why use MVC? Under what circumstances can the MVC mode be used?
Question 2: What is the corresponding MVC in the struts architecture?
Question 3: What are the advantages and disadvantages of J2EE development compared with traditional development?
Question 4: How to maintain the integrity of database transactions? Give a java example (only the core code is needed)
Question 5: Why use the connection pool and thread pool?
Question 6: What development tools do you like to use? Why?

Several other SQL statements
Finally, we made a small project, which is similar to our shopping cart, mainly to test the addition, deletion, modification, and query of databases.

This is the table structure.
SQL is the tables.

The previous steps are relatively simple, that is, to create a small project at last, without limited time

The manager asked me a question 2nd times.
It was written during the written test.
The last step is to look at your skills in writing code. Generally, it won't run your program.
The last small project is a WEB program. Some open-source projects can be used to add points.
It is mainly about database operations.
Remember to use transactions

Su Yuan Gao Ke (latest) Interview Questions

Development requirements:
You can add, delete, modify, and query a table on a webpage. The operation table is CKDEFINE.

Development Environment:
The database is DB2
Development Tools Eclipse + MyEclipse
Application Server: JBOSS4.0

Database connection code segment:
Private statio string databaseserver Ip = "172.24.133.43 ";
// Database server Ip Address
Private statio string port = "50000"; // database server port
Private statio string SID = "YDDBTMP"; // database SID
Private statio string user = "testdb2"; // db login username
Private statio string password = "db login password"

// Connect the function body
Public connection getconnect () throws Exception {
Connection conn = nu11;
Try {
Class. forName ("com. ibm. db2.jcc. DB2Diver"). newInstance ();
String url = "jdbc: db2: // + databaseserver IP +": + port + "/" SID;
Conn = DriverManager. getConnection (ur1, user, psssword );
} Catch (classNotFoundException e ){
System. out. println ("connect error !");
}
Return conn;
}

Jar package bit connecting to the DB2 database... the remaining full text>

How to pass the java Test

1. Contact Basics
2. Find an interview book
3. Write questions online ..
Good luck with you...

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.