Getting started with java---Introduction & simple output example & preparation before development

    Java is the general term for the Java object-oriented programming language and Java platform launched by Sun Microsystems in May 1995. Developed by James Gosling and colleagues, it was officially launched in 1995. Java is divided into three systems:

  • JavaSE (J2SE) (Java2 Platform Standard Edition, Java Platform Standard Edition)
  • JavaEE (J2EE) (Java 2 Platform, Enterprise Edition, Java Platform Enterprise Edition)
  • JavaME (J2ME) (Java 2 Platform Micro Edition, java platform micro edition).

    In June 2005, the JavaOne conference was held, and SUN released Java SE 6. At this point, various versions of Java have been renamed to remove the number "2" in them: J2EE was renamed Java EE, J2SE was renamed Java SE, and J2ME was renamed Java ME. Its main features are as follows:

  • The Java language is simple:

    The syntax of the Java language is very close to that of the C and C++ languages, making it easy for most programmers to learn and use. Java, on the other hand, discards rarely used, hard-to-understand, and confusing features of C++, such as operator overloading, multiple inheritance, and automatic type casting. In particular, the Java language does not use pointers, but references. And provides automatic garbage collection, so that programmers do not have to worry about memory management.

  • The Java language is object-oriented:

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

  • The Java language is distributed:

    The Java language supports the development of Internet applications. There is a network application programming interface (java net) in the basic Java application programming interface, which provides a class library for network application programming, including URL, URLConnection, Socket, ServerSocket and so on. Java's RMI (Remote Method Activation) mechanism is also an important means of developing distributed applications.

  • The Java language is robust:

    Java's strong type mechanism, exception handling, and automatic garbage collection are important guarantees for the robustness of Java programs. Discarding pointers is a sensible choice for Java. Java's security checking mechanism makes Java more robust.

  • The Java language is safe:

    Java is usually used in the network environment, for this, Java provides a security mechanism to prevent malicious code attacks. In addition to many security features of the Java language, Java has a security precaution mechanism (class ClassLoader) for classes downloaded over the network, such as assigning different namespaces to prevent replacement of local classes of the same name, byte code checking, and providing security management The mechanism (class SecurityManager) lets Java applications set up security sentinels.

  • The Java language is architecture neutral:

    Java programs (files suffixed with java) are compiled into an architecture-neutral bytecode format (files suffixed with 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 environments and software distribution.

  • The Java language is portable:

    This portability comes from architecture neutrality, in addition, Java also strictly stipulates the length of each basic data type. The Java system itself also has strong portability. The Java compiler is implemented in Java, and the Java runtime environment is implemented in ANSI C.

  • The Java language is interpreted:

    As mentioned earlier, Java programs are compiled into bytecode format on the Java platform, which can then be run on any system that implements this Java platform. At runtime, the Java interpreter in the Java platform interprets and executes these bytecodes, and the classes required in the execution process are loaded into the runtime environment in the linking phase.

  • Java is high performance:

    Compared to those interpreted high-level scripting languages, Java is indeed high performance. In fact, Java's running speed is getting closer and 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 sub (grandchild) class. There are usually two ways to create a thread: First, wrap an object that implements the Runnable interface into a thread using a constructor of type Thread(Runnable), and second, derive a subclass from the Thread class and override run method, an object created using this subclass is a thread. It is worth noting that the Thread class has implemented the Runnable interface, so any thread has its run method, and the run method contains the code to be run by the thread. A thread's activity is controlled by a set of methods. The Java language supports the simultaneous execution of multiple threads and provides a synchronization mechanism between multiple threads (the keyword is synchronized).

  • The Java language is dynamic:

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

    The development history is as follows:

  • On May 23, 1995, the Java language was born
  • In January 1996, the first JDK-JDK1.0 was born
  • In April 1996, 10 major operating system vendors declared that they would embed JAVA technology in their products
  • In September 1996, about 83,000 web pages were created using JAVA technology.
  • On February 18, 1997, JDK1.1 was released
  • On April 2, 1997, the JavaOne conference was held, with more than 10,000 participants, setting a record for the scale of similar conferences in the world at that time
  • In September 1997, JavaDeveloperConnection community members exceeded 100,000
  • In February 1998, JDK1.1 was downloaded more than 2,000,000 times
  • On December 8, 1998, the JAVA2 enterprise platform J2EE was released
  • In June 1999, Sun released three versions of Java: Standard Edition (JavaSE, formerly J2SE), Enterprise Edition (JavaEE, formerly J2EE), and Micro Edition (JavaME, formerly J2ME)
  • On May 8, 2000, JDK1.3 was released
  • On May 29, 2000, JDK1.4 was released
  • On June 5, 2001, NOKIA announced that it would sell 100 million Java-enabled mobile phones by 2003
  • On September 24, 2001, J2EE 1.3 was released
  • On February 26, 2002, J2SE1.4 was released, and the computing power of Java has been greatly improved since then.
  • At 18:00PM on September 30, 2004, J2SE1.5 was released, becoming another milestone in the history of Java language development. To express the importance of this release, J2SE 1.5 was renamed Java SE 5.0
  • In June 2005, the JavaOne conference was held, and SUN released Java SE 6. At this point, various versions of Java have been renamed to remove the number "2" in them: J2EE was renamed Java EE, J2SE was renamed Java SE, and J2ME was renamed Java ME
  • In December 2006, Sun released JRE6.0
  • On April 20, 2009, Oracle acquired Sun for $7.4 billion. Get the copyright of java.
  • In November 2010, Apache threatened to withdraw from the JCP due to Oracle's unkindness to the Java community [4].
  • On July 28, 2011, Oracle released the official version of java7.0.
  • On March 18, 2014, Oracle Corporation released Java SE 8.

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

    After installing the above tools, we use a simple example to demonstrate Java programming, create a file HelloWorld.java (the file name must be the same as the class name) , the code is as follows:


public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}

    It should be noted here that both String args[] and String[] args can be executed, but String [] args is recommended to avoid ambiguity and misreading. Running the above example, the output is as follows:

