How to set up smartphones and PCs. Informational portal
  • home
  • Windows 7, XP
  • An introduction to Java programming. What technologies are the main components of the Java platform? Java Technologies and Web Application Development

An introduction to Java programming. What technologies are the main components of the Java platform? Java Technologies and Web Application Development

Language Java programming and its accompanying runtime system were designed so that once developed and compiled programs are delivered over the Internet in binary form and run on any Java-enabled machine. Security has been a part of Java development from the very beginning. This section will discuss the operation of this security system.

Java is a type-safe language. This means that the compiler will reject any attempt to use the variable like this



revenge with her type. For comparison, consider the following

It generates a random number and stores it in the p pointer. It then stores a zero byte at the address contained in p, overwriting what was there before - code or data. In Java, constructs that mix types in this way are prohibited by the grammar itself. In addition, Java does not have pointer variables, ghosts, user-managed memory allocations (such as malloc and free), and all array references are checked at runtime.

Java programs are compiled into intermediate binary code called JVM bytecode. There are about 100 commands in the JVM, most of which push objects of a particular type onto the stack, pop them off the stack, or arithmetically concatenate two entries on the stack. These JVM programs are generally interpreted, although in some
In some cases, they can be compiled into machine language for faster execution. In the Java model, applets sent over the Internet for remote execution are JVM programs.

When an applet arrives, it is passed through the JVM bytecode check procedure for compliance with certain rules. A properly compiled applet will match them automatically, but there is nothing stopping an attacker from writing a JVM applet in JVM assembly language. The verification procedure includes looking for answers to the following questions:

1. Is the applet trying to spoof pointers?

2. Does it violate access restrictions to members of private classes?

3. Is he trying to use a variable of one type as a variable of another type?

4. Does it generate a stack overflow or underflow?

5. Doesn't it perform invalid conversions of variables of one type to variables of another type?

If the applet passes all of these tests, it can be run without fear of accessing areas of memory other than its own.

However, applets can still make system calls by calling Java methods (procedures) provided for this purpose. The methods that were used to do this in Java have been improving all the time. In the first version of Java, the JDK (Java Development Kit) 1.0, applets were divided into two classes: reliable and unreliable. Applets fetching from the local disk were reliable and allowed to make any system call they needed. In contrast, applets obtained over the Internet were considered unreliable. They were run in a sandbox, as shown in Fig. 9.33, and they were practically not allowed to do anything.

After gaining experience with this model, Sun decided that it was too restrictive. JDK 1.1 has been digitally signed. When the applet came from the Internet, it was verified to be signed by a person or organization that the user trusts (as determined by the user's list of trusted digital signature holders). If the signatures could be trusted, the applet could do anything; if not, it ran in a sandbox with strict restrictions.

After gaining additional experience, this system was also found to be unsatisfactory, so the security model was changed again. JDK 1.2 introduced a configurable, highly customizable security policy that applies to all applets, both local and remote. This security model is so complex that a separate book should be devoted to its description (Gong, 1999), so we will give only a brief generalized picture of some of its main features. Each applet is characterized by two things: where it came from and who signed it. The question of where he came from is answered by his URL, and the question of who signed it is answered by the private key that was used to digitally sign him. Each user can create a security policy consisting of a list of rules. Each rule can list the URL, the owner of the signature, the object, and the action that the applet can take with the object if the applet's URL is

and the owner of the signature will match those specified in the rule. The conceptually provided information is shown in table. 9.3, although in reality it is formatted differently and relates to the Java class hierarchy.


One kind of action allows access to a file. An action can define a specific file or directory, a set of all files in a given directory, or a set of all files and directories recursively contained in a given directory. Three lines in table. 9.3 correspond to these three cases. In the first line, user Susan has set her permissions record so that applets coming from her tax processor machine, www.taxprep.com, and signed by the processing company, have read access to her tax data in file 1040.xls ... They can only read this file, which no other applets can read. In addition, all applets from all sources, whether signed or not, can read and write files in the / usr / tmp directory.

Further, Susan trusts Microsoft so much that she allows applets received from her site and signed by Microsoft to read, write and delete files below the Office directory in the directory tree, for example, to fix bugs and install new versions of software. To verify signatures, Susan must either have the required public key on her disk, or must receive them dynamically, for example, in the form of a certificate signed by a company she trusts and whose public key she has.

Not only files can act as protected resources. You can also protect network access. Here the object will be a specific port on a specific computer. The computer is specified using an IP address or DNS name; ports on this computer are indicated by a range of numbers. Possible actions include connecting to a remote computer and accepting connections from remote computer... Thus, the applet can access the network, but this access is limited to communicating with only those computers that are explicitly listed in the permission list. Applets can dynamically load if needed additional code(classes), but user-supplied classloaders can exercise strict control over which machines can source those classes. There are many other security tools available as well.

More on the topic Security in the Java System:

  1. Section 39 Classification of contracts in separate types. - Roman classification. - The system of Prussian law, French and Austrian code. - The system of the Russian vault. - The system of this presentation.

What is information security? This is a state of information security, which ensures its confidentiality, availability and integrity.

Usually, in order to assess the state of information security, it is necessary to understand and analyze threats and their sources, assess the level of damage, the likelihood of implementation and the relevance of threats, risks (optional) that may affect our system / information.

In my opinion, it is impossible to assess the safety of a particular technology or programming language without being tied to a specific implementation method, that is, without a specific ready-made software product in a language that has a detailed technical specification with a description of the architecture and functionality. But this too will not be enough, since it is necessary to assess the security state of the finished information system with its specific architecture, set of components, business processes, information and, finally, people. Let me give you an example of building a house. We have materials (sand, cement, crushed stone, brick, etc.) and tools (bucket, shovel, trowel, etc.). We will not be able to assess the quality and reliability of the finished house solely by the materials / tools used: how long it will stand, whether it will be cracked, whether it will be cold or quiet. You need to choose a house project, construction technology and a team of craftsmen. And only after the completion of construction, we will be able to measure compliance with the project, GOST, SNiPs, check measurements of thermal protection, noise, loads, analyze the quality of cement and answer most of the questions. But the main question "how long will it stay?" we will not have an exact answer, since we do not know all the operating conditions of the house and all the factors that will affect throughout the entire time.

How to keep Java safe

Take Java for example . It is an object-oriented programming language; Java programs are translated into Java bytecode, which is executed by the Java virtual machine (JVM), a program that processes byte code and passes instructions to hardware as an interpreter. The advantage of this method of executing programs is complete independence of the bytecode from the operating system and hardware, which allows you to run Java applications on any device for which there is a corresponding virtual machine.

« Universal language ”sounds nice, but the most common problem is both back side medals is a memory leak in the JVM leading to memory overflows and crashes. In connection with this problem, vulnerabilities are not excluded, because the basic postulate of reliability is that the simpler the better. In this case, such a complex pie is being assembled from ensuring the compatibility of a large number of platforms and operating systems that it is almost impossible to track and close all vulnerabilities found in them and quickly eliminate them. For the same Microsoft, vulnerabilities can be found and fixed after 4-8 years, and this is if you do not take into account the undeclared features left intentionally or by mistake.

From my practice: when programmers add new functionality that is associated with an already implemented one, or fix old functionality, then in 15% of cases they break a previously working product. And if at the same time they do not carry out full testing, at the output we have a product with new functionality, but with the old partially not working. There are also differences in coding for different platforms, OS versions, software. In this regard, one can imagine how difficult it is to maintain the Java programming language and the JVM, not to mention security issues.

At the moment, Java Development Kit 10 has been released, which offers us standard security mechanisms, released for Java SE 8 and described in the Security Documentation. Nothing new has been added in the tenth version.

Note that Oracle has a Java Security Resource Center. In general, the company divides Java security into four main sections:

A) developers should:

Follow and use everything Latest updates development and security environments;

Use programs for checking the correctness of the code (for example, Checker Framework);

B) system administrators should:

Follow and use all the latest updates for Java and the necessary components for the product to work (including OS, libraries, frameworks, etc.);

Use the Java deployment rules described by and;

Use a reliable timestamp.

C) end users should:

Always use the latest original Java version;

D) security professionals need:

Use advanced management tools and improve security (for example, Advanced Management Console);

Monitor the timely installation of all security updates;

It is important that everyone follows and follows the safety rules and regulations. Achieving a state of security at an adequate level can only be done together and using all available measures (technical, organizational). As my practice shows, in 60% of organizations, IT and information security services are doing well with security, as well as with users who use corporate devices and are connected to single domain... But the most uncontrollable in this area are developers, team leaders, architects.

Software development and security issues

More broadly, the main reasons for security problems in applications during software development are as follows:

A) Lack of understanding of security terminology in general, not to mention specific knowledge and applied solutions.

As a rule, developers associate security at best with the following things: access control and logging and password protection, less often - connection protection at the https level (using encryption mechanisms that are available out of the box by default). That is, formally they will use security methods, which in fact will remain formal, "for show", without taking into account the requirements and nuances:

For passwords: the default values ​​are usually used and are not additionally configured for length, strength, change frequency, non-repeatability, number of attempts. Quite often, these parameters cannot be tweaked, since they were not included in the scope task for software development, which leads to the need to add code.

For managing and logging access: at best, the developers have described the groups or roles of users and access objects that should be available in the software. At worst, the developers themselves "divided" the sections and objects into the ones needed by users and administrators. In the first case, we get a system that can be flexibly configured, but it takes a significant amount of time to configure and negotiate rights. In the second - a formal system of access control. In addition, developers need to understand what kind of information and in what volume need to be logged. However, they are often not provided with this information, which leads to insufficient detail in the logs to analyze incidents or understand what is happening in the software. Or to excessive storage of logs and a large amount of information, which imposes significant restrictions on the ability to store information for a required period of time (for example, one to three years) or there is a need to purchase additional information storages. With redundant recording of information, additional problems arise with the speed of analysis and analysis of incidents and the speed of finding the necessary information. Redundancy may also require additional funding for staff expansion, the purchase of SIEM systems with unique rules for processing information, or it may lead to risks associated with out-of-date information. At the same time, too much time is spent on analyzing and processing information.

Protection of communication channels is no less important, especially for payment and banking systems, where, in addition to disclosing personal and personal data, financial losses are possible. Most often it happens that they don’t think about the protection of channels and information transmission media, and if they do, they use the “default” settings, for example, TLS / SSL. But it also has its own peculiarities in the choice of the protocol version (TLS 1.1, 1.2, 1.3 or SSL v1-3), encryption algorithm (RC4, IDEA, Triple DES, SEED, Camellia or AES), key length. Sometimes, for example, the correct TLS 1.2 protocol is chosen, with AES encryption, a key length of 256 bits, but you forget about the possibility of choosing an address on port 443 for HTTPS and or port 80 for HTTP, instead of blocking port 80, as a result of which it becomes possible to get access through an unsecured channel. Or, for example, they raise the infrastructure on virtual machines and do not think at all about the need to close network access between virtual machines.

B) The second problem is related to the business, as it invests money in specific special functionality that does not take into account security blocks.

Unfortunately, a business does not always understand why it should spend resources on security blocks, if there is no functional benefit from them, the product will not bring more money, but there are only probable risks that may not work. Business more often understands the need to invest in security when an information security incident has already occurred.

Unfortunately, not only business is to blame for this, but also its environment, which:

Also does not understand security;

Spared the budget for information security specialists (they are not hired at all or highly specialized specialists are hired, or one person is hired to be responsible for everything);

I could not reasonably convey the need for security and correctly justify the current risks (reputational, financial, temporary).

C) The problem with communication in the company or lack thereof.

This is the case when the business and its environment understand the need and importance of information security. They allocated budgets, hired appropriate specialists, but there are difficulties in communication between business units and information security / IT services, developers.

D) Lack of awareness of ordinary users of the company in information security issues.

Suppose you have all the necessary departments, specialists, technical and organizational measures. But users resist and do not want to work by the rules. This is a very common situation, and it is also necessary to solve it comprehensively, since people do not understand why they need extra work to comply with information security issues (scan files with antivirus, remember complex passwords, know and comply with policies and business processes, etc.). It is necessary to periodically arrange master classes, to tell at a household level what information security is, what problems and solutions are there, to communicate the global goals and objectives of information security, and to motivate them and their impact on business.

E) Lack of information security architects - information security specialists are not always involved in software development, and programmers themselves think about the security of the architecture and the use of written and ready-made security patterns (Security patterns).

Developers do not know all the nuances and cannot know, since their task is to complete the development and move on to the next one. If you delve deeper into the development itself, the process is much more complicated than it seems. Therefore, it is necessary to clearly get the task from the business, decompose it into understandable mini-tasks for developers, conduct development, conduct alpha and beta tests, load, functional tests, fix errors, return to tests - this process is cyclical and long. Therefore, it is not surprising that they do not have enough resources to think through the safety of the product to the smallest detail.

To talk about security, you need to solve the problems described above. I do not specifically describe the options for solutions, since everything depends on specific problems, environment, conditions. There is no one-size-fits-all pill and every precaution must be taken. The main task is for all employees of the company to penetrate, understand and comply with information security requirements and be interested in observing them. And only then it will be possible to talk about the effectiveness and a good level of maturity of information security in the company.

The developerWorks Java Zone contains hundreds of articles, tutorials, tips, and content from the Java community to help you get the most out of the Java platform and related technologies when developing applications. However, aspiring developers who are just getting started with Java can find it difficult to navigate the sheer volume of resources available on the Internet. Therefore, we have created this page, which provides an overview of the underlying Java technologies in the general context of the capabilities of this language. Find links to resources for further learning Java, such as developerWorks articles for beginners and other educational resources, and links to downloads for IBM products.

Are you an aspiring Java developer? This page provides an overview of the major Java ™ technologies and their place in modern software development. With links to introductory developerWorks articles on this and related topics, other educational materials, and downloads and IBM products, this page is an excellent starting point for learning Java.

What are "Java technologies"?

Java is both a programming language and a platform.

First, Java is a high-level object-oriented programming language... At compilation, which is executed once during the build of the application, the Java code is converted to intermediate language code ( bytecode). In turn, the bytecode is parsed and executed ( interpreted) the Java virtual machine (JVM), which acts as a translator between the Java language and the operating system hardware. All Java implementations must emulate the JVM so that the applications you write can run on any system that includes the Java virtual machine.

Second, Java is software platform, versions of which are supplied for various hardware systems. There are three versions of Java (see the Java Platform Editions section below). The platform includes the JVM and the Java Application Programming Interface (API), which is an extensive set of ready-made software components (classes) that facilitate the development and deployment of applets and applications. The Java API covers many aspects of Java development, including basic object manipulation, network programming, security, XML generation, and Web services. The API is organized as a set of libraries called in packages which contain classes and interfaces for solving related problems.

In addition to the API, every full Java platform implementation must include the following:

  • Developer tools for compiling, running, monitoring, debugging, and documenting applications.
  • Standard mechanisms for deploying applications to a user environment.
  • Toolkits that allow you to create complex graphical user interfaces.
  • Integration libraries for programmatic access to databases and remote object manipulation.

