You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Java/basics.md
+71-9Lines changed: 71 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,10 +3,8 @@
3
3
-[What is JRE, JDK & JVM?](#what-is-jre-jdk--jvm)
4
4
-[Battle of JDKs. OpenJDK vs Oracle JDK](#battle-of-jdks-openjdk-vs-oracle-jdk)
5
5
-[Datatypes](#datatypes)
6
-
-[Details](#details)
7
-
-[Character constant vs String Constant](#character-constant-vs-string-constant)
6
+
-[Character vs String](#character-vs-string)
8
7
-[Boxing & Unboxing](#boxing--unboxing)
9
-
-[StingBuilder vs StringBuffer and immutability](#stingbuilder-vs-stringbuffer-and-immutability)
10
8
-[Language features](#language-features)
11
9
-[Constructors](#constructors)
12
10
-[Can the constructor be overridden?](#can-the-constructor-be-overridden)
@@ -17,6 +15,9 @@
17
15
-[Difference between instance variables & local variables](#difference-between-instance-variables--local-variables)
18
16
-[Object creation](#object-creation)
19
17
-[Static vs instance methods](#static-vs-instance-methods)
18
+
-[Interning](#interning)
19
+
-[Mutable & Immutable](#mutable--immutable)
20
+
-[StingBuilder vs StringBuffer and immutability](#stingbuilder-vs-stringbuffer-and-immutability)
20
21
-[equals](#equals)
21
22
-[hashCode](#hashcode)
22
23
-[equals + hashCode](#equals--hashcode)
@@ -68,13 +69,13 @@ Java is secure by design. Lots of opensource libraries, big and mature community
68
69
pic-here
69
70
70
71
JRE - Java Runtime Environment
71
-
JRE is an environment which is designed to run programs. It contains the class libraries, loader class, and JVM.
72
+
JRE is an environment which is designed to run programs. It contains the class libraries, loader class, and JVM. It is platform dependent.
72
73
73
74
JVM - Java Virtual Machine
74
-
JVM is an engine that provides a runtime environment to drive the Java Code or applications. It converts Java bytecode into machine language. JVM is a part of Java Run Environment (JRE). It cannot be separately downloaded and installed. To install JVM, you need to install JRE. The full form of JVM is Java Virtual Machine.
75
+
JVM is an engine that provides a runtime environment to drive the Java Code or applications. It converts Java bytecode into machine language. JVM is a part of Java Run Environment (JRE). It cannot be separately downloaded and installed. To install JVM, you need to install JRE. The full form of JVM is Java Virtual Machine. It is platform independent.
75
76
76
77
JDK - Java Developer Kit
77
-
JDK is a software development environment used for making applets and Java applications
78
+
JDK is a software development environment used for making applets and Java applications. It contains developing, debuggin & monitoring libraries. It is platform dependent.
78
79
79
80
80
81
```
@@ -85,12 +86,44 @@ rt - Run Time
85
86
```
86
87
87
88
## Battle of JDKs. OpenJDK vs Oracle JDK
89
+
Sun microsystems owned the JDK until Oracle acquired Sun microsystems. So Sun JDK has become Oracle JDK after the acquisition. Oracle maintains the Oracle JDK.
90
+
91
+
OpenJDK is an open source implementation of the Java Standard Edition platform with contribution from Oracle and open Java community. OpenJDK was the reference implementation for Java 7, maintained by Oracle.
92
+
93
+
Oracle JDK is built from the OpenJDK, so technically there are no much differences apart from the enterprise support and bug fixes Oracle JDK provides. However Oracle SDK provides better performance over OpenJDK.
94
+
95
+
OpenJDK is released under license `GPL v2` wherein Oracle JDK is licensed under `Oracle Binary Code License Agreement`.
96
+
97
+
Oracle JDK has Flight Recorder, Java Mission Control, and Application Class-Data Sharing features, while OpenJDK has the Font Renderer feature.
char (Character) datatype (primitive) is a single character surrounded by single quotes. It occupies 2 bytes of memory size. String is a non primitive Object, it is usually one or more characters surrounded by double quotes.
104
+
105
+
```
106
+
Eg:
107
+
char -> 'a','1','.' etc
108
+
String -> "a", "a is an English alphabet", "1 + 1 = 2"
109
+
```
110
+
92
111
### Boxing & Unboxing
93
-
### StingBuilder vs StringBuffer and immutability
112
+
`Autoboxing` is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes. For example, converting an int to an Integer, a double to a Double, and so on. If the conversion goes the other way, this is called `unboxing`.
113
+
114
+
|Primitive type|Wrapper class|
115
+
|--- |--- |
116
+
|boolean|Boolean|
117
+
|byte|Byte|
118
+
|char|Character|
119
+
|float|Float|
120
+
|int|Integer|
121
+
|long|Long|
122
+
|short|Short|
123
+
|double|Double|
124
+
125
+
Since Java is a Object Oriented language, in order to utilize the Object level features like Collections it is necessary for the primitive datatypes need to be converted to Objects. Java provides Autoboxing to facilitate this.
126
+
94
127
## Language features
95
128
### Constructors
96
129
### Can the constructor be overridden?
@@ -101,6 +134,35 @@ rt - Run Time
101
134
### Difference between instance variables & local variables
102
135
### Object creation
103
136
### Static vs instance methods
137
+
### Interning
138
+
String Interning is a method of storing only one copy of each distinct String Value, which must be immutable.
139
+
140
+
In Java, String class has a public method `intern()` that returns a canonical representation(Standaridized representation) for the string object. Java’s String class privately maintains a pool of strings, where String literals are automatically interned.
141
+
142
+
When the `invoke()` method is invoked an a String object, if the String literal is available in the pool, the reference of the object is returned from the pool. If it is not available in the pool, the object is added to the pool and the reference returned.
143
+
144
+
But when a String object is created with `new String()` a new object is created in Heap memory and returned. So this way of String initialization is mostly discouraged on performance grounds.
145
+
146
+
### Mutable & Immutable
147
+
When an object can change it's state, it is called a mutable Object. (In X-Men, people can can alter their form or abilities are called mutables).
0 commit comments