java 基础问题

java产生的背景

早期的Java

  • The Java language was initially called OAK.
  • Originally, it was developed for handling portable devices and set-top boxes. Oak was a massive failure.
  • In 1995, Sun changed the name to “Java” and modified the language to take advantage of the burgeoning www (World Wide Web) development business.
  • Later, in 2009, Oracle Corporation acquired Sun Microsystems and took ownership of three key Sun software assets: Java, MySQL, and Solaris.

总结:

c++不好用,缺少垃圾回收系统,还有可移植的安全性、分布程序设计、和多线程功能,并且没有跨平台的功能,总之就是不好用

James Gosling 试图修改和扩展C++的功能,他自己称这种新语言为C++ –

但是后来他放弃了,而是创造出一种全新的语言,命名为Oak(橡树),但是版权原因,后改名为Java

java的组成部分

https://www.guru99.com/java-platform.html

JDK (Java Development Kit):making Java applications,contains tools required to write Java programs and JRE to execute them

JRE is a piece of software that is designed to run other software. It contains the class libraries, loader class, and JVM.

JVM (Java Virtual Machine) is an engine that provides a runtime environment to drive the Java Code or applications

java的应用场景

  • It is used for developing Android Apps
  • Helps you to create Enterprise Software
  • Wide range of Mobile java Applications
  • Scientific Computing Applications
  • Use for Big Data Analytics
  • Java Programming of Hardware devices
  • Used for Server-Side Technologies like Apache, JBoss, GlassFish, etc.

java的优势

Simple, Robust, Portable, Platform-independent, Secured, High Performance, Multithreaded, Architecture Neutral, Object-Oriented, Interpreted, and Dynamic

How Java Virtual Machine works?

Step 1) The code to display the addition of two numbers is System.out.println(1+2), and saved as a .java file.

Step 2) Using the java compiler the code is converted into an intermediate code called the bytecode. The output is a .class file.

Step 3) This code is not understood by any platform, but only a virtual platform called the Java Virtual Machine.

Step 4) This Virtual Machine resides in the RAM of your operating system. When the Virtual Machine is fed with this bytecode, it identifies the platform it is working on and converts the bytecode into the native machine code.

While working on your PC or browsing the web, whenever you see either of these icons, be assured the java virtual machine is loaded into your RAM. But what makes Java lucrative is that code, once compiled, can run not only on all PC platforms but also on mobiles or other electronic gadgets supporting Java.

What is Java Virtual Machine & its Architecture

What is Java Virtual Machine & its Architecture

在这里插入图片描述

1) ClassLoader

The class loader is a subsystem used for loading class files. It performs three major functions viz. Loading, Linking, and Initialization.

2) Method Area

JVM Method Area stores class structures like metadata, the constant runtime pool, and the code for methods.

3) Heap

All the Objects, their related instance variables, and arrays are stored in the heap. This memory is common and shared across multiple threads.

4) JVM language Stacks

Java language Stacks store local variables, and it’s partial results. Each thread has its own JVM stack, created simultaneously as the thread is created. A new frame is created whenever a method is invoked, and it is deleted when method invocation process is complete.

A Java Thread is like a virtual CPU that can execute your Java code - inside your Java application. when a Java application is started its main() method is executed by the main thread - a special thread that is created by the Java VM to run your application. From inside your application you can create and start more threads which can execute parts of your application code in parallel with the main thread.

Java threads are objects like any other Java objects. Threads are instances of class java.lang.Thread, or instances of subclasses of this class. In addition to being objects, java threads can also execute code.

5) PC Registers

PC register store the address of the Java virtual machine instruction which is currently executing. In Java, each thread has its separate PC register.

6) Native Method Stacks

Native method stacks hold the instruction of native code depends on the native library. It is written in another language instead of Java.

7) Execution Engine

It is a type of software used to test hardware, software, or complete systems. The test execution engine never carries any information about the tested product.

8) Native Method interface

The Native Method Interface is a programming framework. It allows Java code which is running in a JVM to call by libraries and native applications.

9) Native Method Libraries

Native Libraries is a collection of the Native Libraries(C, C++) which are needed by the Execution Engine.

In order to write and execute a software program, you need the following

1) Editor – To type your program into, a notepad could be used for this

2) Compiler – To convert your high language program into native machine code

3) Linker – To combine different program files reference in your main program together.

4) Loader – To load the files from your secondary storage device like Hard Disk, Flash Drive, CD into RAM for execution. The loading is automatically done when you execute your code.

5) Execution – Actual execution of the code which is handled by your OS & processor.

Java code Compilation and Execution in Java VM

1)In your main, you have two methods f1 and f2.

  • The main method is stored in file a1.java
  • f1 is stored in a file as a2.java
  • f2 is stored in a file as a3.java

2)The compiler will compile the three files and produces 3 corresponding .class file which consists of BYTE code. Unlike C, no linking is done.

3)The Java VM or Java Virtual Machine resides on the RAM.

During execution, using the class loader the class files are brought on the RAM. The BYTE code is verified for any security breaches.

4)the execution engine will convert the Bytecode into Native machine code. This is just in time compiling. It is one of the main reason why Java is comparatively slow.

JIT or Just-in-time compiler is the part of the Java Virtual Machine (JVM). It interprets part of the Byte Code that has similar functionality at the same time.

Why is Java slow?

The two main reasons behind the slowness of Java are

  1. Dynamic Linking: Unlike C, linking is done at run-time, every time the program is run in Java.
  2. Run-time Interpreter: The conversion of byte code into native machine code is done at run-time in Java which furthers slows down the speed
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值