The JVM is also a proven framework for running applications written in languages ​​other than Java. In particular, Groovy, Scala, and specialized implementations of Ruby and Python provide developers with the ability to execute dynamic and functional languages ​​on the JVM (for more information, see What is Java's relation to dynamic languages ​​and functional programming?).

The Java language was developed by Sun Microsystems. Currently, the development of Java technologies, including work on specifications, reference implementations and compatibility tests, is carried out under the control of the open non-profit organization JCP (Java Community Process), which brings together Java developers and licensees. In 2007, Sun released a free version of Java, which includes the core components of the platform, under the GNU GPL v2 (GPLv2) license. You can read more about this version in the Java and Free Software Development section.

Why should you learn Java?

The main advantage of the Java language is the portability of Java applications, i.e. Ability to run on any hardware platform and operating system, since all JVMs, no matter what platform they run on, are capable of executing the same bytecode.

The Java language and platform are extremely scalable. You can easily create apps for devices with limited resources by adapting software originally written for the desktop. However, Java is also ideal for developing server-side Web applications that enable a user to access computing resources on the Web. The ability to safely execute code downloaded over the network was originally built into the Java design, so this language provides high level safety when working over the Internet. Web applications run in runtime environments called Web containers which provide many convenient services, including dispatching requests, security and concurrency, lifecycle management, and access to APIs such as naming, transaction management, and email. A number of are written in Java application servers that act as Web containers for other Java, XML, and Web services components that interact with databases and dynamically render Web page content. These servers also provide an environment for deploying enterprise applications and tools for transaction management, clustering, security, connectivity, and the required levels of availability, performance, and scalability.

By supporting the use of open standards in enterprise applications, Java opens up a wide range of opportunities for XML-based Web services to help business partners exchange information resources and applications. Java is at the heart of many IBM technical consulting products and services (IBM Products and Technologies for Java Developers) and plays a key role in several of the company's core businesses.

  • Explore the IBM approach and learn how SOA can help you create heterogeneous applications with functionality from multiple sources, both inside and outside the enterprise, thereby supporting horizontal business processes. IBM provides a range of business users and IT professionals to help you get started with this technology.
  • is a component-based approach offered by IBM that provides a full range of opportunities for strategic change. The solutions provided are based on flexible, extensible, open standards-based software (including Java) and hardware infrastructure.

Java Platform Editions
There are three editions of the Java platform that allow application developers, service providers, and hardware manufacturers to create solutions that meet the needs of specific user groups.

  • Java SE (Java Platform, Standard Edition)... Using Java SE, you can build and deploy Java applications for desktops and servers, and develop embedded software and programs for real-time systems. The Java SE Edition includes the classes needed to create Web services and the core Java components EE (Java Platform, Enterprise Edition). The current version of the Java SE platform is Java SE 6, also known as "Mustang". However, many developers are still using Java SE 5 (Java 5.0, or "Tiger").
    • For an excellent overview of Java SE 5 features, see the column articles. Most of the programming aspects for the Java SE 5 platform, for which many existing applications have been built, are still relevant to Java SE 6.
    • This article describes the new features in Java SE 6 for monitoring and evaluating application performance.
    • This article provides an introduction to a scripting language that runs on top of the Java SE 6 platform and serves to simplify the programming of complex user interfaces.
    • This two-part series titled provides an introduction to the API provided by Java SE 6 that allows Java applications to execute dynamic scripting code and vice versa. ...
  • Java EE (Java Platform, Enterprise Edition)... This enterprise version of the platform helps developers build and deploy portable, reliable, scalable, and secure server-side Java applications. Building on the capabilities of Java SE, Java EE provides Web services, component models, remoting, and management APIs to implement enterprise software in SOA and Web 2.0.
    • Read articles and for an introductory overview of the capabilities of the latest version of the Java EE platform.
    • Check out the series - a popular framework for building lightweight and reliable Java EE applications.
    • For more information on Java EE, see the articles in the column.
    • The articles in the Getting Started: Migrating to Java Platform series were written specifically for .NET, Windows client / server, and ASP developers to help them migrate to Java.
  • Java ME (Java Platform, Micro Edition)... Java ME provides a runtime environment for applications built for a wide variety of mobile and embedded systems such as mobile phones, PDAs, set-top boxes, and printers. This platform edition provides flexible user interfaces, a robust security model, a full range of built-in network protocols, and powerful support for network and offline dynamically loaded applications. Applications based on the Java ME specifications can run on a variety of devices and still be able to leverage their system capabilities.

What technologies are the main components of the Java platform?

The developerWorks Java zone contains the included Java. Some of the possible components are listed below. additional packages and extensions included in each edition of the platform. Each technology has a short description and a link to resources that describe its place in the Java world. Note that many of the components are included in all three editions of the Java Platform.

Technologies included in Java SE:

  • Java Foundation Classes (Swing)(JFC) is a collection of Java class libraries used to create graphical user interfaces and other graphical functions in Java client applications. Management .
  • JavaHelp is a platform-independent extensible help system that allows developers and technical writers to embed help pages in applets, software components, applications, operating systems, and devices, and create Web help systems. Refer to the article.
  • Thanks to Java Native Interface(JNI) Java applications running inside the JVM can interact with programs and libraries written in other programming languages.
  • Technology Java Web Start Simplifies the deployment of Java applications by allowing users to download and run rich software, such as spreadsheets, with the click of a mouse button, without installation (see article).
  • Java Database Connectivity(JDBC) is an API that provides the means to access most relational data sources from Java applications. It can connect to many SQL databases as well as other tabular data sources such as spreadsheets and flat files.
  • Java Advanced Imaging(JAI) is an object-oriented API that provides a simple, high-level programming model to simplify image manipulation.
  • Java Authentication and Authorization Service(JAAS) is a technology that provides services with a means to authenticate users and verify their access rights. It includes a Java implementation of the standard PAM (Pluggable Authentication Module) framework and supports user-level authorization.
  • Java Cryptography Extension(JCE) is a set of packages that provide infrastructure and implementations for encryption, key generation and exchange, and Message Authentication Code (MAC) algorithms. This technology also includes support for symmetric, asymmetric, block and stream ciphers, as well as stream-safe and sealed objects. More details can be found in the manual.
  • Java Data Objects(JDO) is a standard abstract persistence model for Java objects based on interfaces. With its help, developers can directly save instances of Java classes. subject area in persistent storage (such as a database). In some cases, this model can replace direct writing to a file, serialization, JDBC, as well as the use of server-side EJB components, both managed by containers (Container Managed Persistence - CMP) and independently storing state (Bean Managed Persistence - BMP).
  • Package Java Management Extensions(JMX) provides tools for building distributed, modular, dynamic and Web-accessible applications for managing and monitoring devices, software, and networks based on service delivery (see article).
  • Java Media Framework(JMF) allows you to add audio, video, and other media information to Java applications and applets (see manual).
  • Java Naming and Directory Interface(JNDI) is a unified interface for accessing various services names and directories on the corporate network. It enables applications to efficiently connect to a variety of naming and directory services in a heterogeneous enterprise environment.
  • Java Secure Socket Extensions(JSSE) is a collection of packages for the secure exchange of information on the Internet. They implement Java version SSL protocols(Secure Sockets Layer) and TLS (Transport Layer Security) and provide tools for data encryption, message integrity checking, server and client authentication (the latter is optional).
  • Java Speech API (JSAPI) includes the JSGF (Java Speech Grammar Format) and JSML (Java Speech Markup Language) specifications. This package provides capabilities for using speech technologies in the user interface. JSAPI is a cross-platform API to support recognition voice commands, systems of speech data input and speech synthesis. For more information refer to next section articles .
  • Java 3D is an API that provides cross-platform and scalable capabilities for working with 3D graphics in Java applications. The API is organized as a set of object-oriented interfaces that fold into a single, simple, high-level programming model.
  • Mechanism Metadata Facility Allows developers to define attributes for classes, interfaces, fields, and methods so that they can undergo special handling by development tools, deployment tools, and third-party libraries at runtime (see article).
  • Java Content Repository API is an API for accessing content repositories in Java SE, regardless of their implementation. Such repositories are high-level information management systems and are extended versions of the classic data repositories.
  • Enumerations(enumeration) is a data type that allows you to describe various data items as a typed set of constants.
  • Generics(generic types) allow you to create classes with parameters (abstract types) that are specified at the stage of instantiation. See the article for details, and also check out the article on how generic types make it easier to work with collections in Java SE 6.0.
  • Utilities Concurrency is a set of classes that provide the middle-tier functionality typically required by parallel processing applications.
  • Java API for XML Processing(JAXP) is an API that Java applications can use to parse and transform XML documents, regardless of the XML processor used. This allows applications to easily switch between different processors without changing the application code. In turn, the JAXB technology ( Java API for XML Binding) provides capabilities to automate matching XML documents and Java objects.
  • SOAP with Attachments API for Java(SAAJ) provides developers with functions for generating and processing messages in accordance with the SOAP 1.1 specification, specifying SOAP with Attachments. See article for more details).

