Java interview third bullet, java interview

Source: Internet
Author: User

Java interview third bullet, java interview

1Both Computers are in the same network environment,AComputer Access failureBShared files on the computer. What are the possible causes of this phenomenon?Is it caused? What should I do?

First, determine whether the file is in the same working group, check whether there is a firewall or something like this, and finally determine whether the file has been shared.

2.How to Use transactions?Write countDemoImplement in one thing,Simultaneous addition and update operations?

BeginTrans is used to start a transaction, RollbackTrans is used to roll back the transaction, and CommitTrans is used to submit all the transaction processing results, that is, to confirm the transaction processing.

Dome:

Create database aaa -- create a database gouse aaa -- select the database aaa 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 -- create a stored procedure, define several variables @ toId int, -- the account receiving the transfer @ fromId int, -- transfer out your account @ momeys money -- transfer amount asbegin tran -- start to execute the transaction update bb set moneys = moneys-@ momeys where ID = @ fromID-the first operation to execute, transfer money, minus the transfer amount update bb set moneys = moneys + @ momeys where ID = @ toID -- perform the second operation and accept the transfer amount, add if @ error <> 0 -- determine if either of the two statements has an error begin rollback tran-start transaction rollback, status return 0 endgoelse before the recovered transfer starts -- how to execute the begin commit tran action to execute this transaction return 1 endgo

By default, oracle starts a transaction when executing the statement. Therefore, you only need to roll back or commit.

 3. Differences between byte streams and byte streams

Byte streams are the most basic. byte streams do not use the buffer (memory) during operations and are directly operated on files, while the swap stream uses the buffer during operations

A byte stream can be used for any type of objects, including binary objects. A byte stream can only process characters or strings.

4. What is java serialization and how to implement java serialization? Alternatively, explain the functions of the Serializable interface.

Serialization is a mechanism for processing object streams. Object streams are called object streams that stream object content. You can perform read and write operations on the converted objects.

The Serializable interface is implemented for the class to be serialized. There is no method to implement this interface. implements Serializable only aims to mark that the object can be serialized and then uses an output stream (such: fileOutputStream) to construct an ObjectOutputStream (Object stream) Object. Then, you can use the writeObject (Object obj) method of the ObjectOutputStream Object to write (that is, save its status) the Object whose parameter is obj ), the input stream is used for recovery.

  Serializable interface: indicates that the object can be serialized.

5. How does JVM load class files?

In JVM (Java Virtual Machine), class loading is implemented by ClassLoader and its subclass. Java ClassLoader is an important Java runtime system component. It is responsible for finding and loading classes of class files at runtime.

6. What is the difference between heap and stack.

Heap is a stack, and stack is a stack.

Stack space is automatically allocated and released by the operating system, heap space is manually applied for and released, and heap is usually allocated with the new keyword.

Stack space is limited, and heap space is very free.

7. What is GC? Why does GC exist?

GC is the meaning of garbage Collection (Gabage Collection). Memory Processing is a place where programmers are prone to problems. Forgetting or wrong memory Collection can lead to instability or even crash of programs or systems, the GC function provided by Java can automatically monitor whether the object exceeded the scope to automatically recycle the memory. the Java language does not provide a display operation to release the allocated memory.

8. Advantages and principles of garbage collection. Two recovery mechanisms are also considered.

Garbage collection removes the need for Java programmers to consider memory management when writing programs. Because of the garbage collection mechanism, objects in java will not have the concept of "Scope.

Garbage collection can effectively prevent memory leakage and effectively use available memory

Garbage collection is usually a separate low-level thread.

The recycling mechanism involves generational replication of garbage collection and marking of garbage collection, and 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 recycle memory immediately? Is there any way to proactively notify virtual machines to recycle garbage?

When a programmer creates an object, the GC (Garbage Collector) starts to monitor the address, size, and usage of the object.

GC uses Directed Graphs to record and manage all objects in heap.

Yes.

The programmer can manually execute System. gc (); Notify the GC to run, but according to the java language specification, GC will not be executed

10. When to use assert.

Assertion is a common debugging method in software development. Many languages support this mechanism.

It is a statement in the program and checks a boolean.

A correct program must ensure that the value of this boolean expression is true. 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 disabled.

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 accidentally adds an additional sentence -- I; assert I = 5 ;}}

 

  

 

11. Is there any memory leakage in java? Please briefly describe it.

Yes. For example: int I, i2; return (i-i2); // when I is a positive number large enough, i2 is a negative number large enough. The result may cause overflow and errors.

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

Yes, but you need to use your own class loader to load the application. Otherwise, the system class loader will always load the java. lang. String in the jre. jar package.

13. Principles of Spring AOP.

Aop (Aspect Oriented Programming), That is, Aspect-Oriented Programming Technology. aop is based on ioc. Is a useful supplement to oop.

    AOP divides the application system into two parts: Core business concerns and general horizontal logic, that is, Crosscutting enterprise concerns. For example, all large and medium-sized applications must involve Persistent, Transaction Management, Security, Logging, and Debugging.

14. How does Spring implement control flip (principle)

 Dependency InjectionSpring beans are organized together by the specified files, instead of being coupled together in hard coding. The implementation of the program completion does not need to care about the caller's implementation, nor does it need to actively locate the factory. This is the best decoupling method. The dependency between instances is managed by the IoC container.

15.Scope

 The default mode is Singleton,That is, scope = "singleton ". In addition, scope includes prototype, request, session, and global session scopes.

Scope = "prototype" Multi-sample. When configuring the bean scope, its header file format is as follows:

<bean id="role" class="com.web.xhaoAction" scope="singleton"/>

 

16. How does spring solve the problem when loading a project slowly.

1. Scan annotation Bean

Write a more accurate scan path,

2. Delayed loading of your bean

You can add default-lazy-init = "true" to <beans> in the configuration file"

3. Delete useless attributes

4. project module development 

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.