$ javac HelloWorld.java
$ java HelloWorldHelloWorld
 

    Above we used two commands javac and java . javac is followed by the filename of the java file, eg HelloWorld.java. This command is used to compile java source files into class bytecode files, such as: javac HelloWorld.java . After running the javac command, if the compilation is successful without errors, a file called HelloWorld.class will appear. The java is followed by the class name in the java file, for example HelloWorld is the class name, such as: java HelloWorld. Note : Do not add .class after the java command.

    Some friends do not understand after seeing it, why is String[] args, what is this args for? String[] args It can be seen that it is an array. To run the Test.class file on the command line, for example, you can write:

java Test luyaran

    It is equivalent to passing a luyaran string to the array. It can also be printed out and can be used as simple input.

publicclassTest{publicstaticvoid main(String[] args){System.out.println(args[0]);}}   
       
        
    

    Running the above example, the output is as follows:

$ javac Test.java
$ java Test luyaran
luyaran

    Note here that main is the entry point of a program, and a java program must have and only have one main method. args[0] is the first parameter you pass in, args[1] is the second parameter you pass in, and so on. String[] args also has an equivalent, which is String... args . The former is in the form of an array, and the latter is in the form of a variable parameter. The former is used more, but the latter should also be recognized.

    The Java language actually has a former name~ called Oak, and the name is also very casual, just because I saw an oak tree outside the window (just because I looked out of the window and glanced at you~), so I just It's called Oak, but the name Oak has already been registered. In the end, they named the language after the name Java. It is said that the programmers of Sun company like to drink coffee, and they are very impressed with a coffee in Java, so they have the classic name of Java and the icon of coffee. .

    Before formally learning java and installing and configuring the development environment, it is necessary to understand some technical terms related to Java:

  • JDK (Java Development Kit): Software used by programmers who write Java programs
  • JRE (Java Runtime Environment): Software used by users who run Java programs
  • Server JRE (Java SE Runtime Environment): The Java runtime environment used by the server
  • SDK (Software Development Kit): Software Development Kit, used in Java to describe the JDK between 1998 and 2006
  • DAO (Data Access Object): data access interface, data access, as the name implies, is to deal with the database
  • MVC (Model View Controller): the abbreviation of model-view-controller, a software design paradigm, used to organize code with a method of separating business logic and data display

    Complement the three main characteristics of object-oriented programming: encapsulation, inheritance, and polymorphism .

Encapsulation (encapsulation): Encapsulation is an information concealment technology, which is reflected in the description of the class and is an important feature of the object. Encapsulation encapsulates the data and the methods (functions) for processing the data as a whole, so as to realize a highly independent module, so that users can only see the external characteristics of the object (what messages the object can accept and what processing capabilities it has), while The internal properties of objects (private data that hold internal state and algorithms that implement processing capabilities) are hidden from the user. The purpose of encapsulation is to separate the designer of the object from the user of the object. The user does not need to know the details of its behavior implementation, but only needs to use the message provided by the designer to access the object.

Inheritance: Inheritance is the mechanism by which subclasses share data and methods of their parent class. It is embodied by the derived function of the class. A class directly inherits all the descriptions of other classes, and can be modified and extended at the same time. Inheritance is transitive. Inheritance is divided into single inheritance (a subclass has one parent class) and multiple inheritance (a class has multiple parent classes). Objects of a class are closed by themselves. If there is no inheritance mechanism, there will be a lot of duplication of data and methods in objects of a class. Inheritance not only supports the reusability of the system, but also promotes the extensibility of the system.

Polymorphism: Objects act according to the messages they receive. When the same message is received by different objects, it can produce completely different actions, a phenomenon called polymorphism. Using polymorphism, a user can send a generic message and leave all the implementation details to the object receiving the message, so that the same message can call different methods. For example: the same run method, when the bird calls it, it flies, and when the beast calls it, it runs. The implementation of polymorphism is supported by inheritance. Using the hierarchical relationship of class inheritance, the protocol with common functions is stored in the highest possible place in the class hierarchy, and the different methods of realizing this function are placed in the lower level. In this way, objects generated at these lower levels can respond differently to generic messages. Polymorphism is achieved in OOPL by redefining base class functions (defined as overloaded or virtual functions) in derived classes.

    Well, this sharing is over here. If you feel good, please give more likes and support. . .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324883228&siteId=291194637