Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the basic knowledge questions of Java

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what are the Java basic knowledge interview questions". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian to study and learn "what are the Java basic knowledge interview questions" together.

Java Overview What is Programming

Programming is the process of getting a computer to write program code in a programming language to solve a problem and finally get the result.

In order for computers to understand people's intentions, humans must tell computers the ideas, methods, and means of the problems to be solved in a form that computers can understand, so that computers can work step by step according to human instructions and complete certain specific tasks. This process of communication between humans and computers is called programming.

what is Java

Java is an object-oriented programming language, which not only absorbs various advantages of C++ language, but also abandons the concepts of multi-inheritance and pointer that are difficult to understand in C++. Therefore, Java language has two characteristics: powerful function and easy to use. Java language as a representative of static object-oriented programming language, an excellent implementation of object-oriented theory, allowing programmers to elegant way of thinking complex programming.

Three major versions after jdk 1.5

Java SE (J2SE, Java 2 Platform Standard Edition)

Java SE was formerly known as J2SE. It allows development and deployment of Java applications for use in desktop, server, embedded and real-time environments. Java SE contains classes that support Java Web Services development and provides the foundation for Java EE and Java ME.

Java EE (Java 2 Platform Enterprise Edition)

Java EE was formerly known as J2EE. Enterprise Edition helps develop and deploy portable, robust, scalable, and secure server-side Java applications. Java EE is built on Java SE and provides Web services, component models, management and communication APIs that can be used to implement enterprise-level service-oriented architecture (SOA) and Web 2.0 applications. February 2018 Eclipse officially rebranded Java EE to Jakarta EE

Java ME (J2ME, Java 2 Platform Micro Edition)

Java ME was formerly known as J2 ME. Java ME provides a robust and flexible environment for applications running on mobile and embedded devices such as mobile phones, PDAs, TV set-top boxes, and printers. Java ME includes a flexible user interface, robust security model, many built-in network protocols, and rich support for networked and offline applications that can be downloaded dynamically. Java ME specification-based applications can be written once for many devices and leverage the native capabilities of each device.

The relationship between JVM, JRE and JDK

JVM

Java Virtual Machine is a Java virtual machine, Java programs need to run on virtual machines, different platforms have their own virtual machines, so the Java language can achieve cross-platform.

JRE

Java Runtime Environment includes Java Virtual Machine and core libraries required by Java programs. The core class library is mainly java.lang package: contains the system classes necessary to run Java programs, such as basic data types, basic mathematical functions, string processing, threads, exception handling classes, etc., the system loads this package by default.

If you want to run a well-developed Java program, you only need to install JRE on your computer.

JDK

Java Development Kit is provided for Java developers, which contains Java development tools, including JRE. So with JDK installed, there is no need to install JRE separately. Among them, development tools: compilation tools (javac.exe), packaging tools (jar.exe), etc.

JVM&JRE&JDK Diagram

What is cross-platform? what is the principle

The so-called cross-platform, refers to the java language program, compiled once, can run on multiple system platforms.

Implementation principle: Java programs are run on the system platform through Java virtual machines, as long as the system can install the corresponding Java virtual machines, the system can run Java programs.

What are the characteristics of Java language?

Easy to learn (Java syntax is very close to C and C++)

Object-oriented (encapsulation, inheritance, polymorphism)

Platform independence (Java virtual machine implements platform independence)

Support for web programming and convenience (Java was born to simplify web programming)

Support for multithreading (multithreading mechanism allows applications to execute multiple tasks in parallel at the same time)

Robustness (Java language strong typing mechanisms, exception handling, automatic garbage collection, etc.)

safety

What is bytecode? What are the biggest benefits of bytecode adoption?

Bytecode: Java source code compiled by the virtual machine compiler after the file (that is, extended to.class file), it is not targeted to any specific processor, only for virtual machines.

Benefits of bytecode adoption:

Java language solves the problem of low execution efficiency of traditional interpreted language to some extent by bytecode, while retaining the portability of interpreted language. Java programs are therefore more efficient to run on, and since bytecode is not specific to a particular machine, Java programs can run on many different computers without recompiling.

Let's look at Java's compiler and interpreter:

Java introduced the concept of virtual machine, that is, a virtual machine with a layer of abstraction added between the machine and the compiler. This virtual machine provides a common interface to compilers on any platform. The compiler only needs to be oriented to the virtual machine, generating code that the virtual machine can understand, and then the interpreter converts the virtual machine code into machine code for specific systems to execute. In Java, this code for virtual machines to understand is called bytecode (i.e., a file extended to.class), and it is not targeted at any particular processor, only to virtual machines. The interpreter for each platform is different, but the virtual machine implemented is the same. Java source code is compiled into bytecode by compiler, bytecode is interpreted and executed by virtual machine, virtual machine sends each bytecode to interpreter, interpreter translates it into machine code on specific machine, and then runs on specific machine. This is the explanation of compilation and interpretation coexistence of Java characteristics mentioned above.

Java source code---> compiler--->jvm executable Java bytecode (i.e. virtual instructions)--->jvm---> interpreter in jvm---> machine-executable binary machine code---> program execution. What is the main class of Java programs? What is the difference between the main classes of apps and Mini programs?

There can be multiple classes in a program, but only one class can be the main class. In Java applications, this main class refers to the class that contains the main() method. In Java Mini programs, the main class is a subclass that inherits from the system class JApplet or Applet. The main class of an application does not have to be public, but the main class of Mini programs does. The main class is the entry point for Java program execution.

What are the differences between Java applications and Mini programs?

Simply put, the application starts from the main thread (i.e., the main() method). Applet Mini programs do not have a main method, but are mainly embedded in the browser page to run (call init() thread or run() to start), embedded in the browser this point is similar to flash Mini games.

Difference between Java and C++

I know a lot of people haven't learned C++, but the interviewer just likes to compare Java and C++! No way!! Even if you haven't learned C++, you have to remember it!

Both object-oriented languages support encapsulation, inheritance, and polymorphism.

Java does not provide pointers to directly access memory, program memory is more secure

Java classes are single-inheritance, C++ supports multiple inheritance; although Java classes cannot inherit more, interfaces can inherit more.

Java has an automatic memory management mechanism that does not require programmers to manually release unused memory.

Oracle JDK vs OpenJDK

Oracle JDK versions will be released every three years, while OpenJDK versions will be released every three months;

OpenJDK is a reference model and is fully open source, whereas Oracle JDK is an implementation of OpenJDK and is not fully open source;

Oracle JDK is more stable than OpenJDK. OpenJDK and Oracle JDK have almost the same code, but Oracle JDK has more classes and some bug fixes. Therefore, if you want to develop enterprise/commercial software, I recommend Oracle JDK as it is thoroughly tested and stable. In some cases, some people mentioned that they might encounter many application crashes when using OpenJDK, but simply switching to Oracle JDK can solve the problem;

Oracle JDK provides better performance than OpenJDK in terms of responsiveness and JVM performance;

Oracle JDK does not provide long-term support for upcoming releases, and users must obtain support each time by updating to the latest version;

Oracle JDK is licensed under the Binary Code License Agreement, while OpenJDK is licensed under the GPL v2 license.

Basic syntax data types Java has what data types

Definition: Java language is a strongly typed language, for each kind of data are defined specific data types, in memory allocated different sizes of memory space.

classification

basic data types

integer type (byte,short,int,long)

floating-point type (float,double)

numeric

Character type (char)

Boolean

reference data types

class

interface

Array ([])

Java Basic Data Type Diagram

Can switch be used on bytes, long, String?

Before Java 5, in switch(expr), expr could only be byte, short, char, int. Since Java5, enumeration types have been introduced in Java, expr can also be enum types, and since Java 7, expr can also be strings, but long integers are not allowed in all current versions.

The most efficient way to calculate 2 times 8

2

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report