Published 15 October 2018

Briefly about Java

Briefly about Java

Java is a cross-platform strongly typed object-oriented programming language.

It is used in order to write smart contracts on the CREDITS platform in the CREDITS Desktop Wallets app.

JDK concept

JDK concept.

Java Development Kit, a Java apps development kit, includes Java compiler, standard Java class libraries,  Java runtime environment (JRE), examples, documentation and various utilities. JDK does not have an integrated development environment for Java. An external editor is used in order to write a program in Java. The program is compiled while using the command utility.

Java features

Java features

  • Simplicity. Java syntax is similar to C++.
  • Reliability. Java language-based programs are stable due to strict language typing use (checking the data types correspondence during compilation), object-oriented exception handling.
  • Security. Provides several protection monitoring levels.
  • Cross-platform. The Java language code is translated into a special platform-independent bytecode. The bytecode is then executed by JVM (Java Virtual Machine). Thus, the same code can be run under different operating systems Windows, Solaris, Linux, Unix, Macintosh.
  • Distribution. Java has the programs library for transferring data based on TCP/IP or FTP, able to open objects and access them through the network while using URLs.
  • Performance. While using JIT compilation, it compiles the bytecode into the machine code while the program is running (instantly).
  • Dynamic. Easily adapts to a constantly changing environment, there is an opportunity to add new methods and objects, get information on the program progress.
  • Multithreading. Allows to create apps that run two or more threads simultaneously, to maximize the process use.
  • Object-oriented language. All Java entities are objects, except for the primitive data types.

Basic language ideas

Basic language ideas

Data types are divided into primitive and reference types in Java. A primitive type variable contains a value and a reference variable contains the object address in memory.

There are 8 primitive data types:

Type

Description

Default value

Size

Examples

boolean

true или false

false

1 bit

true, false

byte

The smallest integer type on the size

0

8 bit

Integers from -128 to 127

char

The character data type is one 16-bit Unicode character

\u0000

16 bit

‘a’,’\u0041’, ’\u102’, ‘\k’

short

Integer sign data type, the valid values range varies​​from -32768 to 32767

0

16 bit

Whole numbers vary from -32768 to 32767

int

Integer sign data type, the valid values range varies​​from -2147483648 to 2147483647

0

32 bit

Integers from -2147483648 to 2147483647

long

Integer sign data type, the valid values range varies​​from -9223372036854775808 to 9223372036854775807

0

64 bit

Integers from -9223372036854775808 to 9223372036854775807

float

Valid numbers, the valid values range varies​​ from  1,4 х 10-45 to 3,4 х 1038

0.0

32 bit

3.16f, 10.8f, 0.339e + 1f

double

Valid numbers with double precision, the valid values range varies​​ from 4,9 х 10-324 to 1,7 х 10308

0.0

64 bit

positive and negative values ​​of 4,9 х 10-324 and 1,7 х 10308


All other data types refer to reference types.

Object variables are fields referring to a particular object instance.

The object is the class instance.

A reference (a pointer to an object) is a variable containing the memory cell address which the object is stored in. Links will help to address the objects by their names while calling methods and changing  the current objects values​.

Class is the object description template in Java. The class starts with the keyword class followed by the class name. The class body and its fields and methods are specified in curly brackets {}.

Function (method) is a named code block which is declared inside a class and can be used for several times. It is used in expressions and returns the execution result.

A constructor is a special method which is called while creating a new object. Initializes the object at creation time. The constructor name is similar to the class name, including the case.

Statistical methods are class ones declared with using the static keyword, are auxiliary methods to be used by other classes without the need to create an instance.

A static method can access static class variables as well as call static class methods only.

Static fields are the class fields declared while using the static keyword, are common to the entire class and can be used without class objects creation.

The test state (assert) is an operator, which allows to test own assumptions about the program. The assertion confirms the expectations about the behavior that the program does not contain errors while checking the logical expression is true.

The abstraction in Java is implemented by abstract class and interface means.

The class, which basis doesn’t allow to create objects is called abstract. It is necessary to use the abstract keyword before the class name in order to declare a class abstract.

The interfaces are used in order to create completely abstract classes. They are declared while using the interface keyword, which means the way the classes which implement this interface should look.

Design Patterns (templates) are ready-to-use solutions which often arise in tasks. There are generative, structural, behavioral ones.

Checking belonging to a class is an expression which allows to check which class the object belongs to while using the instanceof keyword. True, if an object belongs to its successor class or implements the interface.

Java use in order to write smart contracts

Java use in order to write smart contracts

Smart contracts in CREDITS Desktop Wallets app is developed while using an interpreted Java programming language, which makes it possible to develop and conduct testing under any operating system. The program code allows all common Java programming language constructs use. A smart contract is a Contract class inherited from the parent SmartContract class.

0 Useful article

Contents