当前位置:网站首页>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 :
char
stay 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
边栏推荐
- NET中小型企业项目开发框架系列(一个)
- How to prepare for the algorithm interview and answer the algorithm interview questions
- 多家呼吸机巨头产品近期被一级召回 呼吸机市场仍在增量竞争
- 微服务入门(RestTemplate、Eureka、Nacos、Feign、Gateway)
- ESP32
- Problems encountered in office--
- An exception occurred in Huawei game multimedia calling the room switching method internal system error Reason:90000017
- Zhang Lijun: la pénétration de l’incertitude dépend de quatre « invariants»
- PyGame practical project: write Snake games with 300 lines of code
- poj 3237 Tree(树链拆分)
猜你喜欢
KingbaseES V8R3集群维护案例之---在线添加备库管理节点
AD637 usage notes
华为游戏多媒体服务调用屏蔽指定玩家语音方法,返回错误码3010
Parker driver maintenance COMPAX controller maintenance cpx0200h
Some common processing problems of structural equation model Amos software
Emotional analysis of wechat chat records on Valentine's day based on Text Mining
2.2.3 output of documents
Kingbasees v8r3 cluster maintenance case -- online addition of standby database management node
Sorting out the problems encountered in MySQL built by pycharm connecting virtual machines
R language learning notes
随机推荐
Did you brush the real title of the blue bridge cup over the years? Come here and teach you to counter attack!
Cold violence -- another perspective of objective function setting
Chapter 05_ Storage engine
思特奇加入openGauss开源社区,共同推动数据库产业生态发展
Learning notes of statistical learning methods -- Chapter 1 Introduction to statistical learning methods
华为联机对战如何提升玩家匹配成功几率
如何组织一场实战攻防演练
从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析
About the writing method of SQL field "this includes" and "included in" strings
让开发效率提升的跨端方案
华为快游戏调用登录接口失败,返回错误码 -1
Hysbz 2243 staining (tree chain splitting)
Shell script, awk condition judgment and logic comparison &||
JMeter installation under win7
Ethereum ETH的奖励机制
ICMP 介绍
Some things make feelings nowhere to put
Haas506 2.0 development tutorial - Alibaba cloud OTA - PAC firmware upgrade (only supports versions above 2.2)
Yolov5 training custom data set (pycharm ultra detailed version)
Poj 3237 Tree (Tree Chain Split)