Skip to content

Commit b201f73

Browse files
author
Kishore
committed
updated
1 parent 07e1a5b commit b201f73

3 files changed

Lines changed: 72 additions & 9 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

Java/basics.md

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
- [What is JRE, JDK & JVM?](#what-is-jre-jdk--jvm)
44
- [Battle of JDKs. OpenJDK vs Oracle JDK](#battle-of-jdks-openjdk-vs-oracle-jdk)
55
- [Datatypes](#datatypes)
6-
- [Details](#details)
7-
- [Character constant vs String Constant](#character-constant-vs-string-constant)
6+
- [Character vs String](#character-vs-string)
87
- [Boxing & Unboxing](#boxing--unboxing)
9-
- [StingBuilder vs StringBuffer and immutability](#stingbuilder-vs-stringbuffer-and-immutability)
108
- [Language features](#language-features)
119
- [Constructors](#constructors)
1210
- [Can the constructor be overridden?](#can-the-constructor-be-overridden)
@@ -17,6 +15,9 @@
1715
- [Difference between instance variables & local variables](#difference-between-instance-variables--local-variables)
1816
- [Object creation](#object-creation)
1917
- [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)
2021
- [equals](#equals)
2122
- [hashCode](#hashcode)
2223
- [equals + hashCode](#equals--hashcode)
@@ -68,13 +69,13 @@ Java is secure by design. Lots of opensource libraries, big and mature community
6869
pic-here
6970

7071
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.
7273

7374
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.
7576

7677
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.
7879

7980

8081
```
@@ -85,12 +86,44 @@ rt - Run Time
8586
```
8687

8788
## 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.
8898

8999
## Datatypes
90-
### Details
91-
### Character constant vs String Constant
100+
![Data Types](images/Java_Datatypes.png?raw=true "Data Types")
101+
102+
### Character vs String
103+
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+
92111
### 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+
94127
## Language features
95128
### Constructors
96129
### Can the constructor be overridden?
@@ -101,6 +134,35 @@ rt - Run Time
101134
### Difference between instance variables & local variables
102135
### Object creation
103136
### 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).
148+
149+
Immutability provides Security, Performance & Thread Safety.
150+
151+
```
152+
Tip:
153+
Normally immutability in java is achieved through following steps :
154+
155+
1. Don’t provide mutator methods for any field
156+
2. Make all fields final and private
157+
3. Don’t allow subclasses by declaring the class final itself
158+
4. Return deep cloned objects with copied content for all mutable fields in class
159+
```
160+
161+
### StingBuilder vs StringBuffer and immutability
162+
In Java String is an immutable object, i.e. everytime there is any change made to the String object, a new object will be created (or referred).
163+
164+
165+
104166
### equals
105167
### hashCode
106168
### equals + hashCode

images/Java_Datatypes.png

44.2 KB
Loading

0 commit comments

Comments
 (0)