Java test every day

Free Core Java Online Practice Test and Preparation for Exam
20190110

1.legal identifier

image.png

java naming:Variables
firstLetter: letter ,$,_
number is not allowed in first letter
secondAfter:letter,$,digit,_
+ is not allowed here
20190111
2.variable initialization
local or static.png

Java (https://en.wikipedia.org/wiki/Java_(programming_language) "Java does not have uninitialized variables. Fields of classes and objects that do not have an explicit initializer and elements of arrays are automatically initialized with the default value for their type.
Local variables in Java must be definitely assigned to before they are accessed, or it is a compile error.

3. data type

Primitive Data Types (Java)
Cours java : Types de donnée primitifs

整數(shù)類型:
byte:8 bite(-128~127)
short :2 byte = 16 bite
int:4 byte = 32 bite
long:8 byte = 64 bite
浮點(diǎn)型:
float:單精度膜蛔,32 bite
double: 雙精度惫确;64 bite

float is represented in 32 bits, with 1 sign bit, 8 bits of exponent, and 23 bits of the significand.
double is represented in 64 bits, with 1 sign bit, 11 bits of exponent, and 52 bits of significand.
scientific-notation number: 2.33728*1012; 33728 is the significand).

字符型:
char :2 byte = 16 bite

使用:
byte,short 直接使用
long:long l = 2[L/l];
float:float f = 2.3f or 2.3F;
double:double d = 2.383747[D/d/];
因?yàn)閘ong和double在整型和浮點(diǎn)型中范圍最大玛界,因此不用刻意指出類型,不會失去精度。
而float如果不指出,possible lossy conversion from double to float

20190115

4 abstract class

abstract class

abstract class may contain abstract method or not, it can't be instantiated like interface, but it can be extended.

20190130
test4

5 bit operations

source:Opérateurs bit à bit

image.png

image.png

The Java equivalent of 'unsigned'
Signed vs unsigned(有符號和無符號)
In C:
When an integer is signed, one of its bits becomes the sign bit, meaning that the maximum magnitude of the number is halved. (So an unsigned 32-bit int can store up to 232-1, whereas its signed counterpart has a maximum positive value of 231-1.)
In java:

In Java, all integer types are signed (except char).

Signed vs unsigned shifts
this operator performs sign extension: that is, as well as shifting the bits of the number one place to the right, it preserves the sign. Specifically, after performing the shift, it copies the sign bit (the leftmost bit) into the leftmost position.
Now, if we're treating an integer as unsigned, then we don't want to copy the sign bit, because it doesn't actually represent the sign! Instead, we want to leave it as zero. To achieve this, in Java, instead of writing >>, we write >>>.

6.Data range

image.png

byte: 8-bit signed,( -128 , 127).
Short: 16-bit signed,( -32,768 , 32,767).
Int: 32-bit signed,(,-231,231-1)

7 Map vs collection

image.png

Collections Framework Overview

The collection interfaces are divided into two groups.
The most basic interface, java.util.Collection,
The other collection interfaces are based on java.util.Map.

8 overloading

overloading

Defining Methods (The Java Tutorials)

The Java programming language supports overloading methods, and Java can distinguish between methods with different method signatures. This means that methods within a class can have the same name if they have different parameter lists (there are some qualifications to this that will be discussed in the lesson titled "Interfaces and Inheritance").

Attention:parameter lists, not including return type.

9 access level

Controlling Access to Members of a Class (The Java Tutorials)
default vs protected
default = no modifier

image.png

image.png

10 Initial Values of Variables

image.png

Chapter 4. Types, Values, and Variables

  • Each class variable, instance variable, or array component is initialized with a default value when it is created
  • A local variable must be explicitly given a value before it is used, by either initialization or assignment.

11 equals() vs ==

equals vs ==

equals() compare content
== compare memory address

test7

12 if(condition)

condition must be true or false
int a = 1;
if(a) will lead a compile error.

test10

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末饥侵,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子衣屏,更是在濱河造成了極大的恐慌躏升,老刑警劉巖,帶你破解...
    沈念sama閱讀 212,542評論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件狼忱,死亡現(xiàn)場離奇詭異膨疏,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)钻弄,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,596評論 3 385
  • 文/潘曉璐 我一進(jìn)店門佃却,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人窘俺,你說我怎么就攤上這事饲帅。” “怎么了瘤泪?”我有些...
    開封第一講書人閱讀 158,021評論 0 348
  • 文/不壞的土叔 我叫張陵灶泵,是天一觀的道長。 經(jīng)常有香客問我对途,道長丘逸,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,682評論 1 284
  • 正文 為了忘掉前任掀宋,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘劲妙。我一直安慰自己湃鹊,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,792評論 6 386
  • 文/花漫 我一把揭開白布镣奋。 她就那樣靜靜地躺著币呵,像睡著了一般。 火紅的嫁衣襯著肌膚如雪侨颈。 梳的紋絲不亂的頭發(fā)上余赢,一...
    開封第一講書人閱讀 49,985評論 1 291
  • 那天,我揣著相機(jī)與錄音哈垢,去河邊找鬼妻柒。 笑死,一個胖子當(dāng)著我的面吹牛耘分,可吹牛的內(nèi)容都是我干的举塔。 我是一名探鬼主播,決...
    沈念sama閱讀 39,107評論 3 410
  • 文/蒼蘭香墨 我猛地睜開眼求泰,長吁一口氣:“原來是場噩夢啊……” “哼央渣!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起渴频,我...
    開封第一講書人閱讀 37,845評論 0 268
  • 序言:老撾萬榮一對情侶失蹤芽丹,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后卜朗,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體拔第,經(jīng)...
    沈念sama閱讀 44,299評論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,612評論 2 327
  • 正文 我和宋清朗相戀三年聊替,在試婚紗的時候發(fā)現(xiàn)自己被綠了楼肪。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,747評論 1 341
  • 序言:一個原本活蹦亂跳的男人離奇死亡惹悄,死狀恐怖春叫,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情泣港,我是刑警寧澤暂殖,帶...
    沈念sama閱讀 34,441評論 4 333
  • 正文 年R本政府宣布,位于F島的核電站当纱,受9級特大地震影響呛每,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜坡氯,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 40,072評論 3 317
  • 文/蒙蒙 一晨横、第九天 我趴在偏房一處隱蔽的房頂上張望洋腮。 院中可真熱鬧,春花似錦手形、人聲如沸啥供。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,828評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽伙狐。三九已至,卻和暖如春瞬欧,著一層夾襖步出監(jiān)牢的瞬間贷屎,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,069評論 1 267
  • 我被黑心中介騙來泰國打工艘虎, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留唉侄,地道東北人。 一個月前我還...
    沈念sama閱讀 46,545評論 2 362
  • 正文 我出身青樓顷帖,卻偏偏與公主長得像美旧,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子贬墩,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,658評論 2 350

推薦閱讀更多精彩內(nèi)容