/ / Java: regular expressions, special characters

Java: regular expressions, special characters

Today, programming in Java, most likely,no one will not be surprised. Progress in this area is so great that the present-day familiar reality would appear 50-60 years ago to be a real story from a film "Back to the Future".

The origins of the Java language

Java is an object-oriented programming language that was originally developed by Sun Microsystems, and later it was supported and developed by Oracle.

java regular expressions
Do not confuse the development language with the environmentperformance or software platform. The latter should be understood as the set of many different components that together provide the execution of Java code in various hardware environments. Programs written in the Java language are translated into a special format, called bytecode, which is later executed by the virtual machine (JVM) - part of the software platform.

Installation and start-up

In order to successfully launch thein this application language, you need to install a special Java component package that is available on the official Oracle website. The company provides different distributions that differ in the target platform, as well as their various options. An ordinary user does not need to use a Java version other than the latest, the newest. This makes sense only for developers who need specific strategies for specific strategies and capabilities.

java package

To install Java on your computer,the user must first make sure that the characteristics of the equipment meet the minimum system requirements. Oracle engineers did a good job of reducing the threshold of system requirements, but it still exists, and it needs to be taken into account. The user must find on the site the necessary distribution, based on the operating system into which he wants to install the software. For example, Java for Windows 7 is an executable.exe-file, which requires only specify the directory to install, and then he will do everything himself. It should be noted that only one copy of the software shell can be installed simultaneously in the system. Therefore, before installing, you need to make sure that the previous version of Java is removed from the system. If you do not do this, the installer will ask you to remove the conflicting program before continuing installation.

Getting started in Java

After the user has successfully installedsoftware environment, it will be available to various tools for both execution of already written programs, and for creating your own. In order to start programming in the Java language, no additional programs are needed. You just need to learn new things and understand the architecture of the language. If the user was able to successfully install Java, and in the process there were no conflicts with other programs, the code can begin to be written in any text editor.

java string

Oracle has made sure thatprovide the maximum set of tools for developers. The Java package includes a language compiler (the Javac utility), which takes as its argument the path to any text file, converts it to a bytecode that the virtual machine understands.

java for windows

After that, the user can not start the application and see the results of his work. In order to install the Java application for Windows 7, it needs to be "packed" into the JAR archive.

The JAR format is derived from the reduction in the Java Archive,and this is a special kind of familiar ZIP-archive, which additionally contains a description of classes and dependencies and points to the entry point (main class) in the application. To create a .jar-archive, the utility with the same name is used, which is also included in the standard package from Oracle. After its successful execution, the user can run the created application either by the Java command from the command line or console, or by a simple double click.

The main components of the Java language

In order to successfully develop applicationsin the Java language, you need to start learning from the very beginning. Beginning programmers sometimes find it difficult to understand the term "object-oriented" language. Many people mistakenly believe that it means the fact that all entities that can be operated on in a language are objects. However, this is not quite true. In Java, besides objects, there is also a set of primitive types. These are integer data types (byte, short, int, long), which are integers of different digits, fractional data types (float, double), as well as strings and character types (String and char), respectively.

For each of them there are so-calledwrapper classes that are used to create a reference to an object of a certain type. This is true for all primitive types except string data.

Features of the implementation of the class of strings in Java

Java strings are a special class. It can be classified as an immutable object. If you imagine the application's memory as a heap, which contains an arbitrary string, then each operation on it (selecting a substring, concatenating, replacing symbols, etc.) will create a new instance of the original line, which will differ from the original result of the operation.

java version
Therefore, it is always necessary to work with strings extremelycautiously: despite the fact that garbage collection in memory works great, the programmer should be extremely careful not to allow memory overflow with unnecessary references to strings. Fortunately, for this there are many auxiliary classes. For example, you can use StringBuilder and StringBuffer, which allow you to manipulate strings, but do not create a new instance after each operation.

The Java language is a regular expression. Their appearance and purpose

Regular expressions appeared at the end of the twentieth century and revolutionized the technologies of electronic text processing.

Previously, the search for specific areas in the text orsubstring was a common problem that required effort and time to implement. Programmers had to check almost every site for an exact match with the specified search parameter or compare it with a large number of conditions. However, with the advent of regular expressions, it became possible to use metacharacters, with the help of which it became possible to describe the template by which the search was to be performed. In the Java language, regular expressions appeared in version 5, and have since become an integral attribute of the software environment.

Features of working with regular expressions in Java

In the Java language, all classes that are one way or anotherare used to work with regular expressions, put in a separate package, which is called java.util.regex. In Java, regular expressions are described by the Pattern class, which means "template" in English. This class takes as a constructor argument a string that can be used to create a template. When you want to describe it, it's better to use metacharacters instead of simple letters.

install java

In order to correctly specify the parameterssearch, it is better to get acquainted with the official documentation from Oracle, as many metacharacters can mean absolutely not what an average user or novice programmer might think. For example, the "+" sign indicates that one or more instances of the immediately preceding element fall under the template. When you implement regular expressions in Java, special characters are the same as in any other programming language. Therefore, migration from another platform should be painless.

Possible variants of using regular expressions

It should be noted that the possibilities of regularExpressions are most suitable for processing very large texts. For example, the search for a key or phrase in the book, provided that the register in which the key is written is not important. Manual search of the text for the decision of a similar task would be extremely inefficient, and with the help of Java regular expressions the task can be solved by a pair of lines of code.

java regular expressions special characters

That is why, when studying thelanguage, you can not skip such an important section as regular expressions. In Java, you can find applications in a variety of areas - from validating the input of data in the form (postal addresses, credit card numbers) to analyzing traffic and user requests.

Read more: