Home Java javaTutorial Summary of Java programming ideas

Summary of Java programming ideas

Jul 17, 2017 pm 01:57 PM
java Summarize notes

This chapter introduces the basic components of Java programs and realizes that almost everything in Java is an object.

Everything is an object

##Directory:

  • 2.1 Manipulate objects with references

  • 2.2 All objects must be created by you

  • 2.3 Never need to destroy objects

  • 2.4 Create new data types: classes

  • 2.5 Methods, parameters and return values

  • 2.6 Building a Java program

  • 2.7 Your first Java program

  • 2.8 Comments and embedded documentation

  • 2.9 Coding style

2.1 Manipulating objects with references

Everything is regarded as an object, and the manipulated identifier is actually a "reference" of the object. The remote control (reference) controls the TV (object). If you want to control the TV, you only need to use the remote control, and the remote control exists independently.

2.2 All objects must be created by you

Once you create a reference, you want it to be associated with a new Objects are associated, and the new operator is usually used to achieve this purpose.

String s = new String("Jiancheng");
Copy after login

 

五个不同的地方可以存储数据:

  • 寄存器:位于CPU内部,寄存器的数量极其有限,所以寄存器根据需求进行分配,速度最快。

  • 堆栈:位于通用RAM(随机访问寄存器)中,Java编译器必须知道存储在堆栈内所有数据的大小和生命周期,“堆栈指针”向下移动则分配新内存,向上移动则释放内存,速度仅次于寄存器,基本数据类型和引用存放在此。

  • 堆:位于RAM区,用于存放所有Java对象,编译器不用知道数据大小和生命周期.

  • 常量存储:常量值通常直接存放在程序代码内部。

  • 非RAM存储:完全存活在程序之外,不受程序的任何控制,例子是流对象持久化对象,在流对象中,对象转换成字节流,通常被发送到另一台机器。在"持久化"对象中,对象被存放于硬盘上,即使程序终止,它们仍可以保持自己的状态。

 9种基本类型:

 

boolean类型所占内存储空间的大小没有明确指定,仅定义为能够取字面值true或false。

高精度数字:

  • BigInteger:支持任意精度的整数

  • BigDecimal:支持任意精度的定点数

操作与对基本类型所能执行的操作相似,但必须以方法调用方式取代运算符方式来实现。

Java中的数组:
数组会被初始化,而且不能在它的范围之外被访问。这种范围检查,是以每个数组上少量的内存开销及运行时的下标检查为代价(换来安全性和效率)。

 2.3 永远不需要销毁对象

作用域:

------------------------------------------------------------------

对象的作用域:

Java的作用和基本类型差别很大,new创建一个Java对象后,它可以存活于作用域之外。只要你需要这个对象,就会一直保留下去,直到垃圾回收器辨别到该对象不会再被引用并释放该对象的内存空间,这样就消除了内存泄漏的问题。

2.4 创建新的数据类型:类

类决定了某一对象的外观与行为,确定了对象的类型。

基本成员默认值:

当变量作为类的成员使用时,Java才确保给定其默认值,来确保基本类型成员变量得到初始化(初始值可能不是你想要的,最好自己初始化)。注意默认初始化的方法不适用于非某个类的字段变量,忘记初始化,Java会在编译时给你返回一个错误。

2.6 构建一个Java程序

static关键字:

下面两种情况需要使用static

  • 只想为某特定域分配单一存储空间,而不去考虑究竟要创建多少对象。

  • 某个方法不与包含它的类的任何对象关联在一起,就是没有创建对象,也能够调用这个方法。

class StatiTest{  static i = 47; //可以直接StatiTest.i这样调用
}
Copy after login

StatiTest st1 = new StatiTest();
StatiTest st2 = new StatiTest();
where st1.i and st2.i point to the same storage space, so they have the same value.

static acts on a method. The difference is that it can be called without creating any object, class.method().

2.9 Coding style

## Camel case style:

  • class, the first letter of each word is capitalized

  • Methods, fields and objects, etc., the first letter of the first word is capitalized Lower case, the remaining first letters are capitalized

Summary:

This chapter is easy to understand and is useful for Java I have an overall understanding of language and some of its basic ideas, and I have been exposed to most knowledge points, but it is easy to forget the details, so it is okay to read more.


The above is the detailed content of Summary of Java programming ideas. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Square Root in Java Square Root in Java Aug 30, 2024 pm 04:26 PM

Guide to Square Root in Java. Here we discuss how Square Root works in Java with example and its code implementation respectively.

Perfect Number in Java Perfect Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Random Number Generator in Java Random Number Generator in Java Aug 30, 2024 pm 04:27 PM

Guide to Random Number Generator in Java. Here we discuss Functions in Java with examples and two different Generators with ther examples.

Armstrong Number in Java Armstrong Number in Java Aug 30, 2024 pm 04:26 PM

Guide to the Armstrong Number in Java. Here we discuss an introduction to Armstrong's number in java along with some of the code.

Weka in Java Weka in Java Aug 30, 2024 pm 04:28 PM

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Smith Number in Java Smith Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

Java Spring Interview Questions Java Spring Interview Questions Aug 30, 2024 pm 04:29 PM

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Break or return from Java 8 stream forEach? Break or return from Java 8 stream forEach? Feb 07, 2025 pm 12:09 PM

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

See all articles