J2EE technologies:

  • Enterprise JavaBeans(EJB) is a component model that simplifies middleware development by providing services such as transaction management, security, and database connectivity.
  • Portlet specification defines a set of APIs for building portals in Java, covering aspects such as aggregation and presentation of information, personalization, and security (see article).
  • JavaMail is an API that provides a set of abstract classes that model the mail system.
  • Java Message Service(JMS) is an API that supports the creation of portable Java messaging applications. He defines general set basic programming concepts and strategies for all JMS-compliant messaging systems.
  • JavaServer Faces(JSF) provides a programming model that helps you build Web applications by assembling pages from reusable user interface components, binding those components to data sources, and client-generated events to server handlers. For more information, see the two-part tutorial and column series article series.
  • JavaServer Pages(JSP) provides a means for Web developers to quick creation and simple support for dynamic, cross-platform Web pages that separate user interface and content generation so that designers can change markup without touching dynamically generated content (see tutorial.
  • Standard Tag Library for JavaServer Pages(JSTL) is a collection of specialized tags that provide a standard format for performing the actions required by many Web applications. Check out Refresh Your JSP Pages with JSTL and the four-part series titled.
  • Java Servlets extend the functionality of Web servers by providing a cross-platform, component-based approach to building Web applications that is free from the performance limitations of CGI.
  • J2EE Connector Architecture(JCA) provides a standard architecture for connecting J2EE applications to heterogeneous enterprise information systems (EIS). This architecture defines a set of scalable and secure transaction-based mechanisms by which EIS vendors can provide standard resource adapters for inclusion in an application server. For more information, see the articles, and the manual.
  • J2EE Management Specification(JMX) defines a management information model for the J2EE platform. This model has been specially designed to interoperate with many systems and control protocols. It contains standard tools for mapping to the Common Information Model (CIM), SNMP Management Information Base (MIB), and Java object model using the J2EE Management EJB Component (MEJB) resident server EJB.
  • Java Transaction API(JTA) is a high-level implementation and protocol independent API that provides programs and application servers with the means to access transactions. Java Transaction Service(JTS) defines an implementation of a transaction manager that supports JTA and implements, at an underlying level, mapping to the Object Transaction Service (OTS 1.1) of the OMG. Transaction propagation in JTS is implemented using the Inter-ORB protocol (IIOP). See the article for more details.

Technologies that are part of J2ME:

  • Mobile Information Device Profile(MIDP) is one of two configurations that make up the Java runtime environment for resource-constrained mobile devices. MIDP provides applications with basic functionality, including tools for creating user interfaces, connecting to network resources, local storage and management life cycle.
  • Connected Device Configuration(CDC) is a standardized infrastructure for building and deploying applications that can be accessed from many networked and embedded devices.
  • Mobile 3D Graphics API for J2ME(M3G) is a lightweight interactive 3D API that is an add-on to J2ME. You can read more about him in the two-part series.

Java Technologies and Web Application Development

Java has been the primary language for developing Web applications for many years. In recent years, many frameworks and libraries have emerged to facilitate the creation of Java Web applications, including rich interactive Web 2.0 applications.

Check out the following resources for Java Web Development.

  • This column introduces Grails, a modern framework for building Web applications written in Groovy. Grails allows you to seamlessly combine previously written Java code with the ability to use a flexible and dynamic scripting language. For more information on Groovy, see What is Java's relationship to dynamic languages ​​and functional programming below ?.
  • Ajax is a programming methodology that uses client-side scripting languages ​​to communicate with a Web server, allowing you to quickly update information on pages without the need for them. full reboot... In this series of articles and, you will learn how Ajax can help you as a Java developer. Check out developerWorks for more information.
  • JavaServer Faces (JSF) provides a programming model to help build Web applications by assembling pages from reusable components user interface and bind these components to data sources, and client-generated events to server handlers. For more information, see the two-part tutorial and column series article series.
  • The Eclipse Web Tools Platform (WTP) extends the popular framework Eclipse development by adding tools for building Web applications based on Java EE technologies (see tutorial).
  • Check out developerWorks for many other excellent materials on these topics.

Java Technologies, SOA and Web Services

Service Oriented Architecture (SOA) is a component model that links functional modules of an application (known as Services where the term came from Web services) through strictly described interfaces and contracts. Interface definitions are independent of the hardware, operating system, and programming language in which the service is implemented, thereby maintaining a unified interaction between services that are components of different systems. SOA is an example of a loosely coupled programming model that provides an alternative to the classic tightly coupled object-oriented models.

Created on this principle, Web services allow you to describe business rules and processes in XML, so that the interaction of applications can be carried out regardless of the platforms and programming languages ​​used. XML technologies promote data portability and simplify message creation, while Java technologies enable you to write portable code. XML and Java work well together, making them the perfect combination of technologies for building and deploying Web services.

For more information, read the following materials:

  • DeveloperWorks pages and pages can help you navigate these challenging technologies.
  • In this series, you will learn about Java Web services infrastructures and the new functional layers built on top of those services.
  • This article provides an introduction to an elegant Web services design style called Representational State Transfer (REST) ​​and explains how to use Java to create RESTful Web services.
  • Understanding JAX-RPC (Java API-based RPC for Working with XML) technology is essential for creating efficient Java Web services.
  • JAX-WS is the obvious next step in the evolution of JAX-RPC. A practical introduction to this new API is given in the tutorial.
  • This series is a guide to Service Component Architecture (SCA), a specification that describes an SOA model for developing applications and systems.
  • This article provides an introduction to the Service Data Objects infrastructure (objects these services), which simplifies the Java EE data model for building SOA applications.

What does Java have to do with dynamic languages ​​and functional programming?

Many developers who are getting started with Java have extensive experience with other programming languages. At the same time, even the most venerable programmers admit that Java is not the ideal language for solving of all problems encountered in practice. Fortunately, with JVM support, you can take full advantage of today's dynamic scripting and functional languages ​​when developing applications for the Java platform. The flexibility and dynamism of these languages ​​prove to be very useful when prototyping and implementing certain types of applications.

You can read more about the possibilities of using dynamic and functional languages ​​in the Java platform in the materials, links to which are given below.

  • The Groovy scripting language allows Java developers to use their most familiar language constructs and libraries while providing a flexible, dynamic development environment that does not require compilation, simplifies syntax, and supports scripting within common Java applications. A detailed overview of the capabilities of this language is given in the articles in the series.
  • The new scripting API in Java SE 6, which is backward compatible with Java SE 5 and contains a small set of interfaces and classes, provides an easy way to invoke scripts written in dozens of languages ​​from Java code. With it, you can load and call external scripts at runtime, dynamically changing the behavior of your application. You can read more about this API in the two-part series titled.
  • Are you an ardent supporter of functional programming? Then you should pay attention to the column that talks about Scala, a programming language for the JVM that combines a functional and object-oriented approach to development.
  • VMs have supported alternative programming languages ​​for a long time. In the column articles, you can read about JVM implementations of languages ​​such as Rexx, Ruby, JavaScript, Python, and some others.

Java and Free Software Development

There are countless ways to build Java libraries, toolkits, frameworks, programs, and application servers that open up additional opportunities for developers to leverage this powerful platform. A number of free technologies have been incorporated over time into the Java platform, while others have remained popular with Java developers over the years, in some cases acting as de facto standards.

  • The Apache Software Foundation (EN) brings together many open source projects, most of which are developed with Java technology. Some of the members of this family of projects are listed below.
    • Apache Struts is a framework for building Web applications that follow the Model-View-Controller architecture.
    • Apache Shale is another modern framework for building Web applications that inherits from Struts and is based on JSP (JavaServer Pages) technology. For an introduction to Shale, see the articles in the series.
    • Apache Ant is the de facto standard for automating the build process of Java applications.
    • The Apache Maven Build Tool was designed with the requirements of modern software projects in mind, with dynamic interactions between development teams and reliance on many independently supported components (see guide).
    • Apache Tomcat is a popular Web container that supports servlets and Java server pages (JSPs).
    • The Apache Geronimo project is about creating a fully spec-compliant Java EE application server based on purely free technology. You can read more about Geronimo in this article and on the developerWorks site for a wealth of helpful content.
    • Apache Derby is a relational database server fully implemented in Java. An introduction to Derby is provided in the article.
  • Eclipse (EN) is an open and independent development platform and a set of basic tools for building software. It is written in Java and provides a plug-in infrastructure to facilitate development, integration, and use of software tools. IBM is a founding member of Eclipse.org and actively participates on the project's governing board and subcommittees. You can read about some of the component technologies of the Eclipse platform aimed at creating Java applications in the following materials:
    • AspectJ is an aspect-oriented extension to the Java language that can be used to modularly implement cross-cutting functionality such as logging or exception handling.
    • The Standard Widget Toolkit (EN) (SWT) is a toolkit that allows you to leverage the power of the operating system to create user interface elements in an efficient and portable manner.
    • Mylyn is a powerful job management system for Eclipse users. For detailed guidance, see the articles and, formerly known as "Acegi Security for Spring", is a powerful and flexible security solution for enterprise applications built on top of the Spring framework. It is covered in detail in four articles in the series.
  • Sun Microsystems has also launched the following community projects at java.net:
    • Openjdk

How to develop Java programming skills?

There are two main ways you can develop your Java programming skills: take a dedicated training course (with certification options), or learn Java on your own by practicing coding. Training courses not only allow you to learn from the experience of qualified developers, but also provide the opportunity to obtain a certification that can convince a potential employer that you have the skills necessary to meet the technical challenges facing us. In doing so, you can deepen your knowledge in various areas of Java, experimenting on your own and using all the resources available. Whichever path you choose, the following resources will help you.

  • Guides and Articles
    • DeveloperWorks has an extensive collection that is second only to coding yourself in terms of usefulness in learning Java.
    • The articles are series and are great for improving your Java language skills.
    • The use of design theory to create real-world applications is discussed in the articles in the series.
    • Experienced Java developers pre-build tools in their applications to debug and test them. DeveloperWorks has several articles in the series - Eclipse-based real-time games for learning Java programming. Introductory information For more information on CodeRuler, see Conquering Medieval Kingdoms with CodeRuler.
  • IBM technical training courses
    • Enjoy a wide variety of Java courses online, face-to-face and multimedia from IBM Global Services.
  • Certification
    • You can take several exams to earn certifications that demonstrate your Java programming skills. For certification courses, see the Java Certification website.
    • IBM empowers your skills in Java-related technologies such as building enterprise applications for WebSphere, Rational software, DB2, XML, and SOA.
  • Forums
    • Moderated by experts with years of Java technology experience, this is the most interactive way to learn the Java language.

IBM products and technologies for Java developers

IBM is one of the leaders in the practical application of Java technologies. The following are links to some of the IBM products and technologies available to developers for the Java platform.

  • Free downloadable products:
    • (Java Developer Kit) is a collection of tools for building and testing applets and applications for Java SE and Java ME on a variety of popular operating systems, including Windows, Linux, and AIX.
    • (IBM Development Package for Eclipse) is an Eclipse-based unsupported developer toolkit that allows you to build and run applications in your own off-the-shelf development environment.
    • : You can download free Eclipse software packages from developerWorks, including the parallel products Calisto and Europa.
    • is a virtual repository of promising Java technologies being developed at IBM. These include APIs, IDEs, development kits, reference implementations, and utilities. Below are links to some of the technologies featured in alphaWorks.
    • ... This utility helps you parse and generate testable Ant scripts for building projects developed with Eclipse, Rational, and WebSphere IDE for the Java EE and SCA platforms.
    • (IBM Pattern Modeling and Analysis Tool for Java Garbage Collector). This utility parses detailed GC trace files, analyzes heap (heap) memory usage, and recommends application tuning based on the memory simulation results. (Secure Shell Library for Java) is a lightweight implementation of the SSH-2 protocol developed by the Internet Engineering Task Force (IETF). It provides secure authentication tools and other secure services that operate over an unsecured network. allows you to consolidate and transform data, thereby increasing the productivity, flexibility and productivity of your business by providing quick access to the information you need.

In this guide, we'll cover everything you need to know before you start learning programming on Java. You will learn about the platform's capabilities, its uses, and how to get started learning Java right.

What is the Java Programming Language?

In 1991, the Green Team, a division of Sun Microsystems, led by James Gosling, created a language for programming consumer electronic devices. At that time it was called Oak ("Oak"). Why "Oak"? Simply because this tree grew outside the window of Gosling's study.

The Green Team demonstrated the use of Oak on an interactive TV. But for digital cable television of those years, this technology was too advanced. At the same time, the Internet was gaining popularity, for which the new programming language was best suited.

After a while, the new language was renamed Green, and after that - in Java, in honor of coffee from the island of Java. Therefore, the Java logo depicts a coffee mug.

During the development of Java, C / C ++ was popular, so Gosling made the syntax of the language similar to C / C ++ and implemented the principle “ write once - run anywhere". In 1995, Sun Microsystems released the first official version Java. And at the same time, it was announced that Java will be included in the Netscape Navigator browser.

In 2010, Sun Microsystems, along with the Java programming language, was acquired by Oracle Corporation.

Java version history

  1. June 1991 - start of the development project programming language Java.
  2. JDK 1.0 - January 1996.
  3. JDK 1.1 - February 1997.
  4. J2SE 1.2 - December 1998.
  5. J2SE 1.3 - May 2000.
  6. J2SE 1.4 - February 2002.
  7. J2SE 5.0 - September 2004.
  8. Java SE 6 - December 2006.
  9. Java SE 7 - July 2011.
  10. Java SE 8 - March 18, 2014.
  11. Java SE 9 - September 21, 2017.

Functions of the Java programming language

Java is a cross-platform language

Java code written on one platform ( that is, the operating system) can be run unchanged on other platforms.

To run Java, the Java virtual machine ( Java Virtual Machine, JVM). The JVM processes the byte code, and then the processor processes the code received from the JVM. All virtual machines work in a similar way, so the same code works the same on all operating systems, which makes Java a cross-platform programming language.

Object Oriented Programming Language

There are various styles of programming, and one of the most popular is object-oriented programming. With this approach, a complex problem is broken down into smaller ones by creating objects. This makes the code reusable.

Object-oriented functions are found in many programming languages, including Java, Python, and C ++. If you are serious about learning programming, the object-oriented approach is worth incorporating into your curriculum.

Java is fast

Early versions programming language Java has often been criticized for slow work... But today the situation has changed dramatically. Newer versions of JVMs run much faster, and processors that interpret them are becoming faster and faster.

Java is one of the fastest programming languages ​​today. Well-optimized Java code runs almost as fast as low-level programming languages ​​like C / C ++ and much faster than Python, PHP, etc.

Java is a secure platform

Java is:

  • a secure platform for developing and launching applications;
  • provides tools for automatic memory management, which reduces the vulnerability of the code;
  • ensures secure data transmission.

Extensive core library

One of the reasons Java is widely used is the huge standard library. It contains hundreds of classes and methods from various packages to make life easier for developers. For example,

java.lang are advanced functions for strings, arrays, etc.

java.util is a library for working with data structures, regular expressions, date and time, etc.

kava.io is a library for file input / output, exception handling, etc.

Using the Java Platform

Before learning Java programming from scratch, you need to know that more than 3 billion devices around the world are running on this platform. What exactly can you use it for:

  1. Android Applications - For developing Android applications, the Java programming language is often used in conjunction with the Android SDK ( from english software development kit - software development kit).
  2. Web Applications - Java is used to build web applications using server side programs, Struts framework and JSP. Some popular web applications written in Java include Google.com, Facebook.com, eBay.com, LinkedIn.com.

It is worth noting that these sites are not necessarily written exclusively in Java, and may use other programming languages ​​as well.

  1. Software development- programs such as Eclipse, OpenOffice, Vuze, MATLAB and many others are written in Java.
  2. Big Data Processing - For processing big data, you can use the Hadoop framework written in Java.
  3. Trading systems- using the platform Oracle Extreme Java Trading Platform, you can write programs for trading.
  4. Embedded devices- Billions of devices are powered by Oracle's Java Embedded technology today, such as TVs, SIM cards, Blu-ray players, and more.

Also programming on Java is used to develop games, scientific applications ( for example, for natural language processing) and in many other areas.

Java Terminology You Should Know

Java is a collection of technologies ( programming language and computer platform) designed to create and run software. but Java term often denote the programming language itself.

Programming language Java is a broad-based, general-purpose, cross-platform, object-oriented programming language.

Java 9 is the latest version of Java at the time of this writing.

Java EE, Java Me, and Java SE — These names refer to Java Enterprise Edition, Micro Edition, and Standard Edition, respectively.

Java EE targets applications that run on servers. Java ME is designed for power-constrained devices such as embedded devices. Java SE is the Java standard edition for writing regular programs.

If you are new to Java programming, we recommend starting with Java SE.

JVM - Java Virtual Machine (" Java virtual machine") Is a program that allows a computer to run programs written in Java.

JRE - Java Runtime Environment (" java runtime") Includes the JVM, corresponding libraries and other components required to run programs. But there is no compiler, debugger, or other development tools in the JRE.

JDK - Java Development Kit (kit Java developer) contains the JRE and other development tools like compilers, debuggers, etc.

How to run Java on your operating system

How to run Java on Mac OS

Here's what to do for Java programming from scratch and platform installations on Mac OS X or macOS:

  1. Download the latest Java version ( JDK) with Java SE download pages.
  2. Double click on the downloaded DMG file and follow the instructions of the installer.
  3. To verify the installation, open a terminal and enter the following command:

javac –version

If Java is installed correctly, the program version will be displayed ( for example javac 1.8.0_60).

The next step is to install the IDE ( integrated development environment) to write and run Java code. We will install the free version IntelliJ IDEA and run Java on it. Here's what you need to do for this:

  1. Go to IntelliJ download page and download the free Community Edition.
  1. Open the downloaded DMG file and follow the installation instructions. For quick access you can move IntelliJ IDEA to the Applications folder.
  2. Open IntelliJ IDEA. Select the option “Don’t import settings” (“ Don't import settings") And click" Ok ". Then accept the Jetbrains privacy policy by clicking on the "Accept" button.
  3. Now you can customize the interface for yourself. You can also skip this step and leave everything as default. If unsure, just skip this step by clicking the Skip All and Set Defaults button. Skip everything and set default settings»).


  1. The program will show you a welcome page. Click on the "Create New Project" button Create a new project»).
  2. In the next window, select "Java" in the left pane and click "New" at the top of the program window to select "JDK". Here you need to select the location where you installed the JDK, and then click Next.


  1. You will have the option to create a project from template ("Create project from template"). Ignore it and click the Next button.
  2. In the next step of the installation programming language Java enter a name for the project and click Finish.
  3. In the left pane, you will see your project. If the panel is not visible, go to the menu Views> Tool Windows> Project.
  4. Go to Hello> New> Java and set the class name. We named it First.


  1. To run the program you just wrote, go to Run> Run ... Click on First ( that is, the name of the file we created


How to run Java on Linux

To run examples from programming lessons from scratch Java on Linux will need JAVA SE Development Kit ( JDK) and IDE to develop your projects. Follow the instructions step by step to get started with Java.

Install Java

  1. Open a terminal and type the following command to install Java:

    sudo add-apt-repository ppa: webupd8team / java


    sudo apt update; sudo apt install oracle-java8-installer

  1. Accept the license agreement and terms of use by clicking "OK" and "Yes", respectively.
  2. You have installed Java. To check that the installation was successful, enter the following command in a terminal:

java –version

If the current version is displayed, the installation was successful. If not, check with Oracle help page.

Installing IntelliJ IDEA

  1. Go to.


  1. Download the free Community Edition by clicking the Download button.
  2. After downloading change the directory in the terminal to the download directory and extract the Java tar file to the / opt folder with the following command:

sudo tar xf .tar.gz -C / opt /

  1. After unpacking, change the directory to the bin folder of the IntelliJ IDEA program:

    cd / opt / / bin

  2. To start the IDE, enter the following command:
  3. We select "Don’t import settings" (" Don't import settings") And click" OK ". After that, we accept the Jetbrains privacy policy by clicking on the "Accept" button.
  4. Now for passing programming courses Java, you can customize the interface for yourself. Create a desktop shortcut for quick access to the program. After that, to launch the IDE, click "Next" in all the following steps.
  5. The program will show a welcome page. Click "Create New Project" Create a new project»).
  6. In the next window, select Java in the left pane and make sure Java is selected in the Project SDK row. If not, then select the location where you installed JDK: / usr / lib / jvm / java-8-oracle.


  1. Press "Next" twice and create a project.
  2. In the next step, enter a name for the project and click Finish. You will now see your project in the left pane. If this panel is not visible, go to the menu Views> Tool Windows> Project.
  3. Add new class Java. Select src in the left pane with the right click and go to New> Java Class. Set the class name. There must be no spaces in the class name.


  1. Write Java code and save the project.
  2. To run the program, go to Run> Run ... Click on HelloWorld ( Project name) - the program will compile the file and run it.


