Getting Started with Java---Introduction & simple Output small example & preparation before development

Source: Internet
Author: User
Tags thread class java se

Java is a generic term for the Java object-oriented programming language and Java platform introduced by Sun Microsystems Company in May 1995. Co-developed by James Gosling and co-workers, and was formally launched in 1995. Java consists of three systems:

    • Javase (J2SE) (JAVA2 Platform standard Edition,java platform version)
    • EE (Java 2 platform,enterprise Edition,java Platform Enterprise Edition)
    • Javame (J2ME) (Java 2 Platform Micro Edition,java Platform mini version).

In June 2005, the JavaOne conference was held and Sun disclosed Java SE 6. At this point, various versions of Java have been renamed to remove the number "2": the name of the Java EE, j2se renamed Java Se,j2me to Java ME. Its main features are as follows:

  • The Java language is simple:

    The syntax of the Java language is close to the C and C + + languages, making it easy for most programmers to learn and use. Java, on the other hand, discards features that are seldom used in C + +, which are difficult to understand and confusing, such as operator overloading, multiple inheritance, and automatic coercion of type conversions. In particular, the Java language does not use pointers, but references. and provides automatic scrap collection, which makes it unnecessary for programmers to worry about memory management.

  • The Java language is object-oriented:

    The Java language provides object-oriented features such as classes, interfaces, and inheritance, and for simplicity, only single inheritance between classes is supported, but multiple inheritance between interfaces is supported, and the implementation mechanism between classes and interfaces is supported (the keyword is implements). The Java language fully supports dynamic binding, while the C + + language uses dynamic binding only for virtual functions. In short, the Java language is a purely object-oriented programming language.

  • The Java language is distributed:

    The Java language supports the development of Internet applications and has a network application programming interface (Java net) in the basic Java application programming interface, which provides a class library for network application programming, including URLs, URLConnection, sockets, ServerSocket and so on. The RMI (remote method Activation) Mechanism of Java is also an important tool for developing distributed applications.

  • The Java language is robust:

    Java's strong typing mechanism, exception handling, and garbage collection are important guarantees of Java program robustness. Discarding pointers is a wise choice for Java. Java's security check mechanism makes Java more robust.

  • The Java language is secure:

    Java is typically used in a network environment, and Java provides a security mechanism to prevent malicious code from attacking. In addition to many of the security features of the Java language, Java has a security mechanism (class ClassLoader) for classes that are downloaded over the network, such as assigning different namespaces to prevent the substitution of locally named classes, byte code checks, and provides security management mechanisms (class SecurityManager) for Java applications to set up Security Sentinel.

  • The Java language is architecture-neutral:

    Java programs (files that are suffixed with Java) are compiled into an architecture-neutral bytecode format (a file with a suffix of Class) on the Java platform and can then be run on any system that implements the Java platform. This approach is suitable for heterogeneous network environment and software distribution.

  • The Java language is portable:

    This portability comes from architecture neutrality, and Java also strictly specifies the length of each basic data type. Java system itself is also very strong portability, Java compiler is implemented in Java, Java operating environment is implemented with ANSI C.

  • The Java language is interpreted:

    As mentioned earlier, Java programs are compiled into bytecode format on the Java platform and can then be run on any system that implements the Java platform. At runtime, these bytecode are interpreted by the Java interpreter in the Java platform, and the classes required during execution are loaded into the runtime environment during the join phase.

  • Java is high-performance:

    Java is really high-performance compared to those high-level scripting languages that are interpreted. In fact, the speed of Java is getting closer to C + + with the development of JIT (just-in-time) compiler technology.

  • The Java language is multithreaded:

    In the Java language, a thread is a special object that must be created by the thread class or its child (grandchild) class. There are usually two ways to create a thread: one is to wrap an object that implements the Runnable interface into a thread using a constructor of type thread (Runnable), and another to derive a subclass from the thread class and override the Run method, and the object created with that subclass is a thread. It is important to note that the thread class has implemented the Runnable interface, so any thread has its run method, and the Run method contains the code that the thread wants to run. The activity of a thread is controlled by a set of methods. The Java language supports simultaneous execution of multiple threads and provides a synchronization mechanism between multithreading (the keyword is synchronized).

  • The Java language is dynamic:

    One of the design goals of the Java language is to adapt to dynamically changing environments. The classes required by the Java program can be dynamically loaded into the runtime environment, or they can be loaded into the network to load the required classes. This also facilitates software upgrades. In addition, classes in Java have a run-time representation that enables type checking at run time.

The history of development is as follows:

  • May 23, 1995, the Java language was born
  • January 1996, the first jdk-jdk1.0 was born
  • In April 1996, 10 of the most important operating system vendors affirmed that Java technology would be embedded in their products
  • In September 1996, about 83,000 Web pages applied Java technology to create
  • February 18, 1997, JDK1.1 released
  • April 2, 1997, the JavaOne meeting, the participation of more than 10,000 people, creating a record of the world's similar conference size
  • In September 1997, Javadeveloperconnection community members exceeded 100,000
  • February 1998, JDK1.1 was downloaded more than 2,000,000 times
  • December 8, 1998, JAVA2 Enterprise platform Java cloud release
  • In June 1999, Sun released three versions of Java: Standard Edition (Javase, formerly J2SE), Enterprise Edition (Java EE was formerly a Java EE), and mini-version (Javame, formerly J2ME)
  • May 8, 2000, JDK1.3 released
  • May 29, 2000, JDK1.4 released
  • Nokia announces June 5, 2001 that it will sell 100 million Java-enabled handsets by 2003
  • September 24, 2001, j2ee1.3 released
  • February 26, 2002, j2se1.4 released, since the Java computing power has been significantly improved
  • September 30, 2004 18:00pm,j2se1.5 released as another milestone in the development of the Java language. To indicate the importance of this version, j2se1.5 renamed Java SE 5.0
  • In June 2005, the JavaOne conference was held and Sun disclosed Java SE 6. At this point, various versions of Java have been renamed to remove the number "2": The renamed Java Ee,j2se to Java Se,j2me renamed Java ME
  • December 2006, Sun Company released JRE6.0
  • Oracle acquires Sun for $7.4 billion on April 20, 2009. Access to Java Copyright.
  • In November 2010, because Oracle was unfriendly to the Java community, Apache threatened to quit jcp[4].
  • July 28, 2011, Oracle released the official version of java7.0.
  • March 18, 2014, Oracle publishes Java SE 8.

