当前位置:网站首页>Basic grammar of interview (Part 1)
Basic grammar of interview (Part 1)
2022-07-05 21:53:00 【J.King】
The difference between character type constant and string constant ?
- form : A character constant is a character caused by a single quotation mark , String constants are caused by double quotation marks 0 One or more characters
- meaning : A character constant is equivalent to an integer value ( ASCII value ), Can participate in expression operation ; A string constant represents an address value ( The string is stored in memory )
- Memory size : Character constants only take up 2 Bytes ; String constant takes several bytes ( Be careful :
charstay Java Two bytes in )
Have you ever used variable length parameters ?
from Java5 Start ,Java Start defining variable length parameters , It allows parameters of variable length to be passed in when calling methods . For example, the following method is acceptable 0 One or more parameters :
public static void method1(String ...args) {
//TODO
}
in addition , The variable length parameter can only be used as the last parameter in the formal parameter list .
public static void method2(String arg1, String ...args) {
//TODO
}
What to do in case of method overloading ? Will priority be given to matching methods with fixed parameters or variable parameters ?
It is a method that will preferentially match fixed parameters , Because the method with fixed parameters has a higher matching degree . in addition ,Java After compiling, the variable parameters of will actually be converted into an array .
What are the notes ? The more comments, the better ?
- Single-line comments
- Multiline comment
- Documentation Comments
When we write code , If there is less code , We or other members of the team can easily understand the code , But when the project structure gets complicated , We need to use annotations . Annotations don't execute ( The compiler erases all comments in the code before compiling it , Comments are not preserved in bytecode ), It's written to us by programmers , Comments are your code specifications , Can help people who read the code to quickly understand the logical relationship between the code . therefore , It's a good habit to add comments when writing programs .
《Clean Code》 The book makes it clear that :
Code comments are not as detailed as possible . In fact, good code itself is a comment , We should try our best to standardize and beautify our code to reduce unnecessary comments .
If the programming language is expressive enough , There's no need to comment , Try to explain it in code .
for instance :
Remove the complex comments below , Just create a function of the same thing as the annotation says
// check to see if the employee is eligible for full benefits
if ((employee.flags & HOURLY_FLAG) && (employee.age > 65))
Should be replaced by
if (employee.isEligibleForFullBenefits())
What's the difference between an identifier and a keyword ?
An identifier is what we write a program for 、 class 、 Variable 、 Method, etc . But there are some identifiers , Has been Java Given a special meaning , It can only be used in special places , This special identifier is a keyword . So it can also be said that , Keywords are special identifiers .
Java What are the common keywords in ?
| classification | keyword | ||||||
|---|---|---|---|---|---|---|---|
| Access control | private | protected | public | ||||
| class , Method and variable modifiers | abstract | class | extends | final | implements | interface | native |
| new | static | strictfp | synchronized | transient | volatile | ||
| Program control | break | continue | return | do | while | if | else |
| for | instanceof | switch | case | default | |||
| Error handling | try | catch | throw | throws | finally | ||
| Package related | import | package | |||||
| Basic types | boolean | byte | char | double | float | int | long |
| short | null | true | false | ||||
| Variable references | super | this | void | ||||
| Reserved words | goto | const |
Access control
Java Language provides a lot of modifiers , It is mainly divided into the following two categories :
- Access modifier
- Non access modifier
Among them, non access modifiers mainly include :static、final、abstract、synchronized and volatile, Non access modifiers ensure the implementation of specific functions according to their respective characteristics .
Java Use access control characters to Protect against class 、 Variable 、 Access to methods and constructors , The size of the permission control corresponding to the access control modifier is :public > protected > default( Package access ) > private.
public : Visible to all classes
Use object : class 、 Interface 、 Variable 、 Method
protected : Visible to classes and all subclasses in the same package
Use object : Variable 、 Method . Be careful : Can't modify class ( External class )
- Subclasses and base classes are in the same package : Be declared protected The variable of 、 Methods and constructors can be Same package Any other class in the ;
- Subclasses and base classes are not in the same package : In a subclass , Subclass instances can access what they inherit from the base class protected Method , and Cannot access base class instance protected Method
default ( Default , Write nothing ): Visible in the same package , Don't use any modifiers
Use object : class 、 Interface 、 Variable 、 Method .
private : Visible in this class
Use object : Variable 、 Method . Be careful : Can't modify class ( External class )
Auto increment and auto decrement operator
++ and – Operators can be placed before variables , It can also be placed after a variable ; When the operator is placed before the variable ( Prefix ), First of all, increase by yourself / reduce , To assign a value ; When an operator is placed after a variable ( suffix ), Assign first , Since the increase again / reduce . for example , When b = ++a when , First of all, increase by yourself ( Add yourself 1), To assign a value ( Assign a value to b); When b = a++ when , Assign first ( Assign a value to b), Since the increase again ( Add yourself 1). That is to say ,++a The output is a+1 Value ,a++ The output is a value . A pithy formula is :“ The symbol is preceded by / reduce , The symbol is followed by / reduce ”
continue、break、return The difference between
continue: End this cycle , Go straight to the next cycle
break: End the whole loop process in the loop body class
return: Used to jump out of the way , End the operation of the method
边栏推荐
- Robot framework setting variables
- Experienced inductance manufacturers tell you what makes the inductance noisy. Inductance noise is a common inductance fault. If the used inductance makes noise, you don't have to worry. You just need
- 让开发效率提升的跨端方案
- 2.2 basic grammar of R language
- 1.2 download and installation of the help software rstudio
- K210学习笔记(四) K210同时运行多个模型
- 854. String BFS with similarity K
- oracle 控制文件的多路复用
- HYSBZ 2243 染色 (树链拆分)
- Sorting out the problems encountered in MySQL built by pycharm connecting virtual machines
猜你喜欢

从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析

Teach yourself to train pytorch model to Caffe (I)

华为联机对战如何提升玩家匹配成功几率

Shell script, awk uses if, for process control

Uni app Bluetooth communication

Analysis and test of ModbusRTU communication protocol

Matlab | app designer · I used Matlab to make a real-time editor of latex formula

JMeter installation under win7

使用Aspect制作全局异常处理类

Making global exception handling classes with aspect
随机推荐
多家呼吸机巨头产品近期被一级召回 呼吸机市场仍在增量竞争
Four components of logger
Oracle检查点队列–实例崩溃恢复原理剖析
Exercise 1 simple training of R language drawing
Objects in the list, sorted by a field
HDU 4391 Paint The Wall 段树(水
crm创建基于fetch自己的自定义报告
one hundred and twenty-three thousand four hundred and fifty-six
HDU 4391 paint the wall segment tree (water
总结出现2xx、3xx、4xx、5xx状态码的原因
Poj3414广泛搜索
How to organize an actual attack and defense drill
matlab绘制hsv色轮图
Emotional analysis of wechat chat records on Valentine's day based on Text Mining
Incentive mechanism of Ethereum eth
CRM creates its own custom report based on fetch
What should I do to prepare for the interview algorithm position during school recruitment?
Deployment of Jenkins under win7
SQL knowledge leak detection
Analysis and test of ModbusRTU communication protocol