首页编程java编程java中字段是什么意思(java "字段"啥意思)

java中字段是什么意思(java "字段"啥意思)

编程之家2023-10-1289次浏览

大家好,关于java中字段是什么意思很多朋友都还不太明白,不过没关系,因为今天小编就来为大家分享关于java "字段"啥意思的知识点,相信应该可以解决大家的一些困惑和问题,如果碰巧可以解决您的问题,还望关注下本站哦,希望对各位有所帮助!

java中字段是什么意思(java "字段"啥意思)

java中的属性是什么意思

属性( attribute)是编程语言结构的任意特性。属性在其包含的信息和复杂性等方面变化很大,特别是当它们能确定时翻译/执行过程的时间。属性的典型例子有:变量的数据类型、表达式的值、存储器中变量的位置、程序的目标代码、数的有效位数。

java中常用属性有:

1,file.separator:文件分隔符。

java中字段是什么意思(java "字段"啥意思)

2,java.class.path: java路径。

2,user.home:用户注目录。

java中类定义的属性是什么意思

java是面向对象编程的语言

java中字段是什么意思(java "字段"啥意思)

什么叫对象?

publicclassPerson{

privatestringname;

}

什么叫类?

Person是定义了一个人的java类-----它是一类事物的统称

既然是人了,那就应该有名字吧,name就是person的一个属性,比如还有年龄啊,性别啊什么的

实例化对象---就是通过类(Person)具体拿到某一个人

比如Personp=newPerson("张三")

张三就是Person中具体的一个对象

这就是面相对象编程明白吧

请问java中的field是什么意思

Java中Field提供有关类或接口的单个字段的信息,以及对它的动态访问权限。反射的字段可能是一个类字段或实例字段。Field是成员变量的意思。Field也是一个类,该类位于java.lang.reflect包下。

Field使用示例:

class Test{

private int a;//private field私有域

protected double b;//protected field保护域

public String c;//public field公共域

Testd;//default access field默认访问域

public static Object e;//public static field公共静态域

......

}

扩展资料

1.获取变量的类型。

Field.getType():返回这个变量的类型。

Field.getGenericType():如果当前属性有签名属性类型就返回,否则就返回 Field.getType()。

isEnumConstant():判断这个属性是否是枚举类。

2.获取成员变量的修饰符。

Field.getModifiers()以整数形式返回由此 Field对象表示的字段的 Java语言修饰符。

3.获取和修改成员变量的值。

getName():获取属性的名字。

get(Object obj)返回指定对象obj上此 Field表示的字段的值。

set(Object obj, Object value)将指定对象变量上此 Field对象表示的字段设置为指定的新值。

参考资料来源:Oracle-Java

java "字段"啥意思

public final static InputStream in= nullInputStream();

nullInputStream是这样实现的:

private static InputStream nullInputStream() throws NullPointerException{

if(currentTimeMillis()> 0)

return null;

throw new NullPointerException();

}

他不是返回null,就是抛出异常,如何初始化in呢?

解答:

看了一下java.lang.System的源代码.

System类里有大量的native方法,是调用本地代码的,这些代码很可能是由虚拟机来调用的.

System类的开头有一段:

static{

registerNatives();

}

这段代码会在虚拟机启动的时候就执行,它在虚拟机里注册System需要使用的一些本地代码

比如:

private static native Properties initProperties(Properties props);

private static native void setOut0(PrintStream out);

在windows下的话,它就告诉虚拟机到哪个dll文件里去找相应的实现

>然而,我知道out是一个PrintStream的对象,但我查看了有关的原代码:public final static PrintStream out= nullPrintStream();

>public final static InputStream in= nullInputStream();

在nullInputStream()方法里有注释解释为什么会设置为空:

/**

* The following two methods exist because in, out, and err must be

* initialized to null. The compiler, however, cannot be permitted to

* inline access to them, since they are later set to more sensible values

* by initializeSystemClass().

*/

private static InputStream nullInputStream() throws NullPointerException{

if(currentTimeMillis()> 0)

return null;

throw new NullPointerException();

}

也就说in, out, and err初始化为null,然后会在后来由initializeSystemClass()方法类初始化成有意义的值

/**

* Initialize the system class. Called after thread initialization.

*/

private static void initializeSystemClass(){

props= new Properties();

initProperties(props);

sun.misc.Version.init();

FileInputStream fdIn= new FileInputStream(FileDescriptor.in);

FileOutputStream fdOut= new FileOutputStream(FileDescriptor.out);

FileOutputStream fdErr= new FileOutputStream(FileDescriptor.err);

setIn0(new BufferedInputStream(fdIn));!!!

setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true));!!!

setErr0(new PrintStream(new BufferedOutputStream(fdErr, 128), true));!!!

// Enough of the world is now in place that we can risk

// initializing the logging configuration.

try{

java.util.logging.LogManager.getLogManager().readConfiguration();

} catch(Exception ex){

// System.err.println("Can′t read logging configuration:");

// ex.printStackTrace();

}

// Load the zip library now in order to keep java.util.zip.ZipFile

// from trying to use itself to load this library later.

loadLibrary("zip");

// Subsystems that are invoked during initialization can invoke

// sun.misc.VM.isBooted() in order to avoid doing things that should

// wait until the application class loader has been set up.

sun.misc.VM.booted();

}

in,out,err就是在以上方法以下三条语句里初始化的.

setIn0(new BufferedInputStream(fdIn));!!!

setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true));!!!

setErr0(new PrintStream(new BufferedOutputStream(fdErr, 128), true));!!!

private static native void setIn0(InputStream in);

~~~~~~~

这是个native函数,是前面registerNatives()的时候注册了的.这个函数应该是把实际连接到输入输出设备的句柄传给虚拟机并赋值给in,out,err

至于:

>InputStream是个抽象的类,怎么能使用char=(char)System.in.read()读入一个字符

我想你还没有明白什么是面向对象.

看看下面代码,我用OutputStream(也是抽象类,跟InputStream对应的输出类)以方便演示:

import java.io.IOException;

import java.io.OutputStream;

public class HelloWorld{

public OutputStream out=null;

public void setOutputStream(OutputStream out){

this.out=out;

}

public static void main(String[] args) throws IOException{

HelloWorld h=new HelloWorld();

PrintStream myOut=System.out;//System.out是一个PrintStream

h.setOutputStream(myOut);

h.out.write("hello,world".getBytes());//一般没人这么写的

}

}

以上代码执行后会输出hello,world

h.out是OutputStream,也是个抽象类,为什么能write(o)呢?

因为PrintStream是OutputStream的子类,所以能被"当作"OutputStream传给h.setOutputStream(myOut);

h.out.write执行的时候实际上是调用这个传进来的PrintStream实例的write方法

同样System.in和out肯定也是在initializeSystemClass()的时候被赋予了一个实际的可用的子类

要能体会到面向对象的好处,就要逐渐适应"对接口编程"的思想,相同接口的对象可以根据需要方便的替换.

比如,我刚才传了一个PrintStream,因此HelloWorld输出到了屏幕上.我如果传给OutputStream的另一个子类FileOutputStream,就会输出到文件里

>还有为什么不是说字符流:writer和reader一般用于UniCode的读写吗?为什么键盘的输入用reader类呢?

不知道你在哪里看到说writer和reader一般用于UniCode的读写

关于java中字段是什么意思到此分享完毕,希望能帮助到您。

java 依据什么来创建类,学习java后要考什么证吗java中i 的意思是什么意思是什么意思,java中i++是什么意思