How to run Java on Windows (XP, 7, 8 & 10)

For mastering Java fundamentals of programming and running the platform on Windows will require a JAVA SE Development Kit (JDK) and IDE to develop projects. Follow the step by step instructions below:

Installing Java

  • Go to download page Java Standard Edition Development Kit.
  1. In the Java SE Development Kit section at the top of the table, click Accept License agreement ( Accept license agreement"). Then click on the Windows (x64) link for a 64-bit operating system or Windows (x86) for a 32-bit operating system.

  1. After downloading, run the installation file and follow the instructions that appear on the screen. Click " Next". Select all functions by clicking " This feature will be installed on local hard drive"And copy the installation location ( it is highlighted in yellow) in "Notepad", and then click " Next».


  1. During the installation process, you will be prompted to install the JRE. Click Next and then Finish to complete the installation.
  2. Now you need to edit the PATH variable. Go to Control Panel> System and Security> System... In the left pane, select " Extra options systems ".

  1. Click " Environment Variables"... In chapter " System Variables " find the PATH variable and in the next window click "Edit".

  1. Select all the text in the " Variable value " and copy it into a separate text file. This will make it easier to edit and check for errors. See if the copied text contains the line: C: ProgramData Oracle Java javapath; ... If so, you can proceed to the next step. If not, then paste the previously copied installation location at the beginning of the variable and add bin at the end of the line like this: C: Program Files (x 86) Java jdk 1.8.0_112 bin; Please note that your JDK version (jdk 1.8.0_112) may be different. Copy the value of the variable and paste it into the PATH window.


  1. Click " OK"To save your changes.
  2. To check if the platform is installed correctly for introduction to programming Java, open command line by typing cmd in the Windows search bar or through the "Run ..." command ( Windows - R). Enter the java -version command. If the current Java version is displayed, the installation was successful. If not, check with Oracle help page.

Installing IntelliJ IDEA

  1. Go to IntelliJ IDEA download page.
  2. Download the free Community Edition by clicking Download.


  1. Once downloaded, run the setup file and follow the instructions that appear on the screen. Then create a desktop shortcut for 64-bit and add associations with the .java extension. Click "Next" and proceed with the installation.


  1. Once installed, open IntelliJ IDEA by clicking on the icon on your desktop.
  2. Select “Don’t import settings” (“ Don't import settings") And click" OK ". After that we accept Jetbrains' privacy policy by clicking "Accept".
  3. Now you can customize the interface for yourself. You can also skip this step and leave everything as default by clicking the Skip All and Set Defaults button.
  4. The program will show a welcome page. Click "Create New Project" Create a new project»).


  1. In the next window, select "Java" in the left pane and click "New" at the top of the program window to select the JDK. Here you need to select the location where the JDK was installed during the Java installation, and then click "Next".
  2. IntelliJ IDEA will find the JDK and recognize it. You don't need to check any other options, just click Next.
  3. On the next screen, enter a name for the project: HelloWorld and click Finish. If the program says that the directory does not exist, click "OK". If you don't see the left pane, go to Views> Tool Windows> Project.
  4. To set the class name, select the src folder in the left pane. Right click on it, go to New> Java and give the class a name. There must be no spaces in the class name.


  1. Write the code and save the Java project programming lesson.
  2. To run the program, go to Run> Run ... Click on HelloWorld - the program will compile the file and run it.


Your first Java program

To introduce users to the new programming language, use the Hello World program. This is a simple program that prints the words Hello, World! In this section, we will teach you how to write this Java program using IntelliJ IDEA.

  1. Open IntelliJ IDEA.
  2. Go to File> New> Project ...> Java ( in the left navigation bar).
  3. Set the Project Name from programming course J a va. We'll name it Hello World and click Finish.
  4. Now we need to create a new Java class.
  5. Select the src folder in the left pane, then go to File> New> Java Class and name the new class HelloWorld.
  6. Copy the following code to HelloWorld.java and save it.

public class HelloWorld (public static void main (String args) (


// prints "Hello, World!"


System.out.println ("Hello, World!");

  1. Click the start button ( Run). If everything is in order, you will see the inscription Hello, World!

How do I learn Java?

Java Official Documentation

Oracle, the company that owns Java, publishes quality tutorials. The official documentation covers all Java features and is updated regularly.

Note: the only negative is that the official Java documentation is not always written in the simplest language.

If you really want to learn programming on Java, buy a good book. Of course, 1000 pages cannot be read in one day. But a good tutorial will help you learn programming.

Java: The Complete Guide (10th Edition)

An excellent book for those who are just starting to learn Java. The latest edition includes all the features of the Java 8 release.

The book covers everything there is to know about Java programming, including syntax, keywords, and fundamental programming fundamentals, as well as the Java API library, Java applets, and more.

The Java Philosophy (4th Edition)

If you are switching to Java from another programming language, this book is for you. If you are starting from scratch, it is best to read it in conjunction with another.

Java 8. Pocket Reference: First Aid for Java Programmers

This book provides clear answers to the questions that arise when teaching J ava programming from scratch... She briefly introduces all the basic concepts of Java (including Java 9). Don't want to flip through hundreds of pages looking for the right line? Buy this book.

Instead of a conclusion

If you start learning Java, you won't be mistaken - it is a promising programming language full of a wide variety of possibilities.

Before you start learning Java, here are a few tips:

  • Don't read tutorial articles and examples like a novel. The only way to become a good programmer is to write a lot of code.
  • If you are migrating from another programming language (say, C #), you do not need to write C #-style code.
  • Find online Java communities. When will you learn to write simple programs in Java, find popular Java sites and forums. Try to solve problems other programmers have. This is a great way to expand your own knowledge. Plus, if you run into trouble, you'll know where to ask for help.

We hope this article will push you towards learning Java and help you get started on your first programs.

Translation of the article “ Learn Java Programming. The Definitive Guide”Was prepared by the friendly project team

We will talk about basic Java syntax for beginners. The syntax of a programming language is a set of rules that govern how it is written and interpreted ...

Java language. Introduction.

For a long time, it was difficult to imagine a computer magazine without an article on the Java language. Even such popular newspapers and magazines as The New York Times, The Washington Post and Business Week wrote about him.

It is impossible to remember that the national public radio (National Public Radio) ever devoted a ten-minute transmission to a programming language. Good or bad depends on the point of view. And the investment of $ 100 million in the production of software created using a specific programming language ?! The television companies CNN, CNBC and other media only talked, and are still talking, about how the Java language can and will do it.

However, this book is for serious programmers, and since Java is a serious programming language, we have a lot to talk about. So, we will not dive into the analysis of advertising promises and try to find out what is true and what is fiction in them. Instead, we will describe Java as a programming language in sufficient detail (including, of course, the features that allow it to be used for working on the Internet, which, in fact, caused so much advertising hype). After that, we will try to separate reality from fantasy by explaining what the Java language can and cannot do.

At first, there was a chasm between the advertising promises and the real possibilities of the Java language. As it matured, the technology became more stable and reliable, and expectations dropped to a reasonable level. Java is now increasingly being used to create "middleware" that maintains communication between clients and server resources (such as databases).

While these important applications are not overwhelming, it is in this area that the Java language has proven itself most useful due to its machine independence, multithreading, and network programming capabilities. In addition, Java took the lead in embedded systems, becoming the de facto standard for portable devices, virtual kiosks, on-board car computers, and the like. However, the first attempts to rewrite widely used programs in Java for personal computers were not crowned with success - the resulting applications turned out to be low-power and slow. With the advent of the new version, some of these problems were solved, and yet it must be admitted that users, in general, are completely indifferent to the language in which the programs they purchased are written. We believe that the main benefits of the Java language will come from creating new kinds of devices and applications, rather than rewriting existing programs.

The Java language as a programming tool

How the Java programming language exceeded its advertising promises. It is undoubtedly one of the best languages ​​available to serious programmers. Java has the potential to be a great programming language, but it's probably too late now. When a new programming language appears, immediately there is unpleasant problem its compatibility with previously created software. Moreover, even if changes to these programs can be made without interfering with their text, it is difficult for the creators of a language that was so warmly welcomed by the public, such as Java, to say directly: “Yes, we may have made a mistake in developing version X, but version Y will be better. " As a result, while awaiting further improvements, we must state that the structure of the Java language will not change significantly in the near future.

The obvious question is: " How did you improve the Java language?"It turns out that this was done not by improving the programming language itself, but by radically changing the libraries of programs written in the Java language. Sun Microsystems has changed everything: starting with the names of individual library functions (making them more meaningful) and the methods of working of graphical modules ( changing the way we handle events and partially rewriting the work programs), and ending with the creation of new language features, for example, printing tools that were not available in Java 1.0. The result was a much more useful software platform than anything previous versions Java language.

Microsoft has released its own product called J ++, which is related to the Java language. J ++ is interpreted by a Java Virtual Machine (Java Virtual Machine) when executing bytecode, but the languages ​​have different interfaces to external codes. The J ++ and Java languages ​​have almost the same syntax. However, Microsoft has created additional language constructs. All of them are of rather dubious value, with the exception of Windows interface API. In addition to the fact that these languages ​​have the same syntax, their core libraries (strings, utilities, network programming tools, multithreading tools, math libraries, etc.) are essentially the same.

However, graphical libraries, user interface and access to remote objects these languages ​​are completely different. Microsoft currently no longer supports J ++, having developed a new language, C #, which has much in common with Java, but uses a different virtual machine. This book does not describe J ++ or C #.

Java language advantages

1) One of the main advantages of the Java language is independence from the platform on which the programs are run: The same code can be run under Windows, Solaris, Linux, Machintosh, and more.
This is really necessary when programs are downloaded over the Internet for later execution under different operating systems.

2) Another advantage is that the syntax of the Java language is similar to the syntax of the C ++ language, and for programmers, fluent in languages C and C ++, learning it is easy... True, for programmers who know the Visual Basic language, this syntax may be unusual.

If you have never programmed in C ++, some of the terms used in this section may not be clear to you. In this case, you can skip it. By the time you get to the end of Chapter 6, these terms will become familiar to you.

3) Also, Java - completely object-oriented language, even more so than C ++... All entities in Java are objects, with the exception of a few primitive types, such as numbers. (Because it is easy to develop complex projects with object-oriented programming, it replaces the older structured programming. If you are not familiar with object-oriented programming, chapters 3-6 will give you everything. necessary information about him.)

However, it is not enough to develop another, slightly improved, dialect of the C ++ language. It is fundamentally important that it is easier to develop error-free programs in Java than in C ++. Why? The Java developers have pondered for a long time why programs written in C ++ are so error-prone. They provided the Java language with the means to eliminate the very possibility of creating programs that would hide the most common errors. To do this, the Java language has done the following.

4) The possibility of explicit allocation and freeing of memory has been excluded.
Java memory is automatically reclaimed by garbage collection. The programmer is guaranteed against errors related to misuse of memory.

