Learning Java: An Overview of the Java Language

1. Overview of the Java language

  • It is a high-level programming language launched by SUN (Stanford University Network, Stanford University Network Company) in 1995.
  • It is an Internet-oriented programming language. Java was initially attractive because Java programs could run in a Web browser. These Java programs are called Java applets. Applets use a modern graphical user interface to interact with Web users. Applets are embedded in HTML code.
  • With the continuous maturity of Java technology in the web, it has become the preferred development language for web applications.
    Background development: Java, PHP, Python, Go, Node.js

1.1 Application field

From the application field of Java, the application direction of Java language is mainly manifested in the following aspects:

  • Enterprise-level applications: mainly refer to complex software systems of large enterprises and various types of websites. Java's security mechanism and
    its cross-platform advantages make it widely used in the development of distributed systems. Applications include finance, telecommunications
    , transportation, e-commerce, etc.
  • Android platform applications: Android applications are written in Java language. The level of Android development largely depends on whether the core capabilities of the Java language are solid.
  • Big data platform development: Various frameworks include Hadoop, spark, storm, flink, etc. In terms of this type of technology ecosystem, there are also various middleware such as flume, kafka, sqoop, etc. Most of these frameworks and tools are used Written in Java, but provides various language APIs such as Java, scala, Python, R, etc. for programming.
  • Applications in the mobile field: mainly in the consumer and embedded fields, referring to applications on various small devices, including mobile phones
    , PDAs, set-top boxes, and automotive communication equipment.

1.2 Main features

  • The Java language is easy to learn. The syntax of the Java language is very close to that of C and C++, making it easy for most programmers to learn and use Java.
  • The Java language is obligatory object-oriented. The Java language provides primitives such as classes, interfaces, and inheritance. 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 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, URLConnectionSocket, ServerSocket, etc. 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, automatic garbage collection, etc. are important guarantees for the robustness of Java programs. The discarding of pointers is a wise choice of Java.
  • The Java language is safe. Java is usually used in the network environment, for this reason, Java provides a security mechanism to prevent the attack of malicious code. Such as: security prevention mechanism (class ClassLoader), such as assigning different namespaces to prevent substitution of local classes with the same name, byte code inspection.
  • The Java language is architecture neutral. Java programs (files with a suffix of java) are compiled into an architecture-neutral bytecode format (files with a suffix of class) on the Java platform, and can then be run on any system that implements the Java platform.
  • The Java language is interpreted. As mentioned earlier, Java programs are compiled into bytecode format on the Java platform, which can then be run in the interpreter of any system that implements the Java platform.
  • Java is slightly more performant. Compared with those interpreted high-level scripting languages, Java's performance is still better.
  • The Java language natively supports multithreading. In the Java language, a thread is a special object that must be created by the Thread class or its child (grandson) classes.

1.3 Operation mechanism and operation process

Features of the Java language
Feature 1: Object Oriented

两个基本概念:类、对象
三大特性:封装、继承、多态

Feature 2: Robustness

吸收了C/C++语言的优点,但去掉了其影响程序健壮性的部分(如指针、内存的申请与释放等),
提供了一个相对安全的内存管理和访问机制

Feature 3: Cross-platform

跨平台性:通过Java语言编写的应用程序在不同的系统平台上都可以运行。
“Write once , Run Anywhere”
原理:只要在需要运行 java 应用程序的操作系统上,
先安装一个Java虚拟机 (JVM Java Virtual Machine) 即可。由JVM来负责Java程序在该系统中的运行。

Two core mechanisms of Java
One: Java virtual machine
insert image description here

insert image description here
Two: garbage collection
insert image description here

1.4 Development experience

step:

  • Java codewriteto a file with a .java extension.
  • Run the java file through the javac commandcompile
  • Execute the generated class file through the java commandrun.
    insert image description here
    first java program
public class Text{
    
    
	public ststic void main(String[] args){
    
    
	System.out.println("Hello World!")l
	}
}
>>Hello World

Summary of the first program

  • Java source files have the extension "java". The basic components of a source file are classes, such as the HelloWorld class in this example.
  • The execution entry point of a Java application is the main() method. It has a fixed writing format:
    public static void main(String[] args) {…}
  • The Java language is strictly case-sensitive.
  • A Java method is composed of statements, and each statement ends with ";".
  • Curly braces appear in pairs and are indispensable.
  • There can be at most one public class in a source file. The number of other classes is not limited. If the source file contains a public class, the file name must be named according to the class name.

