Parsing in Java methods means that the method is taking input from a string and returning some other data type.Definition of parseThe actual definition of "parse" in Wiktionary is "To split a file or other input into pieces of data that can be easily stored or manipulated." So we are splitting a string into parts then recognizing the parts to convert it into something simpler than a string.Parsing an integerAn example would be the parseInt function. It would take an input such as "123", which would be a string consisting of the char values 1, 2, and 3. Then it would convert this value to the integer 123, which is a simple number that can be stored and manipulated as an integer.I can see why you might be confused by this simple example, though, since the string "123" doesn't have any obvious parts.Parsing a dateHere is a better example involving parsing a date from a string:SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = format.parse("2016-04-23");
This example shows a date format that actually has recognizable parts:yyyy is the year- is a literal dashMM is the month- is another literal dashdd is the dayJava is parsing the date string for you by breaking it down into a predefined template of parts and recognizing the parts. Then the the parse function outputs a date object, which is easier to store and manipulate than a date string.Parsing a whole languageThis is what parsing always means. Whole programming languages are parsed according to how the parts are built together in the language definition.And not only that, but individual statements, words, and data pieces of the language can be parsed as well, because they are defined as little bits of syntax.Examples of this would include:Parsing a hexadecimal number, like "0xFF", by breaking it down into the , the x, and the series of characters from -9 and a-f or A-F.Parsing a floating point number like "-1.23f", by breaking it down into a sign, an integer part, a decimal point, a fractional part, then the letter f for float.Little structures like this are defined throughout the language, which is why those parsing functions keep popping up. There is no limit to the functions of this type that can be created, since an endless variety of new syntax definitions can be created to parse.However, Java tends to limit itself to variations of known syntax, like integer, float, and date, that are predefined for it.Why use parsing functions?Because user input is nearly always in the form of strings. Before you can convert it to a Java data type that you can actually work with, you usually need to parse it.The exception is when you are working with ordinary text. In that case, you leave the string as a string, and just use string functions to manipulate it, by changing case, or splitting into substrings, or whatever.