Thursday 22 November 2012

String Memory, String Pool



String memory

If you use the new keyword, a new String object will be created. Note that objects are always on the heap - the string pool is not a separate memory area that is separate from the heap.

The string pool is like a cache. If you do this:

String s = "abc";
String p = "abc";
 
then the Java compiler is smart enough to make just one String object, and s and p will both be referring to that same String object. If you do this:

String s = new String("abc");
 
then there will be one String object in the pool, the one that represents the literal "abc", and there will be a separate String object, not in the pool, that contains a copy of the content of the pooled object. Since String is immutable in Java, you're not gaining anything by doing this; calling new String("literal") never makes sense in Java and is unnecessarily inefficient.

Note that you can call intern() on a String object. This will put the String object in the pool if it is not already there, and return the reference to the pooled string. (If it was already in the pool, it just returns a reference to the object that was already there). See the API documentation for that method for more info.



 in java for String there is a special consideration, if you are creating a String class object like
String s="jai"
than this will go to string pool and if are again want the same string like
String s2="jai"
than no other object of String class is created now reference variable s2 will refer to "jai"
this is done because String objects are immutable.
and you can check it by == test like
if(s==s2)
this will give the true value and execute if condition.


means when you do any modification on them than another object of String class is created and the reference of that class is gone.like
String s="jai"
s=s.concat(" hai");
now is referring to jai hai and reference to jai string is gone and this object is stored is sting pool. for further use.
like in future we need that object than the new object is not created and by JVM the reference of that object is given to that reference variable.

and if you are creating a object by new operator than always new object is created .
e.g.
String s2="jai".
String s=new String ("jai");
 and now you are doing the == test than this will give false and if condition will not execute.
if(s2==s)
{
//code
}
this will not execute.


Tuesday 9 October 2012

Difference between Carriage Return, Line Feed (New Line) and Form Feed

Carriage return means to return to the beginning of the current line without advancing downward. The name comes from a printer's carriage, as monitors were rare when the name was coined. This is commonly escaped as "\r", abbreviated CR, and has ASCII value 13 or 0xD.

Linefeed means to advance downward to the next line; however, it has been repurposed and renamed. Used as "newline", it terminates lines (commonly confused with separating lines). This is commonly escaped as "\n", abbreviated LF or NL, and has ASCII value 10 or 0xA. CRLF (but not CRNL) is used for the pair "\r\n".

Form feed means advance downward to the next "page". It was commonly used as page separators, but now is also used as section separators. (It's uncommonly used in source code to divide logically independent functions or groups of functions.) Text editors can use this character when you "insert a page break". This is commonly escaped as "\f", abbreviated FF, and has ASCII value 12 or 0xC.
As control characters, they may be interpreted in various ways.

The most common difference (and probably the only one worth worrying about) is lines end with CRLF on Windows, NL on Unix-likes, and CR on older Macs (I believe the situation has changed somewhat with OS X to be more like Unix). Note the shift in meaning from LF to NL, for the exact same character, gives the differences between Windows and Unix. (Windows is, of course, newer than Unix, so it didn't adopt this semantic shift. I don't know the history of Macs using CR.) Many text editors can read files in any of these three formats and convert between them, but not all utilities can.
Form feed is a bit more interesting (even though less commonly used directly), and with the usual definition of page separator, it can only come between lines (e.g. after the newline sequence of NL, CRLF, or CR) or at the start or end of the file.

<br>
Assuming you mean this:
public static String newLine = System.getProperty("line.separator");
newLine is environment agnostic \r isn't.
So newLine will give you \r\n on windows but \n on another environment.
However, you shouldn't use this in a JTextArea and println will work fine with just \n on windows.
Edit now that I've seen the code and your comment

In your situation. I think you should use your own constant - \r\n
  File f = new File(strFileGenLoc);
  BufferedWriter bw = new BufferedWriter(new FileWriter(f, false));
  rs = stmt.executeQuery("select * from jpdata");
  while ( rs.next() ) {
    bw.write(rs.getString(1)==null? "":rs.getString(1));
    bw.write("\\r\\n");
  }

difference between RTGS and NEFT fund transfer

difference between RTGS and NEFT fund transfer

1. What is RTGS System?

Ans The acronym "RTGS" stands for Real Time Gross Settlement. RTGS system is a funds transfer mechanism where transfer of money takes place from one bank to another on a "real time" and on "gross" basis. This is the fastest possible money transfer system through the banking channel. Settlement in "real time" means payment transaction is not subjected to any waiting period. The transactions are settled as soon as they are processed. "Gross settlement" means the transaction is settled on one to one basis without bunching with any other transaction. Considering that money transfer takes place in the books of the Reserve Bank of India, the payment is taken as final and irrevocable.

2 How RTGS is different from Electronic Fund Transfer System (EFT) or National Electronics Funds Transfer System (NEFT)?

Ans EFT and NEFT are electronic fund transfer modes that operate on a deferred net settlement (DNS) basis which settles transactions in batches. In DNS, the settlement takes place at a particular point of time. All transactions are held up till that time. For example, NEFT settlement takes place 6 times a day during the week days (9.30 am, 10.30 am, 12.00 noon. 1.00 pm, 3.00 pm and 4.00 pm) and 3 times during Saturdays (9.30 am, 10.30 am and 12.00 noon). Any transaction initiated after a designated settlement time would have to wait till the next designated settlement time. Contrary to this, in RTGS, transactions are processed continuously throughout the RTGS business hours.

Source(s):

Reserve Bank of India
http://www.rbi.org.in/scripts/FAQView.aspx?Id=65

Monday 8 October 2012

TextBox only allows numbers/numerics

A Lot of javascript functions to assist you 

<script language="JavaScript" type="text/javascript">
function isNumber(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}
 
 
                               OR


Html

<input type="text" id="numbersOnly" />

Javascript

<script language="JavaScript" type="text/javascript">
var input = document.getElementById('numbersOnly');
input.onkeydown = function(e) {
    var k = e.which;
/* numeric inputs can come from the keypad or the numeric row at the top */
    if ( (k < 48 || k > 57) && (k < 96 || k > 105)) {
        e.preventDefault();
        return false;
    }
}
</script>

                               OR
 
Html
 
<input type="text" onKeyUp="numericFilter(this);" />
 <script language="JavaScript" type="text/javascript"> 
Javascript 
 
function numericFilter(txb){
        txb.value =txb.value.replace(/[^\0-9]/ig, "");
 }
 </script>