5) Introduced true arrays and disallowed pointer arithmetic.
Now programmers, in principle, cannot erase data from memory due to improper use of pointers.

6) The possibility of confusing the assignment operator with the equality comparison operator has been eliminated.
Now you can't even compile the if (ntries = 3) expression. ... ... (programmers on Visual language Basic may not notice any problem here at all, since this error is the source of most of the misunderstandings in C and C ++).

7) Multiple inheritance is excluded. It has been replaced by a new concept - an interface borrowed from the Objective C language.
The interface gives the programmer almost everything that the programmer can get from multiple inheritance, while avoiding the complexity of managing class hierarchies.

Characteristics of the Java language

Simple
Interpreted
Distributed
Reliable
Safe
Machine independent
Object oriented
High performance
Multithreaded
Dynamic
Computer architecture independent

We have already touched on some of these points in the last section. In this section, we will: provide quotes from the Java language manual that reveal the features of the language; Let us share with the readers our thoughts on certain properties of the language, based on our own experience of working with its latest version.

Simple

We wanted to create a system that is easy to program, does not require additional training and takes into account the established practice and programming standards. Therefore, although we considered the C ++ language unsuitable for these purposes, the Java language was designed to be as similar to it as possible in order to make the system more accessible. The Java language lacks many of the rarely used, obscure, and obscure C ++ features that, in our opinion, do more harm than good.