The Java language tries to ensure that there are more than 1G in the system, and the other tools are as follows:

    • Linux systems, Mac OS systems, Windows 95/98/2000/xp,win 7/8 systems.
    • Java JDK 7, 8 ...
    • Notepad Editor or other editor.
    • Ide:eclipse

After installing the above tools, we use a simple example to show Java programming, create the file Helloworld.java (the filename needs to match the class name), the code is as follows:

HelloWorld {void Main (string[] args) {System.out.println ("Hello World");} }

Note here thatString args[] and string[] args can be executed, but it is recommended to use string[] args, which avoids ambiguity and misreading. Running the above example, the output is as follows:

HelloWorld.  HelloWorldHello    World

Above we used two commands Javac and Java. Javac is followed by the file name of the Java file, such as Helloworld.java. This command is used to compile the Java source file into a class bytecode file, such as: Javac Helloworld.java. After running the Javac command, a helloworld.class file appears if there is no error in compiling successfully. Java followed by the class name in the Java file, such as HelloWorld is the class name, such as: Java HelloWorld. Note : Do not Add. class after the Java command.

Some small partners see later do not understand, why is string[] args, this args is why? String[] args can see that it is an array. In the command line such as running the Test.class file, you can write:

Test Luyaran

Equivalent to passing an Luyaran string to the array. can also be printed out, can be used as a simple input.

Public Class test {     public staticvoid Main (string[]< Span class= "PLN" > Args)  {         system.. Printlnargs[0    }}    

Running the above example, the output is as follows:

Test.  Test Luyaranluyaran  

Note here that main is the entry for a program, and that a Java program must run and have only one main method. Args[0] is the first parameter you passed in, Args[1] is the second parameter passed in, and so on. string[] args also has an equivalent notation, String ... args. The former is an array form and the latter is a variable parameter form. The former is used more, but the latter should also be recognized.

The Java language is actually a once used name ~ Oak, and the name of the time is also very heart, just because of the window to see an oak (just because facing the windows more than a look at you), so called oak, but oak this name has been registered. In the end they named the language in Java, which is said to be the Sun's program apes are very fond of coffee, and a very deep impression of a coffee in Java, so there is the classic Java name and coffee icon.

Before you formally learn Java and install the configuration development environment, it is important to understand some of the terminology related to Java:

    • JDK (Java development Kit): Software used by programmers who write Java programs
    • JRE (Java Runtime Environment): Software used by users running Java programs
    • Server JRE (Java SE Runtime Environment): Java Runtime Environment used by the service side
    • SDK (software Development Kit): Software Development Kit, used in Java to describe JDK between 1998 and ~2006 years
    • DAO (data access Object): The database access interface, data access, as the name implies is to deal with databases
    • MVC (Model View Controller): Models-views-controllers (Controller) abbreviations, a software design paradigm used to organize code in a way that separates business logic from data display

3 main features of object-oriented programming are added: encapsulation, inheritance, polymorphism.

Encapsulation (encapsulation): encapsulation is an information concealment technique, which is embodied in the description of the class and is an important feature of the object. Encapsulation makes the data and the method (function) of processing the data encapsulated as a whole, in order to achieve a very independent module, so that the user can only see the external characteristics of the object (the object can accept which messages, what processing power), and the object's internal characteristics (the preservation of the internal state of private data and the implementation of processing capacity algorithm) is hidden The purpose of encapsulation is to separate the designer of the object from the user of the object, and the user does not have to know the details of its implementation, but only accesses the object with the information provided by the designer.

Inheritance: inheritance is the mechanism by which subclasses share their parent data and methods. It is represented by the derivation function of the class. A class inherits all the descriptions of other classes directly, and can be modified and expanded. Inheritance has transitivity. Inheritance is divided into single inheritance (a subclass has one parent) and multiple inheritance (a class has multiple parent classes). The objects of the class are closed, and if there is no inheritance mechanism, the data and methods in the objects of the class will be duplicated very much. Inheritance not only supports the reusability of systems, but also facilitates the extensibility of the system.

Polymorphism : objects are acting according to the messages they receive. When the same message is accepted by different objects, it can produce a completely different action, a phenomenon called polymorphism. The use of polymorphic users can send a common message, and all implementation details are left to the object receiving the message, so the same message can invoke different methods. For example: the same as the Run method, when a bird calls a fly, the beast invokes a run. The implementation of polymorphism is supported by inheritance, with the hierarchical relationship of class inheritance, the protocol with common function is stored at the highest level of class, and the different methods of implementing this function are placed at a lower level, so that the objects generated at these low levels can respond differently to generic messages. Polymorphism can be achieved in OOPL by redefining a base class function (defined as an overloaded function or virtual function) in a derived class.

Well, this time to share to the end of this, if it feels good, please more praise support oh ...

Original link: 80088993

Getting Started with Java---Introduction & simple Output small example & preparation before development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.