/ / Java: regular expressions, special characters

Java: regular expressions, special characters

Today, Java programming is most likelyno one will be surprised. Progress in this area is so great that today's familiar reality would seem to us 50-60 years ago as a real plot from the movie a la "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 its support and development began to be implemented by Oracle.

java regular expressions
Не стоит путать язык разработки со средой performance or software platform. The latter should be understood as a combination of many different components, which together ensure 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 means of a virtual machine (JVM) - part of the software platform.

Installation and Getting Started

In order to successfully run developed onIn this application language, you need to install a special package of Java components, which 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 necessarily have to use a version of Java that is different from the latest, newest one. It only makes sense for developers who need features and capabilities specific to certain strategies.

java package

To install Java on your computer,The user must first make sure that the hardware specifications meet the minimum system requirements. Oracle engineers have worked hard to lower the threshold of system requirements, but it still exists and needs to be considered. The user must find the necessary distribution on the site, based on the operating system in which he wants to install the software. For example, Java for Windows 7 is an executable.exe-file, which will require only to specify the directory for installation, and then he will do everything himself. It is worth noting that only one copy of the software shell can be installed on the system at a time. Therefore, before installing you need to make sure that the previous version of Java is removed from the system. If this is not done, the installer will ask you to remove the conflicting program before proceeding with the installation.

Begin Development in Java

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

java strings

Oracle has taken care toProvide a maximum set of tools for developers. The Java package includes a language compiler (the Javac utility), which, taking the path to any text file as an argument, converts it into bytecode that the virtual machine understands.

java for windows

After that, the user can not start the application and see the results of their work. To install a Java application for Windows 7, it is necessary to “pack” it into a JAR archive.

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

Core components of the Java language

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

For each of them there are so-calledclasses are wrappers that are used to create a link to an object of a particular kind. This is true for all primitive types, except for string data.

Java class string implementation considerations

Java strings are a special class.It can be classified as an immutable object. If the application's memory is presented as a heap, which contains an arbitrary string, then each operation on it (substring allocation, concatenation, character replacement, etc.) will create a new instance of the original line, which will differ from the original result of the operation.

java version
Therefore, you should always work with strings extremelycaution: despite the fact that the garbage collection in memory works great, the programmer should be extremely careful to prevent memory from overflowing with unnecessary references to lines. 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.

Java language is a regular expression. Their appearance and purpose

Regular expressions appeared at the end of the twentieth century and revolutionized the technology of electronic word processing.

Previously search for certain sections in the text orsubstring was a common problem that required effort and time to implement. Programmers had to check almost every area for exact compliance with a given 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 which it became possible to describe the pattern by which the search should be performed. In Java, regular expressions appeared in version 5, and since then have become an integral attribute of the software environment.

Peculiarities of working with regular expressions in Java

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

install java

In order to correctly specify the parameterssearch, it is better to familiarize yourself with the official documentation from Oracle, since many metacharacters can mean something completely different from what an ordinary user or novice programmer might think. For example, the “+” sign indicates that one or more instances of the immediately preceding element fall under the pattern. When implemented in Java regular expressions, special characters are the same as in any other programming language. Therefore, migration from another platform should go smoothly.

Possible uses of regular expressions

It is worth noting that the possibilities of regularexpressions are most suitable for processing very large texts. For example, the search for some key or phrase in the book, provided that the register in which the key is written is not important. Manual search of the text to solve such a problem would be extremely inefficient, and with the help of Java-embedded regular expressions, the problem can be solved with a couple of lines of code.

java regular expressions special characters

That is why when studying the considered by uslanguage can not miss such an important section as regular expressions. In Java, they can find application in a wide range of fields - from checking the correctness of data entry in the form (postal addresses, credit card numbers) to analyzing traffic and user requests.

Liked:
0
Popular Posts
Spiritual development
Food
yup