The Java syntax is essentially a cleansed version of the C ++ syntax. This language has no header files, pointer arithmetic (and pointers themselves), structures, unions, operator overloading, virtual base classes, etc. (The differences between Java and C ++ are described in the C ++ notes scattered throughout the book.) However, the developers did not seek to correct all the shortcomings of the C ++ language.

For example, the syntax of the switch statement in the Java language has remained unchanged. Knowing the C ++ language, it will be easy to move to the syntax of the Java language.
If you usually use a visual programming environment (such as Visual Basic), the Java language will seem complicated to you.
Its syntax often looks rather strange (although it is not difficult to understand the meaning of the expression). More importantly, the Java language requires a lot more programming. The beauty of Visual Basic is that its visual programming environment allows you to create an application infrastructure almost automatically. Achieving the same result with Java requires manual programming, but results in much shorter programs.

There is, however, a third type of programming environment that allows you to create programs using "drag-and-drop" technology.

Another aspect of simplicity is brevity. One of the goals of the Java language is to enable the development of programs that can be executed completely independently on small machines. The main interpreter and class support facilities are about 40KB in size; standard libraries and threading tools (especially the self-contained microkernel) take another 17: KB.
This great success... Note, however, that the GUI support libraries are much larger.

Object oriented

In simple terms, object-oriented programming is a programming technique that focuses on data (i.e., objects) and the means of accessing them. By analogy with carpentry, the object-oriented craftsman is mainly focused on the chair he makes, and only secondarily he is interested in the tools needed to do so; at the same time, the non-object-oriented carpenter thinks only of his tools. The object-oriented properties of Java and C ++ are essentially the same.

Object orientation has proven its worth over the past 30 years, and without it it is impossible to imagine a modern programming language. Indeed, the object-oriented features of the Java language are comparable to the C ++ language. The main difference between them lies in the mechanism of multiple inheritance, for which the Java language is found the best solution as well as in the Java metaclass model.

Reflection (Chapter 5) and Object Serialization (Chapter 12) allow you to implement persistent objects and tools for building graphical user interfaces from out-of-the-box components.

If you've never programmed in object-oriented languages, read Chapters 4-6 carefully. These chapters cover the basics of object-oriented programming and show you the benefits of developing complex projects over traditional, procedural-oriented languages ​​such as C or Basic.

Distributed

Java has a large library of programs for transferring data based on TCP / IP (Transmission Control Protocol / Internet Protocol), HTTP (Hypertext Transfer Protocol) or FTP (File Transfer Protocol file transfer). Applications written in the Java language can open and access objects over the network using andURLs (Uniform Resource Location) are as easy as a local network.

The Java language provides a powerful and easy-to-use web experience. Anyone who has ever tried to write programs for working on the Internet in other languages ​​will be pleasantly surprised at how easily the most difficult tasks, for example, opening network connections (sockets connection), are solved in Java. An elegant mechanism of so-called servlets makes server operation extremely efficient.

Servlets are supported by many popular Web servers. (Networking will be covered in Volume II.) The communication between distributed objects in Java is provided by the remote method invocation mechanism (this topic is also covered in Volume 2).

Reliable

The Java language is designed to create programs that must work reliably in all situations. The Java language focuses on early detection possible mistakes, dynamic check(during program execution), as well as the elimination of error-prone situations ... The only significant difference between the Java language and the C ++ language is the Java model of pointers, which excludes the possibility of memory overwriting and data corruption.

This property is also very useful. The Java compiler detects errors that other languages ​​find only at runtime. In addition, programmers who have spent many hours looking for an error that caused memory corruption due to an invalid pointer will be very glad that such problems cannot arise in the Java language, in principle.

If you've previously programmed in a Visual Basic or COBOL language that doesn't explicitly use pointers, you might not understand why this is so important. C programmers are less fortunate. They need pointers to access strings, arrays, objects, and even files. When programming in the Visual Basic language, none of this is required, and the programmer does not have to worry about the memory allocation for these entities. On the other hand, many data structures in a non-pointer language are very difficult to implement. For common structures like strings and arrays, pointers are not needed. The power of pointers comes into play only where you can't do without them, such as when creating linked lists. The Java programmer is forever rid of invalid pointers, misallocations, and memory leaks.

Safe

The Java language is intended for use in a networked or distributed environment. For this reason, great attention has been paid to safety. The Java language allows you to create systems that are protected from viruses and tampering.

In the first edition, we wrote: “Never say never,” and we were right. A group of security experts at Princeton University discovered the first security bugs in Java 1.0 shortly after the first version of the JDK went on sale. Moreover, both they and other specialists continued and subsequently found more and more bugs in the security mechanisms of all subsequent versions of the Java language.

On the positive side of this situation, the Java language development team declared its zero tolerance for any security bugs and immediately began to fix any problems found in the applet security mechanism. In particular, by publishing the internal specifications of the Java language interpreter, Sun has made it much easier to find hidden errors in the security system and attracted independent specialists to search for them.

This increased the likelihood that any errors in the security system would soon be discovered. In any case, it is extremely difficult to trick the Java language security system. The bugs found so far have been almost subtle and (relatively) few in number.

