Prathyu Krishna

Greenhorn
+ Follow
since Apr 17, 2017
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Prathyu Krishna

I am not a Java programmer, but had some hands on Java in college. My prep was about 2 months. I studied Sybex book two times thoroughly and did practice questions after every chapter..
Watched youTube videos on the concepts which I was not confident enough
I brought Enthuware, but didn't work on it.. All I did was think like a compiler, go through the syntax then solve the program
I didn't get a lot of time because of my work and my score is not pretty good, but a pass is a pass...

I understand the trim() now, but what's the output ?
Both are Hello World, Is true the correct answer?

Henry Wong wrote:
When I run the code, I get "true" as the result.

Henry




Code is from Sybex book. I didn't try to run it
Here,



Here trim() doesn't change the value of z. Then, why it doesn't refer to the same reference as x?
why trim() doesn't output HelloWorld?





I got it. Thanks for taking time to explain this so well!
See this example..

My question is:
1. Strings are immutable then why does it append "d" ?
2. totally confused what reference variables are?

Can someone explain why it doesn't output SPARKY?

Here is the full code from Sybex review questions/ chapter3

3. String s= "Hello";
4. String t = new String(s);
5. if("Hello".equals(s))  System.out.println("1");
6 if(t==s) System.out.println("2");
7. if(t.equals(s)) System.out.println("3");
8. if("Hello"==s) System.out.println("4");
9. if("Hello"==t) System.out.println("5");
output: 1 3 4

I am now totally confused. why it doesn't print 5??
String s= "Hello";
String t = new String(s);
if(t.equals(s)) System.out.println("Equal");//outputs equal
if("Hello".equals(t)) System.out.println("Equal");//outputs equal
if(t==s)  System.out.println("Equal");//outputs equal

1.String s is saved in the string pool and String t doesn't reside in the string pool. why they both are equal??
2.Can there be these many if's without else?? I don't see any error with 3 if's

1.int x=0;
2. x++;
3. System.out.println(x); // outputs 1



1. int x=0;
2. ++x;
3. System.out.println(x); //outputs 1
 
Can you walk me through the flow of increment and decrement operators in various situations?
Why am I getting 1 as output? Can you walk me through the flow of the code??



here y++ is a post increment. why is it giving output as 2 like a pre-increment?