Skip to content

Commit b7830f8

Browse files
committed
add new file
1 parent ccbf1c1 commit b7830f8

5 files changed

Lines changed: 282 additions & 7 deletions

File tree

‎JavaCore/1.JavaConcurrency.md‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ List questions:
3333
1. [What is the difference between process and thread?](#what-is-the-difference-between-process-and-thread-)
3434
1. [What is an immutable object? How do you create an Immutable object in Java?](#what-is-an-immutable-object-how-do-you-create-an-immutable-object-in-java-)
3535
1. [Can we create an Immutable object, which contains a mutable object?](#can-we-create-an-immutable-object-which-contains-a-mutable-object-)
36+
1. [Why should you use immutable objects?](#why-should-you-use-immutable-objects-)
3637
1. [What are the states associated in the thread?](#what-are-the-states-associated-in-the-thread-)
3738
1. [When you will synchronize a piece of your code?](#when-you-will-synchronize-a-piece-of-your-code-)
3839
1. [What is deadlock? Example of deadlock.](#what-is-deadlock-example-of-deadlock-)
@@ -362,9 +363,16 @@ List questions:
362363

363364
***References:*** [javarevisited](http://javarevisited.blogspot.sg/2013/03/how-to-create-immutable-class-object-java-example-tutorial.html)
364365

365-
1. Can we create an Immutable object, which contains a mutable object? [⤴](#java-concurrency)
366+
1. ##### Can we create an Immutable object, which contains a mutable object? [⤴](#java-concurrency)
367+
366368
Yes, its possible to create an Immutable object which may contain a mutable object, you just need to be a little bit careful not to share the reference of the mutable component, instead, you should return a copy of it if you have to. Most common example is an Object which contain the reference of java.util.Date object.
367369

370+
1. ##### Why should you use immutable objects? [⤴](#java-concurrency)
371+
372+
One main advantage for using immutable objects is that, because the values cannot ever change, they can be freely passed from thread to thread without ever needing locking.
373+
This means that, because there is no locking with synchronized blocks, there is no bottleneck where multiple threads need to wait for a single mutable value to be available.
374+
Usually when you have a need to update the value in an immutable object, you make a new copy of the object with the updated value.
375+
368376
16. ##### What are the states associated in the thread? [⤴](#java-concurrency)
369377

370378
17. ##### When you will synchronize a piece of your code? [⤴](#java-concurrency)

‎JavaCore/2.JavaBasic.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ List questions:
5353
1. [How does Java handle integer overflows and underflows?](#how-does-java-handle-integer-overflows-and-underflows-)
5454
1. [What are polymorphism and inheritance?](#what-are-polymorphism-and-inheritance-)
5555
1. [String literal and String object](#string-literal-and-string-object-)
56+
1. [What does the keyword transient mean in Java?](#what-does-the-keyword-transient-mean-in-java-)
5657

5758
Main methods:
5859

@@ -64,6 +65,10 @@ Main methods:
6465
1. [What is the first argument of the String array in main method?](#what-is-the-first-argument-of-the-string-array-in-main-method-)
6566
1. [If I do not provide any arguments on the command line, then the String array of Main method will be empty or null?](#if-i-do-not-provide-any-arguments-on-the-command-line-then-the-string-array-of-main-method-will-be-empty-or-null-)
6667
1. [Can main method be declared final?](#can-main-method-be-declared-final-)
68+
1. [Can we make main synchronized in Java?](#can-we-make-main-synchronized-in-java-)
69+
1. [How to call a nonstatic method from main in Java?](#how-to-call-a-nonstatic-method-from-main-in-java-)
70+
1. [Can we overload the main method in Java? Which main method JVM will call?](#)
71+
1. [Can we override the main method in Java?](#can-we-override-the-main-method-in-java-)
6772

6873
---
6974

@@ -294,6 +299,9 @@ Both represent mutable sequence of characters.
294299

295300
[Difference between String literal and New String object in Java](http://www.java67.com/2014/08/difference-between-string-literal-and-new-String-object-Java.html)
296301

302+
1. ##### What does the keyword transient mean in Java? [⤴](#java-basics)
303+
It marks a member variable not to be serialized when it is persisted to streams of bytes. When an object is transferred through the network, the object needs to be 'serialized'. Serialization converts the object state to serial bytes. Those bytes are sent over the network and the object is recreated from those bytes. Member variables marked by the java transient keyword are not transferred, they are lost intentionally.
304+
297305
Main Method
298306
---
299307

@@ -323,6 +331,19 @@ Main Method
323331
8. ##### Can main method be declared final? [⤴](#java-basics)
324332
Yes it can be declared as final
325333

334+
1. ##### Can we make main synchronized in Java? [⤴](#java-basics)
335+
Yes, main can be synchronized in Java, synchronized modifier is allowed in the main signature and you can make your main method synchronized in Java.
336+
337+
1. ##### How to call a nonstatic method from main in Java? [⤴](#java-basics)
338+
This question applies not only to main but all static methods in Java. Since nonstatic methods can not be called from static context directly, you need to first create an Object as local variable and then you can call nonstatic method using that object
339+
340+
1. ##### Can we overload the main method in Java? Which main method JVM will call? [⤴](#java-basics)
341+
Yes you can overload the main method in Java, nothing wrong with this but Java will only call your specific main method, i.e. main method with the following signature:
342+
public static void main(String[] args) or public static void main(String args...) which is the main method as variable argument method and only supported post-Java 5 world
343+
344+
1. ##### Can we override the main method in Java? [⤴](#java-basics)
345+
No, you can not override the main method in Java, Why? because main is a static method and in Java static method is bonded during compile time and you can not override static method in Java. If you declare a method with same name and signature its called method hiding.
346+
326347
Reference
327348
---
328349
[svozniuk-repo](https://raw.githubusercontent.com/svozniuk/java-interviews/master/Java%20Core/Java%20Basics.md)

0 commit comments

Comments
 (0)