Skip to content

Commit ab985de

Browse files
committed
BASE-4618: Class variable example
1 parent f55e2ea commit ab985de

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.finalkeyword;
2+
3+
public class ClassVariableFinal {
4+
5+
final static String X = "x";
6+
final static String Y = "y";
7+
8+
public static void main(String[] args) {
9+
for (int i = 0; i < 1500; i++) {
10+
long startTime = System.nanoTime();
11+
String result = concatStrings();
12+
long totalTime = System.nanoTime() - startTime;
13+
if (i >= 500) {
14+
System.out.println(totalTime);
15+
}
16+
}
17+
}
18+
19+
private static String concatStrings() {
20+
return X + Y;
21+
}
22+
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.finalkeyword;
2+
3+
public class ClassVariableNonFinal {
4+
5+
static String x = "x";
6+
static String y = "y";
7+
8+
public static void main(String[] args) {
9+
for (int i = 0; i < 1500; i++) {
10+
long startTime = System.nanoTime();
11+
String result = concatStrings();
12+
long totalTime = System.nanoTime() - startTime;
13+
if (i >= 500) {
14+
System.out.println(totalTime);
15+
}
16+
}
17+
}
18+
19+
private static String concatStrings() {
20+
return x + y;
21+
}
22+
23+
}

0 commit comments

Comments
 (0)