1.5 Java API

  • API (Application Programming Interface, Application Programming Interface) is
    the basic programming interface provided by Java.
  • The Java language provides a large number of basic classes, so Oracle also provides corresponding API documents for these basic classes to tell developers how to use these classes and the methods contained in these classes.
  • 下载API:
    https://docs.oracle.com/javase/8/docs/api/index.html
    insert image description here

Commonly used API summary
https://blog.51cto.com/u_15067223/4843315?articleABtest=1

Review and Homework

1. What are the characteristics of the java language?

Object-oriented: two basic concepts: class and object; three major features: encapsulation, inheritance, polymorphism
Robustness: absorbs the advantages of C/C++ language, but removes the parts that affect the robustness of the program (such as pointers, memory application and release, etc.), providing a relatively safe memory management and access mechanism
cross-platform: applications written in the Java language can run on different system platforms. “Write once, Run Anywhere”

2. What is the difference between System.out.println() and System.out.print()?

What is the effect of the following code in operation?
System.out.println(); After printing, it will wrap.
System.out.print(); After printing, it will not wrap.

3. Can multiple classes (not internal classes) be included in a ".java" source file? What are the restrictions?

Can. But at most one class name is declared public, the same as the file name.

4. The file name of the Something class is OtherThing.java

class Something {
    
    
    public static void main(String[] something_to_do) {
    
            
        System.out.println("Do something ...");
    }
}

correct. No one has ever said that Java's class name must be the same as its file name. But the name of the public class must be the same as the file name.

5. Why do you want to set the path (or what is the purpose of setting the path)?

The purpose is to call all instructions in the directory specified by jdk under any file path in the console.

6. What is the relationship between JDK, JRE and JVM?

JDK contains JRE, and JRE contains JVM.
JDK=JRE+java core development tool
JRD=JVM+JAVA core class library
insert image description here

7. Does the source file name have to be the same as the class name? If not, then under what circumstances must it be the same?

Multiple classes can be declared in a java source file. However, at most one class can be declared public.
And it is required that the class name of the class declared as public must be the same as the source file name.

8. What is GC? Why is there GC?

GC means garbage collection (Gabage Collection). Memory handling is a place where programmers are prone to problems.
Forgotten or wrong memory recovery will lead to instability or even crash of the program or system. The GC function provided by Java can automatically monitor whether the object exceeds Scope so as to achieve the purpose of automatically reclaiming memory, the Java language does not provide an explicit operation method to release the allocated memory.

9. What is the basic principle of the garbage collector? Can the garbage collector reclaim memory immediately? Is there any way to actively notify the virtual machine to perform garbage collection?

For GC, when a programmer creates an object, the GC begins to monitor the address, size, and usage of the object. Usually, GC uses a directed graph to record and manage all objects in the heap. In this way it is determined which objects are "reachable" and which are "unreachable".
When the GC determines that some objects are "unreachable", the GC is responsible for reclaiming these memory spaces. Can. Programmers can manually execute System.gc() to notify the GC to run, but the Java language specification does not guarantee that the GC will execute.

10. Write code to output heart shape.

class PrintHeart1 {
    
    
	public static void main(String[] args) {
    
    

		System.out.print("\t" + "*" + "\t\t\t\t\t\t\t\t\t\t\t\t" + "*" + "\t" + "\n");
		System.out.print("*" + "\t\t" + "*" + "\t\t\t\t" + "I love Java" + "\t\t\t\t" + "*" + "\t\t" + "*" + "\n");
		System.out.print("\t" + "*" + "\t\t\t\t\t\t\t\t\t\t\t\t" + "*" + "\t" + "\n");
		System.out.print("\t\t" + "*" + "\t\t\t\t\t\t\t\t\t\t" + "*" + "\t\t" + "\n");
		System.out.print("\t\t\t" + "*" + "\t\t\t\t\t\t\t\t" + "*" + "\t" + "\n");
		System.out.print("\t\t\t\t" + "*" + "\t\t\t\t\t\t" + "*" + "" + "\t" + "\n");
		System.out.print("\t\t\t\t\t" + "*" + "\t\t\t\t" + "*" + "" + "\t\t" + "\n");
		System.out.print("\t\t\t\t\t\t" + "*" + "\t\t" + "*" + "" + "\t\t" + "\n");
		System.out.print("\t\t\t\t\t\t\t" + "*" + "\n");

	}

}

insert image description here

Guess you like

Origin blog.csdn.net/weixin_52357829/article/details/129226383