I just announced the new Spring 5 modules in REST With Spring:

>> CHECK OUT THE COURSE

This tutorial series focuses on core Java - "Back to Basics". We're going to cover Java Collections and Java IO:

1. Core Java Language Concepts

2. Core Java

7. Advanced Java

8. Tracking Java Development

There we go - the "Back to Basics" Java series, covering basic operations with collections and IO.

I just announced the new Spring 5 modules in REST With Spring:

>> CHECK OUT THE LESSONS

newest oldest most voted
Deepak Pandey
Guest
Deepak Pandey

Hey Eugen. when we use new operator to create a String object.
i.e String obj1=new String(“abc”);
It will create object in heap , but is it create an object in String pool also or copy the value in string pool.
Please elaborate the process.
Thanks
Deepak

Eugen Paraschiv
Guest

Hey Deepak. Simply put, when you instantiate the String object via the constructor, you’re creating a new object on the heap. When you’re using the String literal, you’re referencing it in the String pool. That distinction will determine the equality of these references.
Of course there are a lot of solid tutorials online that go into the details of how that works, so I’d definitely recommend doing a search and reading through some of these – it’s worth taking a bit of time to get the basics nailed down.
Hope it helps. Cheers,
Eugen.

drumdumdum
Guest
drumdumdum

See Example 3.10.5-1. String Literals in Java language specification. Literal strings within the same class (§8) in the same package (§7) represent references to the same String object (§4.3.1). Literal strings within different classes in the same package represent references to the same String object. Literal strings within different classes in different packages likewise represent references to the same String object. Strings computed by constant expressions (§15.28) are computed at compile time and then treated as if they were literals. Strings computed by concatenation at run time are newly created and therefore distinct. The result of explicitly interning a computed… Read more »