ComputersProgramming

Java: regular expressions, special characters

Today, programming in Java, most likely, no one will cause surprise. Progress in this area is so great that the present-day habitual reality would seem 50-60 years ago to be a real story from the movie "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.

Do not confuse the development language with the runtime environment or the 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 applications developed in this language, you need to install a special package of Java-components, which is available on the official website of Oracle. 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.

To install Java on your computer, the user must first make sure that the hardware specifications 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 that will only require you to specify a directory for installation, 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 with the installation.

Getting started in Java

After the user has successfully installed the software environment, various tools will be available to him for execution of already written programs, and for creating his 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.

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

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 must be "packed" into the JAR-archive.

The JAR format is derived from the shortening of 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 the .jar-archive, the utility with the same name is used, which is also included in the standard package from Oracle. After successful execution, the user can run the created application either with the Java command from the command line or console, or with a simple double click.

The main components of the Java language

In order to successfully develop applications in the Java language, learning it should start 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-called wrap classes, which 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 implementing 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.

Therefore, it is always necessary to work with strings very cautiously: despite the fact that garbage collection in memory works perfectly, 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 or substrings 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 somehow used to work with regular expressions are placed in a separate package 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.

In order to correctly specify the search parameters, it is better to familiarize yourself with the official documentation from Oracle, as many metacharacters can mean absolutely not what an ordinary user or a beginner programmer might think. For example, the "+" sign indicates that one or more instances of the immediately preceding element fall under the template. When implementing 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 regular expressions 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.

That is why when studying the language we are considering, there is absolutely no way to 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.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.birmiss.com. Theme powered by WordPress.