This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Krish Krishnan

Greenhorn
+ Follow
since Feb 13, 2020
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Krish Krishnan

The switch statement in Java: Why the language was designed in such a way that the execution falls through each steps, instead of exiting the switch statement, even after a predicate match was found and no explicit break was given after the matched case?
1 year ago
Continuing my last post:
The approach was to sort the string so that the alpha characters (if any exists) would occur first then the digits after. So, if the 1st character is a letter and last character is digit the check is successful.
1 year ago
Thanks much for clarifying this.
As a beginner, I am facing another challenge while coding String validation: Wanted to make sure the string contains at least 1 alphabetic character and at least 1 numeric. Defined the following:
final char[] digit = new char[] {'0','1',...'9'};
final char[] alpha = new char[] {'A','B',...'Z'};
hoping that the presence of both can be checked against these 2 (as a whole as in some other language constructs as (if str[0] in alpha) and (if str[length-1] in digit). is there an equivalent construct in Java? or any other better way the check be done in a better way than checking each element?  
1 year ago
Oh, immutable - forgot about it - Thanks for the quick response!
1 year ago
How do we sort the characters in a String?
1 year ago
Hello Mike, Congratulations on passing the OCA exam!
I have gone through the same situations you went through while taking the exam - at least 3 times my online attempts and twice with nearest testing center. In the case of testing center, I was getting notifications that the test center is closed (due to COVID situation) and asking me to reschedule the exam. During the online test attempts, I reach to the point where you enter the ID information along with the photos of the surroundings of the testing area after the test for the PC/Internet speed etc and meets the requirements. When I press 'Start Exam' button, the screen presents with a sample question and I agree with it by selecting "True" as answer. There it ends, period. I wait expecting the real test will be delivered for 10 to 15 min but no response. I wished that there will be some online communication about what's going on, by the proctor or some administering staff who must be noticing the ID information I had sent and the pics. Absolutely nothing!
Both time I tried to reach PearsonVUE contact number, but never got any responses both times (may be due to COVID).
My question is how did you (Mike) got the test delivered/completed? In general, are there any online tests conducted regularly with the online proctor available?
Thanks.
Thank you Junilu!
1 year ago
I should have used 'way' or 'process/procedure' instead of 'method which I think you interpreted as if I meant the the Java 'method'.

...the concatenate method . . .

Don't say concatenate method. You are not calling any concatenate methods there. You are assigning a new object.

Yes, I am realizing that a lot are out there to learn, and much to know what you express in questions may not be the right thing you wanted.

1 year ago
Thanks much to both the in-depth explanations and examples that helped to get into the matter in the right way!  
1 year ago
My post had a typo:
String s="1";  //s currently holds "1"
s += "2";       //s currently holds "12"
// typo: s += "2";       //s currently holds "12"
s += "3";       //s currently holds "123"
System.out.println(s)  //123

From both the responses, I did not get the answer for my question:
When String s declared and initialized with "1", and immutable, how the concatenate method changing the object pointed to by s? I understood that 'cause of the immutability, String s refers to a new object when concatenated with new elements (as "2" and "3' in the example), and making the sOld which keeps the original reference to "1" and "12" etc, but ready for garbage collection - and as this process is expensive, the StringBuilder and ArrayList were introduced, I believe.
1 year ago
String Immutability again! Sorry, trying to clarify it firm.
Quote: Once String object is created, it is not allowed to change. (OCA Java SE8 Programmer Study Guide ). The same chapter gives an example of String concatenation as below:
There is only one thing to know about concatenation, but it is an easy one. In this example you just have to remember what += does. s+="2" means s=s+"2".
String s="1";  //s currently holds "1"
s += "2";       //s currently holds "12"
s += "2";       //s currently holds "12"
System,out.println(s)  //123

When String s declared and initialized with "1", and immutable, how the concatenate method changing the object pointed to by s?
1 year ago
Thanks much for the many thoughtful responses received for my inquiry - very helpful in making the concept much more clear and learned few new things as bonus!
1 year ago
While it's perfectly understood that a & b are reference variables and not objects themselves, and a and b may be made to point to some objects such as "abc" etc. including null. Here the code snippet has some object methods such as a.toUppercase(),  b.replace("B", "2") and replace('C', '3') - the last 2 are chained, that return the results "ABC", "A2C", and "A23" respectively. As I understand, these 3 returned String objects don't change or replace the original Strings (maintaining their immutable status) and generating 3 new objects in the String pool. Along with returning the new results (and generating the new objects), the results' references are saved in the variable b (but not in a), as obvious in the code b=a.toUppercase() etc. Hence the explanation that b is changing and a not changing.
I hope my understanding is correct?
1 year ago
I am not sure how to explain - my doubt is why variables a and b are behaving differently being both are immutable? a not changing but b changing!
1 year ago