java written interview (a)

jvm: java virtual machine
jre: java runtime environment
jvm + load to the base class library jvm in
jdk: java development tools
jre + necessary development tools

Environment variables:
1. the JAVA_HOME: jdk facilitate the switch version D: \ Java \ jdk1.8.0_131
2.path: .exe file path in the path can be performed in any environment% JAVA_HOME% \ bin in the system
3.classpath: classpath path All .class files will be loaded into the jvm (java virtual machine)% JAVA_HOME% \ jre \ lib

Program sequence:
1. edit the code
Compile the java code -> class (the javac cs1902.java).
3. Load the .class file into the jvm (a class to be loaded into the jvm be used)
4. Run run java code (java cs1902)

Identifier naming convention:
Class name: the word begins with capital letters, more than one word is the first letter of each word capitalized, large hump
method names, variable names, parameter names: lowercase first letter, more than one word then the second start uppercase first letter of each word, small hump

Reserved words: goto, const

Basic data types: four eight kinds
Integer class: byte 8 -128 ~ 127 (default 0)
Short 16 (default 0)
int 32 (default 0)
Long 64 (default 0)
floating point: double 64 (default 0.0)
long 32 (default 0.0)
character: char 16 (space by default)
Boolean: boolean (default false)

Data type conversion: Automatic (Small -> Large)
force (Large -> small) may result in reduced accuracy or data overflow

Variables must first be assigned to use

The difference between local and global variables are:
1. Declare a different location
2. Global variables have default values, local variables no default

There will be a logical and (&&) and logical OR (||) short circuit in the
logical AND (&&): expression 1 && expression 2 1 if the expression is false does not validate the expression 2 short circuit occurs
logic or ( ||): expression expression 1 || 1 2 If the expression is true will not validate the expression two short circuit occurs

Distinguish the difference between a ++ and ++ a a, a-- and --a of

Bitwise operators: a bitwise left shift operator i.e. a << 1 A 2 (A 1 multiplied by a power of 2) a << 3 i.e. A 2 2 2 (A multiplied by the cube of 2)

Classic face questions: 2 calculates the most efficient method of multiplying equal to a few 8
2 << 3 (i.e. 2 multiplied by the cube of 2)

swtich (key): value of the key can be a byte short int char enum (jdk after 1.7 can be String), you can not use boolean long float double

case penetrate: a case statement is missing from the break, then break to appear until the end

Cycle steps:

  1. Initializes loop variable
    2. Analyzing the loop variable
    3. Perform loop logic
    4. Modification loop variable

and while the difference between the do-while:
the case where the first condition is not satisfied, the loop can not be performed while loop, can execute a do-while

break out of the entire cycle
continue the end of the cycle
of the overall process ends return

The method of action: improve code readability, improved code maintainability

Overloaded methods: 1 in the same class
the same method name 2.
3. A list of the different parameters (parameter type, the number, order (sequence type))

Recursion: Features: method calls itself
Note: to find the exit program

Recursive classic T questions:
1. output triangle
2. Feibolaqi Sequence

  1. 2 + 22 + 222 + 2222 +. . . .
    4. one hundred yuan one hundred chicken

Problems encountered using an array
1. bounds array subscript
int [] = A new new int [. 4] A [. 6]. 1 =
2. assigned address assignment or pass by value or address
int [] a = {1,2,3 } If the address in a stack array is 1111 @
int [] a b = b in the array address stack @ 1111 is
assigned is the address of the array regardless of any array b is a change of an array to another will change
3. null pointer exception
data type other than the basic data types are called reference data types
reference to the default value of the data type is null (null object)
if you call the null object's methods or properties throws null pointer exception

Array pass by value or address
int [] a = {1,2,3,4,5};
int [] b = a;
array of arrays a and b the same address
changed to another will change the value of an array

Basic data type is a value assigned assignment
reference data type is an address assignment assigned
exist in the value of the basic data type of the stack
within the reference value of the data type of a heap

== and equals the difference
if the basic data types used for equality comparison ==
if == comparison with reference data types are equal with the address equals the comparison value is equal

Bubble sort
a binary search

How to optimize virtual machine
1. expand the memory
2. Garbage collection
3.oom - Out of Memory

What is object-oriented? Object-oriented and process-oriented is the difference between what
an object-oriented way of thinking is a
difference: the object-oriented things is entrusted to someone else to do
process-oriented is hands

The difference between the conventional method and the method of construction
1. constructor does not return type
2. constructor method name and the name of the same class
public Person () {}

the role of this key and use
the current object of this class representatives in your references (address value), that object reference own
this. member variable name
this. member method name

Procedure for overloading and rewrite
overloaded: occur in the same class in the same method name parameter list of the different
rewrite: Method occur in succession neutron class inherits the parent class may not fit the needs of a subclass of subclasses override the parent methods of the class

Access: public protected default private (pen questions often arise)
authority in this class with the package class or different buns class with buns classes in different packages
public ✔ ✔ ✔ ✔
protected ✔ ✔ ✔ ✘
default ✔ ✔ ✘ ✘
Private ✔ ✘ ✘ ✘

Whether static variables and methods can be inherited?
Not inherited but can be used by subclasses
static properties and methods are common to attribute this kind of thing has

We can not create a class to inherit String class because the String class is modified by the final

Two String how to compare the size?
With a CompareTo (b)
because the String class implements Comparable interface

Singleton

Singleton pattern starving formula-fed and formula What is the difference
1. The object initialization time different
starving formula: The object has been created and has been occupied memory in a class is loaded into the jvm method area when
well-fed formula: first when used only once to generate the object (less memory consumption)
object class 2. singleton, in general, are accessed concurrently biggest target
thread
high concurrent time use, thread-safe

Factory Pattern

Comparator: Comparable and Compatator difference
Comparable interface: the object is to have the ability to compare itself
Comparator interface: an external comparator

After the 1.8 JDK biggest change is that?
lambda expressions (JDK 1.8 only)

Five common abnormal
1. null pointer exception
2. array subscript bounds exception
exception does not comply with the mathematical principles 3.
exception does not match the input type 4.
5. The exception type transition

Object: In java.lang package

Object methods

Object's equals and hashCode methods

java :( create an object in two ways)
new new ****
objects .Clone

new out of the objects and distinguish clone out:
Performance

Deep and shallow clone clone on
a deep clone step
shallow clone step

final, finally, finalize the difference
does not matter just looks like the
final: Constant finally: abnormal use finalize: Last call this method before garbage collection

The location specified in the string string appears all find out (recursive)

Existing following string: zoukx is a good man;
the first letter of each word capitalized Zoukx Is A Good Man;

The difference between String, StringBuffer and StringBuilder of

  1. String value of the constant pool
    when the stitching is actually open up new space and then assign
    it unsuitable for use in cycle stitching (memory usage too)
    2.StringBuffer and StringBuilder
    professional to do the string concatenation cycle, mosaic when, in fact, is behind the original object additional
    3.StringBuffer thread-safe
    high efficiency StringBuilder thread-safe

Guess you like

Origin www.cnblogs.com/shumengjiao/p/11331578.html