tag:blogger.com,1999:blog-8712770457197348465.post8478278401423782974..comments2024-03-19T01:04:48.783-07:00Comments on Javarevisited: Top 15 Java String interview Question Answers for 3 to 5 Years Experiencedjavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger27125tag:blogger.com,1999:blog-8712770457197348465.post-33690176102205994922019-10-27T11:31:31.323-07:002019-10-27T11:31:31.323-07:00We need main method because the code starts its ex...We need main method because the code starts its execution from main method. We can also say that main is pre declared user defined method.Anonymoushttps://www.blogger.com/profile/06058742336776542670noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-21924195844257215142019-01-31T04:59:33.730-08:002019-01-31T04:59:33.730-08:00Can you guys explain, why two objects?Can you guys explain, why two objects?javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-61252142879586540742019-01-28T08:45:44.694-08:002019-01-28T08:45:44.694-08:002 objects2 objectsAnonymoushttps://www.blogger.com/profile/04345443012422685996noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-55257226662851364782018-04-13T20:46:18.815-07:002018-04-13T20:46:18.815-07:002 objects2 objectsonlineTpointhttps://www.blogger.com/profile/18013100998590819353noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-72347857346971939712017-01-08T00:59:47.034-08:002017-01-08T00:59:47.034-08:002 objects 2 objects Skhttps://www.blogger.com/profile/15341641947130888880noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-25000048222852481662016-04-19T02:44:12.173-07:002016-04-19T02:44:12.173-07:00My solution using StringBuffer:
//input:"my n...My solution using StringBuffer:<br />//input:"my name is jack"<br />//output:"ym eman si kcaj"<br /><br />public class ReversingCharcaterInAString {<br /><br /> public static void main(String[] args) {<br /> // TODO Auto-generated method stub<br /> String sentence = new String("my name is jack");<br /> StringBuffer sb = new StringBuffer();<br /> StringBuffer sb1 Anonymoushttps://www.blogger.com/profile/11969936631512230959noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-73085727258033145952015-12-28T00:50:31.801-08:002015-12-28T00:50:31.801-08:00Hello
shariq bharat
there will be created 3 string...Hello<br />shariq bharat<br />there will be created 3 string objects<br />Anonymoushttps://www.blogger.com/profile/10132194033593524266noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-6516753916954067152015-09-16T12:26:26.758-07:002015-09-16T12:26:26.758-07:00Hi,
I am using some string objects in my programme...Hi,<br />I am using some string objects in my programme and in finally block making it null. Will it be garbage collected?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-6791618725862921842015-08-21T04:19:01.342-07:002015-08-21T04:19:01.342-07:00/*input : my name is rajesh
output :ym eman si hs...<br />/*input : my name is rajesh<br />output :ym eman si hsejar<br />*/<br />class Program20 <br />{<br /> public static void main(String[] args) <br /> {<br /> System.out.println("---------------------------------");<br /> String str="my name is rajesh";<br /> System.out.println("Given string :"+str);<br /> String[] st=str.split(" ");<br /> for(int Anonymoushttps://www.blogger.com/profile/04907177239155905328noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-82511555257017318692015-02-27T07:45:15.422-08:002015-02-27T07:45:15.422-08:00@ Anonymous: Yes in Java 7 we can use String in Sw...@ Anonymous: Yes in Java 7 we can use String in Switch. but We can achieve it using Enum.<br /><br />private enum Fruit {<br /> apple, carrot, mango, orange;<br />}<br /><br />String value; // assume input<br />Fruit fruit = Fruit.valueOf(value); // surround with try/catch<br /><br />switch(fruit) {<br /> case apple:<br /> method1;<br /> break;<br /> case carrot:<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-69816586322023488082014-10-25T23:26:37.520-07:002014-10-25T23:26:37.520-07:00package com.str1;
import java.io.*;
import java.io...package com.str1;<br />import java.io.*;<br />import java.io.BufferedReader;<br />import java.io.InputStreamReader;<br /><br />public class B <br />{<br /> public static void main(String[] args)throws IOException <br /> {<br /> String s1;<br /> System.out.println("Enter the String= ");<br /> BufferedReader in=new BufferedReader(new InputStreamReader(System.in));<br /> s1=Anonymoushttps://www.blogger.com/profile/09936402402735712473noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-75645118195277021372014-09-04T08:34:57.705-07:002014-09-04T08:34:57.705-07:00One question you need to add into this list is &qu...One question you need to add into this list is "What encoding method do Strings use?", as I strongly feel that Java developer should be aware of character encoding and make sure they use right encoding while converting bytes to string and vice-versa. I expect "UTF-16" or "UCS 2" as answer, though UTF-16 is more appropriate. If candidate mention about use of surrogateAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-72412633361511340432014-08-19T23:40:16.658-07:002014-08-19T23:40:16.658-07:00How substring method work in Java ? , Answer for t...How substring method work in Java ? , Answer for this question need an attention. The new JDK provided the fix for memory leak.Bhagath Sagarhttps://www.facebook.com/bhagathsagarnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-49847191080038179462014-07-27T08:40:38.955-07:002014-07-27T08:40:38.955-07:002 months after this posting question #8 became voo...2 months after this posting question #8 became voodoo optimization: http://www.javaadvent.com/2012/12/changes-to-stringsubstring-in-java-7.html<br /><br />2 years later I'm still seeing this blog post thrown around without the correction. Here is a good overview of the differences: http://jaxenter.com/the-state-of-string-in-java-49450.htmlKarl the Paganhttps://www.blogger.com/profile/08670068559230178483noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-43274049746030298022014-03-11T06:09:50.544-07:002014-03-11T06:09:50.544-07:00my question is
why we create main method , and h...my question is <br /><br />why we create main method , and how it will be created Anonymoushttps://www.blogger.com/profile/09620522849355041488noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-24219294067159828062014-03-11T06:08:14.494-07:002014-03-11T06:08:14.494-07:00two object are created to answer of shariq bhagat
...two object are created to answer of shariq bhagat<br /><br />for in heap memory and another will in string pool as constant'<br /><br />and both have different hascodeAnonymoushttps://www.blogger.com/profile/09620522849355041488noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-87809174738007436382014-03-08T03:19:56.900-08:002014-03-08T03:19:56.900-08:00My previous String reversal implementation is very...My previous String reversal implementation is very basic and limited, the task is a little bit more complicated because of the unicode character representation: http://docs.oracle.com/javase/6/docs/api/java/lang/Character.html#unicode<br />One have to consider surrogate ranges (a unicode character could be represented by two char-s)madnorbhttps://www.blogger.com/profile/16130714949556057088noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-86909970808000422992014-03-08T03:02:02.783-08:002014-03-08T03:02:02.783-08:00I left in a bug :), this is the bugfix:
...
flip...I left in a bug :), this is the bugfix:<br />...<br /> flip(charArray, wordStartIdx, charArray.length-1);<br /> return new String(charArray);<br /> }<br />...madnorbhttps://www.blogger.com/profile/16130714949556057088noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-50293280913194340562014-03-08T02:58:12.902-08:002014-03-08T02:58:12.902-08:00@Sanidhya A quick implementation, hopefully withou...@Sanidhya A quick implementation, hopefully without bugs :)<br /><br />public class ReverseWords {<br /> public String run(String input, char delimiter){<br /> if (input == null) return null;<br /> char[] charArray = input.toCharArray();<br /> int wordStartIdx = 0;<br /> for(int i = 0; i from; to--, from++){<br /> char tmp = charArray[from];<br /> charArray[from] = charArray[to];<br /> madnorbhttps://www.blogger.com/profile/16130714949556057088noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-83480766714887331382013-08-28T03:14:55.226-07:002013-08-28T03:14:55.226-07:00In the JDK 7 release, you can use a String object ...In the JDK 7 release, you can use a String object in the expression of a switch statement<br /><br />http://docs.oracle.com/javase/7/docs/technotes/guides/language/strings-switch.htmlKaushal Kapoorhttps://www.blogger.com/profile/13062148145438610012noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-26328209918754623082013-08-22T20:42:56.137-07:002013-08-22T20:42:56.137-07:00Hello Javin, Can we use String in Switch case? Thi...Hello Javin, Can we use String in Switch case? This question is asked to me at TCS Interview? I said no, because Switch only accept integer values, but interviewer was not happy at all?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-76885118768771076992013-08-22T20:10:01.538-07:002013-08-22T20:10:01.538-07:00To answer Shariq Bharat questions in more detail, ...To answer Shariq Bharat questions in more detail, Yes, there are two objects are created, but both are created in first line itself. Before creating object using new String(), JVM creates an string literal "abc", that is your first object, now by using content of this object, second object is created by calling constructor of String, this object also has value "abc" but Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-11547221104285652822013-08-22T10:32:32.116-07:002013-08-22T10:32:32.116-07:00question pls
input:"my name is jack"
out...question pls<br />input:"my name is jack"<br />output:"ym eman si kcaj"Anonymoushttps://www.blogger.com/profile/04246682938446916934noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-85386019082949128452013-03-16T02:35:28.886-07:002013-03-16T02:35:28.886-07:00@Attila-Mihaly Balazs , 99.99% agree with you, and...@Attila-Mihaly Balazs , 99.99% agree with you, and one should be using StringBuilder by default.Javin @ Must Override Eclipse Errorhttp://javarevisited.blogspot.com/2013/02/must-override-superclass-method-java-eclipse.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-62478258423800168142013-03-16T02:34:18.645-07:002013-03-16T02:34:18.645-07:00@Shariq Bharat, Two object, one in each line. Seco...@Shariq Bharat, Two object, one in each line. Second one will be added into String pool.Javin @ String to int in Javahttp://javarevisited.blogspot.com.au/2011/08/convert-string-to-integer-to-string.htmlnoreply@blogger.com