Java Interview third bomb

Source: Internet
Author: User
Tags assert

1 , two of computers are in the same network environment, A the computer cannot access B shared files for your computer. What are the possible causes of this phenomenon ? How to deal with it?

First decide whether you are in the same workgroup, then see if there are firewalls, and finally determine if the file is shared

2. How does a transaction work ? Write a Demo to achieve in one thing , new and updated simultaneous operations ?

BeginTrans is used to open a transaction, RollbackTrans is used to roll back a transaction, and CommitTrans is used to commit all transacted results, that is, acknowledgment transactions.

Dome

Create DATABASE AAA--Creates a DB Gouse AAA-    -Select AAA This database CREATE table BBB (    ID int not null PRIMARY key,--account    Moneys Money--Transfer amount) Use this table to create a stored procedure: CREATE PROCEDURE Mon-Creates a stored procedure, defines several variables @toid int,--the account that receives the transfer @fromid int,--turns out his account @momeys money-- Amount transferred Asbegin Tran--Start Execution Transaction update BB Set [email protected] where [email protected]-perform the first operation, transfer money, minus the amount of the transferred out update BB set [EMA Il protected] where [email protected]-perform the second operation, accept the amount of the transfer, increase if @ @error <>0--to determine if any one of the two statements appears with an error begin rollback tran– Start the rollback of the transaction, the recovery of the transfer before the start of the status of return 0endgoelse   --How to execute a successful begin commit Tran perform the operation of this transaction return 1endgo

Oracle opens a transaction by default when the statement is executed, so only rollback or commit is required.

3. The difference between a byte stream and a stream of characters

Byte stream is the most basic, the byte stream in the operation of the time itself is not used in the buffer (memory), and the file itself is directly manipulated, and the character stream is used in the operation of the buffer

The byte stream can be used for any type of object, including binary objects, and character streams can only handle characters or strings.

4. What is Java serialization and how do I implement Java serialization? Or, explain the role of the serializable interface.

Serialization is a mechanism for dealing with the flow of objects, so-called object flow is the flow of the object's contents. The object can be read and written after being fluidized.

The class that needs to be serialized is implemented with the Serializable interface, which has no method to implement, implements serializable just to annotate that the object is serializable, and then uses an output stream (such as: FileOutputStream ) to construct a ObjectOutputStream object, and then, using the WriteObject (Object obj) method of the ObjectOutputStream object, you can write out (that is, save its state) the object with the parameter obj. The input stream is used to restore the word.

  The role of the Serializable interface: labeling the object as serializable

5. Describe the principle mechanism of the JVM loading class file?

The loading of classes in the JVM (Java Virtual machine) is implemented by ClassLoader and its subclasses, and Java ClassLoader is an important Java Runtime system component. It is responsible for locating and loading classes of class files at run time.

What is the difference between 6.heap and stack.

Heap is heaps, stack is stacks

The stack space is automatically allocated and freed by the operating system, and the heap space is manually applied and released, and the heap is commonly used to allocate new keywords.

Stack space is limited, the heap space is a large free zone

What is 7.GC? Why do you have a GC?

GC is the meaning of garbage collection (Gabage Collection), memory processing is where programmers are prone to problems, forgetting or wrong memory recycling can cause program or system instability or even crashes, The GC functionality provided by Java can automatically monitor whether an object exceeds the scope to achieve the purpose of automatically reclaiming memory, and the Java language does not provide a way to release the displayed operation of the allocated memory.

8. Advantages and principles of garbage collection. and consider 2 kinds of recycling mechanisms.

Garbage collection eliminates the need for Java programmers to consider memory management when writing programs. Because of the garbage collection mechanism, objects in Java no longer have a "scope" concept.

Garbage collection can effectively prevent memory leaks, effectively using the memory that can be used

Garbage collection is usually a separate low-level thread

The recycling mechanism has generational replication garbage collection and token garbage collection, incremental garbage collection (answer these four should be enough for HR to drink a pot.) )

9. What is the basic principle of the garbage collector? Can the garbage collector reclaim memory right away? Is there any way to proactively notify a virtual machine for garbage collection?

When a programmer creates an object, the GC (garbage collector) starts to monitor the object's address, size, and usage.

GC Records and manages all objects in the heap in a graph-based manner

OK.

The programmer can manually execute System.GC () and notify the GC to run, but according to the Java language Specification there is no guarantee that the GC will perform

10. When to use Assert.

Assertion (assertion) is a common debugging method in the software development process. Many languages support this mechanism

It is a statement in the program that checks for a Boolean.

A correct program must ensure that the Boolean expression value is true, and that if the value is False, the program is already in an incorrect state. The system will give a warning or exit

The Assertion check is usually closed.

Dome

Package Com.huawei.interview;public class Asserttest {/** * @param args */public static void main (string[] args) {//TODO Auto-generated method Stubint i = 0;for (i=0;i<5;i++) {System.out.println (i);} Assume that the program is not careful more than a sentence--i;--i;assert i==5;}}

  

Is there a memory leak in 11.java, please describe it briefly.

Yes. such as: int i,i2; return (I-I2); When I is a positive number large enough, the i2 is a large enough negative number. results in overflow, resulting in errors

12. Can you write a class, also called java.lang.String?

Yes, but when applied, it needs to be loaded with its own classloader, otherwise the class loader of the system will always just load the java.lang.String in the Jre.jar package.

The principle of 13.Spring AOP.

strong> Aop ( Aspect oriented Programming ), which is aspect-oriented programming technology, AOP is based on the IOC. is a useful addition to OOP.

    AOP divides the application system into two parts, the core business logic (concerns) and the general logic of the landscape, the so-called aspect crosscutting enterprise concerns, for example, All medium-to-large applications involve persistent management (persistent), transaction management (Transaction Management), Security Management (safety), log Management (Logging), and debug Management (Debugging).

14.Spring How to implement control rollover (principle)

  Dependency injection let Spring Bean to be organized together with the alleged documents, Instead of being coupled in a hard-coded way. The completion of the program without regard to the implementation of the caller, nor the need to actively locate the   factory, this is the best way to decouple. Dependencies between instances are IoC

scope of scope

The default is a singleton mode,  that is scope= "singleton". In addition, scope also has prototype, request, session, global session scope.

 Scope= "prototype" multiple examples. When you configure the scope of the bean, its header file is as follows:

<bean id= "Role" class= "Com.web.xhaoAction" scope= "singleton"/>

16. A project loaded slowly, how spring solves the problem.

   1. Scan the annotation Bean

Write a more precise scan path,

2. delay loading your bean

<beans> plus: default-lazy-init=" true "&NBSP;

3. Remove the useless attribute

4. Project Sub-module development  

Java Interview third bomb

Related Article

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.