當前位置:首頁 » 編程語言 » java欄位

java欄位

發布時間: 2022-01-07 23:54:08

java欄位和屬性的區別

private long id; 欄位(一般來說:屬性私有)
public long getId() { return id; } (getId,叫做得到屬性,get是得到,get後面的ID,小寫,叫做屬性)
public void setId(long id) {this.id = id; } (同上)

❷ java中欄位是什麼怎麼定義欄位欄位是變數嗎和變數 方法 屬性有什麼區別欄位有返回值嗎。。。

欄位就是成員變數,注意是成員變數,不是局部變數。欄位也就是屬性了,一個類的屬性。
只是叫法不同,java的API中一般叫成員變數就欄位,有時也叫域。而我們一般的編程的時候,就欄位叫成員變數

補------------
out就是一個欄位,也就是是System類的一個成員變數。只不過個這成員變數是一個對象,也就是out是一個 PrintStream類的對象。這就是在一個類里執有其它類的對象的用法

❸ 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 ring 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的讀寫

資料庫text對應java什麼欄位

如果你是自動生成資料庫表和欄位的話建議您在對應的String欄位上面加上

@Column(nullable = false, columnDefinition = "TEXT")

這樣資料庫欄位類型就是TEXT,而不是VARCHAR,默認都是VARCHAR的

❺ java如何獲得資料庫表中各欄位的欄位名

Java獲取資料庫的表中各欄位的欄位名,代碼如下:

importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.ResultSet;
importjava.sql.PreparedStatement;
importjava.sql.ResultSetMetaData;
importjava.sql.SQLException;
publicclassTestDemo{
(){
Connectionconn=null;
try{
Class.forName("com.mysql.jdbc.Driver");
Stringurl="jdbc:mysql://資料庫IP地址:3306/資料庫名稱";
Stringuser="資料庫用戶名";
Stringpass="資料庫用戶密碼";
conn=DriverManager.getConnection(url,user,pass);
}catch(ClassNotFoundExceptione){
e.printStackTrace();
}catch(SQLExceptione){
e.printStackTrace();
}
returnconn;
}
publicstaticvoidmain(String[]args){
Connectionconn=getConnection();
Stringsql="select*fromAccessType";
PreparedStatementstmt;
try{
stmt=conn.prepareStatement(sql);
ResultSetrs=stmt.executeQuery(sql);
ResultSetMetaDatadata=rs.getMetaData();
for(inti=1;i<=data.getColumnCount();i++){
//獲得所有列的數目及實際列數
intcolumnCount=data.getColumnCount();
//獲得指定列的列名
StringcolumnName=data.getColumnName(i);
//獲得指定列的列值
intcolumnType=data.getColumnType(i);
//獲得指定列的數據類型名
StringcolumnTypeName=data.getColumnTypeName(i);
//所在的Catalog名字
StringcatalogName=data.getCatalogName(i);
//對應數據類型的類
StringcolumnClassName=data.getColumnClassName(i);
//在資料庫中類型的最大字元個數
intcolumnDisplaySize=data.getColumnDisplaySize(i);
//默認的列的標題
StringcolumnLabel=data.getColumnLabel(i);
//獲得列的模式
StringschemaName=data.getSchemaName(i);
//某列類型的精確度(類型的長度)
intprecision=data.getPrecision(i);
//小數點後的位數
intscale=data.getScale(i);
//獲取某列對應的表名
StringtableName=data.getTableName(i);
//是否自動遞增
booleanisAutoInctement=data.isAutoIncrement(i);
//在資料庫中是否為貨幣型
booleanisCurrency=data.isCurrency(i);
//是否為空
intisNullable=data.isNullable(i);
//是否為只讀
booleanisReadOnly=data.isReadOnly(i);
//能否出現在where中
booleanisSearchable=data.isSearchable(i);
System.out.println(columnCount);
System.out.println("獲得列"+i+"的欄位名稱:"+columnName);
System.out.println("獲得列"+i+"的類型,返回SqlType中的編號:"+columnType);
System.out.println("獲得列"+i+"的數據類型名:"+columnTypeName);
System.out.println("獲得列"+i+"所在的Catalog名字:"+catalogName);
System.out.println("獲得列"+i+"對應數據類型的類:"+columnClassName);
System.out.println("獲得列"+i+"在資料庫中類型的最大字元個數:"+columnDisplaySize);
System.out.println("獲得列"+i+"的默認的列的標題:"+columnLabel);
System.out.println("獲得列"+i+"的模式:"+schemaName);
System.out.println("獲得列"+i+"類型的精確度(類型的長度):"+precision);
System.out.println("獲得列"+i+"小數點後的位數:"+scale);
System.out.println("獲得列"+i+"對應的表名:"+tableName);
System.out.println("獲得列"+i+"是否自動遞增:"+isAutoInctement);
System.out.println("獲得列"+i+"在資料庫中是否為貨幣型:"+isCurrency);
System.out.println("獲得列"+i+"是否為空:"+isNullable);
System.out.println("獲得列"+i+"是否為只讀:"+isReadOnly);
System.out.println("獲得列"+i+"能否出現在where中:"+isSearchable);
}
}catch(SQLExceptione){
e.printStackTrace();
}
}
}

❻ JAVA里的欄位是什麼意思

sm yisd什麼欄位?

❼ java"欄位"啥意思

欄位也稱為屬性,相當於一個類的成員變數(相當與C++中)
因為out是System類的PrintStream類型的靜態屬性(欄位),所以可以直接拿來用而不用實例化對象,定向到控制台輸出

❽ java中,欄位是什麼

對「網友採納」的答案加一句給以後搜索的人看:欄位是屬於類本身的,也就是類的成員變數,用Static修飾。它可以是一個類,比如System的out欄位就是PrintStream的對象

❾ JAVA怎麼截取欄位

String str = "12.66";
str.substring(0,2);

❿ java中的屬性和欄位的區別

1、Java中的屬性和欄位有什麼區別?
答:Java中的屬性,通常可以理解為get和set方法。而欄位,通常叫做「類成員」。

這兩個概念是完全不同的。

屬性只局限於類中方法的聲明,並不與類中其他成員相關。例如:
void setA(String s){}
String getA(){}
當一個類中擁有這樣一對方法時,我們可以說,這個類中擁有一個可讀寫的a屬性(注意是小寫a)。如果去掉了set的方法,則是可讀屬性,反之亦然。

類成員(欄位),通常是在類中定義的類成員變數,例如:
public class A{
private String s = "123";
}
我們可以說A類中有一個成員變數叫做s。

熱點內容
蘋果連接id伺服器出錯是怎麼回事 發布:2024-09-20 08:01:07 瀏覽:502
編程鍵是什麼 發布:2024-09-20 07:52:47 瀏覽:651
學考密碼重置要求的證件是什麼 發布:2024-09-20 07:19:46 瀏覽:477
電腦主伺服器怎麼開機 發布:2024-09-20 07:19:07 瀏覽:728
2022款瑞虎升級哪些配置 發布:2024-09-20 06:59:07 瀏覽:264
資料庫與asp 發布:2024-09-20 06:55:25 瀏覽:727
python解釋編譯 發布:2024-09-20 06:52:57 瀏覽:648
舞蹈豐收腳本 發布:2024-09-20 06:36:26 瀏覽:595
linux進程埠號 發布:2024-09-20 06:36:11 瀏覽:80
派派怎麼改密碼忘了 發布:2024-09-20 06:25:49 瀏覽:780