Sun's security Web page is at the following URL: http://java.sun.com/sfaq/.

Here are some of the situations that the Java security system prevents.

1) Stack overflow of an executable program, which was caused by a notorious "worm" spreading on the Internet.

2) Damage to memory areas outside the space allocated to the process.

3) Reading and writing local files using a secure classloader such as a web browser that disallows such file access.

All of these security measures are appropriate and usually work flawlessly, but discretion never hurts. Although the bugs found so far were far from trivial, and the details of their search are often kept secret, it must be admitted that it is probably still impossible to prove the safety of the Java language.

Over time, new protections were added to the language. Starting with version 1.1, the concept of digitally signed classes appeared in the Java language. When you use a digitally signed class, you can be sure of the author. If you trust it, you can grant this class all the privileges available on your machine.

Alternative code delivery mechanism suggested by by Microsoft, relies on ActiveX technology and uses only digital signatures for security. Obviously, this is not enough - any user of Microsoft software can attest that the programs are widely renowned manufacturers often crash, creating the risk of data corruption. Java security is much more reliable than ActiveX technology because it controls the application from the moment it starts and prevents it from causing damage.

Architecture independent

The compiler generates an object file, the format of which does not depend on the architecture of the computer - the compiled program can run on any processors under the control of the Java program execution system. To do this, the Java compiler generates byte-code commands that do not depend on the specific architecture of the computer. The bytecode is designed in such a way that it can be easily interpreted on any machine or translated into machine-dependent code on the fly.

This is not a new idea. More than 20 years ago, both Niclaus Wirth's Pascal implementation system and UCSD Pascal used the same technology. The use of bytecodes gives a big benefit during program execution (although synchronous compilation compensates for it in many cases). The Java developers have done an excellent job of developing a set of bytecode commands that work great on most modern computers easily translating into real machine commands.

Machine independent

Unlike the C and C ++ languages, the Java specification has no implementation-specific aspects. Both the size of the basic data types and the arithmetic operations on them are well-defined.

For example, int in Java always means a 32-bit integer. In C and C ++, the int type can mean either a 16-bit or 32-bit integer, as well as an arbitrary size integer, as chosen by the developer of a particular compiler. The only limitation is that the size of the int type cannot be less than the size of the short int and the size of the long int. Fixed size numeric types avoids many of the hassles associated with running programs on different computers. Binary data is stored and transmitted in a fixed format, which also avoids misunderstandings associated with different byte ordering on different platforms ("big endian / little endian" conflict). Strings are saved in standard Unicode format.

Libraries, which are part of the system, define a machine-independent interface. For example, the language provides an abstract class Window and its implementations for the Unix, Windows, and Macintosh operating systems.

Anyone who has ever tried to write a program that works equally well on Windows, Macintosh, and ten flavors Unix systems, knows that this is a very difficult task. The Java version made a heroic attempt to solve this problem by providing a simple toolkit that adapts common user interface elements to a wide variety of software platforms. Unfortunately, the library, which took a lot of work, did not allow us to achieve acceptable results on different platforms. (At the same time, different errors appeared in graphics programs on different platforms.)

However, this was only the beginning. In many applications, machine independence is far more important than the sophistication of a graphical user interface. These are the applications that have benefited from Java 1.0. However, the graphical user interface toolkit has now been completely redesigned and no longer depends on the user interface on the host computer. A new version more meaningful and, in our opinion, more attractive to the user than the previous ones.

Interpreted

The Java interpreter can be sent to any machine and execute bytecode directly on it. Since link editing is an easier process, software development can become much faster and more efficient.

This may be an advantage when developing applications, but the quote is a clear exaggeration. In any case, the Java compiler in the Java Software Development Kit (JSDK) is rather slow. (Some compilers of the third kind, such as those from IBM, are much faster.) Recompilation speed is just one factor that characterizes the efficiency of a programming environment. When you compare the speed of Java versus Visual Basic, you might be disappointed.

High performance

While interpreted bytecodes are generally more than adequate in performance, there are situations where even higher performance is required. Bytecodes can be translated on the fly (at runtime) into machine codes for a specific processor on which the application is running.

If an interpreter is used to execute bytecodes, the phrase "high performance" should not be used. However, on many platforms a different kind of compilation is possible, provided by just-in-time compilers-JITs. They translate the bytecode into machine-dependent code, store the result in memory, and then call it as needed. Since the interpretation is performed only once, this approach increases the speed of work many times over.

Despite the fact that synchronous compilers are still slower than machine-dependent compilers, they are in any case much faster than interpreters, providing 10- or even 20-fold speedup for some programs. This technology is constantly improving and in the end it can reach speeds that traditional compilers can never surpass. For example, a synchronous compiler can determine which piece of code is being executed more often and optimize it for execution speed.

MULTI-THREAD

Provides better interactivity and program execution.

If you've ever tried to multithreaded computations in any other programming language, you'll be pleasantly surprised at how easy it is to do this in Java. Java threads can take advantage of multiprocessing systems if the operating system allows it. Unfortunately, the implementations of streams on most platforms are very different from each other, and the developers of the Java language make no attempt to achieve uniformity. Only the code for calling threads remains the same for all machines; the Java language shifts the implementation of multithreading to the underlying operating system or threading library. (Threads are covered in Volume II.) Despite this, it is the ease of multithreading that makes Java so attractive for server software development.

Dynamic

In many ways, Java is more dynamic than C or C ++. It has been designed to easily adapt to an ever-changing environment. New methods and objects can be freely added to libraries without causing any harm. The Java language makes it easy to get information about the progress of a program.

This is very important when you need to add code to an already running program. A prime example of this is code that is downloaded from the Internet for execution by a browser. In Java 1.0, it was not easy to get information about the progress of a program being executed, but the current version of the Java language exposes both the structure and behavior of the objects of the program being executed to the programmer.
This is very valuable for systems that need to analyze objects during program execution. Such systems include GUI builders, smart debuggers, plug-ins, and object databases.

Java and the Internet

The idea is simple - users download Java bytecodes from the Internet and execute them on their machines. Java programs that run on Web browsers are called applets. To use the applet, you need a Java-enabled Web browser that can interpret bytecodes. The Java language source is licensed by Sun, which insists that both the language itself and the structure of its core libraries remain unchanged. Unfortunately, this is not the case in reality. Different versions of Netscape and Internet Explorer browsers support different versions the Java language, and some of these versions are significantly outdated. This unfortunate situation creates more and more obstacles in the development of applets that take advantage of the latest version of the Java language. To address this problem, Sun has developed the Java Plug-in, which provides the most modern environment for running Java programs based on the Netscape and Internet Explorer browsers.

Loading an applet is like embedding an image in a Web page. The applet becomes part of the page, and the text wraps around the space it occupies. However, the difference is that the image is now alive. It reacts to user commands, changes its appearance and transfers data between the computer on which the applet is viewed and the computer running the applet.

Loading an applet is like inserting a picture into a Web page. The applet becomes part of the page, and the text wraps around the space it occupies. The point is that the image is "live". It responds to user input, changes its appearance, and transfers data between the computer running the applet and the computer running the applet.

In fig. 1.1 shows a good example of a dynamic Web page that performs complex calculations and uses an applet to display molecules. To better understand the structure of the molecule, you can rotate it or zoom in on the image using the mouse. Such manipulations cannot be implemented on static Web pages however applets make this possible. (This applet can be found at http: //jmol.sourceforge.net.)

Rice. 1.1. Jmol applet

Applets can be used to add new buttons and text fields to a Web page. However, these applets are slow to load over the phone line.

Much the same can be done with Dynamic HTML, forms HTML language(Hypertext Markup Language) or a scripting language such as JavaScript. Of course, the first applets were meant for animation: spinning globes, dancing cartoon characters, fanciful texts, and so on. However, most of the above can do animated GIFs, and Dynamic HTML, combined with scripting, does a lot more than applets.

As a result of browser incompatibilities and inconsistent loading over slow network connections, applets targeting Web pages have not been a huge advance. In local area networks (intranets) the situation is completely different. They usually do not have problems associated with throughput channel, so the loading time of applets is unimportant. On the local network, you can select the desired browser or use the Java Plug-In program. Employees cannot move software delivered over a network to the wrong location or install it incorrectly, and a sysadmin does not need to bypass all client machines and update software on them. A large number of programs designed for inventory accounting, vacation scheduling, travel reimbursement and the like have been developed by many corporations in the form of browser-based applets.

As we wrote the book, the pendulum swung from client programs to server-side programming again. Specifically, application servers can use the monitoring capabilities of the Java Virtual Machine to automatically balance load, pool database connections, synchronize objects, safely shutdown and reload, and other processes required for scalable server applications. which are almost impossible to implement correctly. Thus, programmers who create applications have the opportunity to buy these complex mechanisms instead of developing them yourself. This increased the productivity of programmers - they focused on the logic of their programs, without being distracted by the details associated with the operation of servers.

Top related articles