導航:首頁 > 編程語言 > noargumentjava

noargumentjava

發布時間:2025-07-13 05:36:15

⑴ 常見的java異常有哪些都是什麼意思

1、ArithmeticException - 算術運算中,被0除或模除。

2、 - 數組越界訪問。

3、ArrayStoreException - 數據存儲異常,寫數組操作時,對象或數據類型不兼容。

4、ClassCastException - 類型轉換異常。

5、IllegalArgumentException - 方法的參數無效。

6、IllegalThreadStateException - 試圖非法改變線程狀態,比方說試圖啟動一已經運行的線程。

7、NullPointerException - 試圖訪問一空對象的變數、方法或空數組的元素

8、NumberFormatException - 數據格式異常,試圖把一字元串非法轉換成數值(或相反)。

9、SecurityException - 如果Applet試圖執行一被WWW瀏覽器安全設置所禁止的操作。

10、 - 如改變了某一類定義,卻沒有重新編譯其他引用了這個類的對象。如某一成員變數的聲明被從靜態改變為非靜態,但其他引用了這個變數的類卻沒有重新編譯,或者相反。

11、OutOfMemoryException - 內存不足,通常發生於創建對象之時。

12、NoClassDefFoundException - JAVA運行時系統找不到所引用的類。

13、IncompatibleTypeException - 試圖實例化一個介面,Java運行時系統將拋出這個異常。

14、UnsatisfiedLinkException - 如果所需調用的方法是C函數,但Java運行時系統卻無法連接這個函數。

15、InternalException - 系統內部故障所導致的異常情況,可能是因為Java運行時系統本身的原因。如果發現一可重現的InternalException,可以直接給Sun公司發電郵[email protected]

⑵ java小程序源代碼,簡單點的,100多行,誰有啊

// My car shop.java

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.border.*;

public class carshop extends JFrame
{
// JPanel to hold all pictures
private JPanel windowJPanel;
private String[] cars = { "","阿斯頓馬丁", "美洲虎", "凱迪拉克",
"羅孚", "勞斯萊斯","別克"};
private int[] jiage = { 0,150000, 260000, 230000,
140000, 290000, 150000};
// JLabels for first snack shown
private JLabel oneJLabel;
private JLabel oneIconJLabel;

// JLabels for second snack shown
private JLabel twoJLabel;
private JLabel twoIconJLabel;

// JLabels for third snack shown
private JLabel threeJLabel;
private JLabel threeIconJLabel;

// JLabels for fourth snack shown
private JLabel fourJLabel;
private JLabel fourIconJLabel;

// JLabels for fifth snack shown
private JLabel fiveJLabel;
private JLabel fiveIconJLabel;

// JLabels for sixth snack shown
private JLabel sixJLabel;
private JLabel sixIconJLabel;

// JTextField for displaying snack price
private JTextArea displayJTextArea;

// JLabel and JTextField for user input
private JLabel inputJLabel;
private JComboBox selectCountryJComboBox;

private JLabel inputJLabel2;
private JTextField inputJTextField2;

// JButton to enter user input
private JButton enterJButton;

//JButton to clear the components
private JButton clearJButton;

// no-argument constructor
public carshop()
{
createUserInterface();
}

// create and position GUI components; register event handlers
private void createUserInterface()
{
// get content pane for attaching GUI components
Container contentPane = getContentPane();

// enable explicit positioning of GUI components
contentPane.setLayout( null );

// set up windowJPanel
windowJPanel = new JPanel();
windowJPanel.setBounds( 10, 20, 340, 200 );
windowJPanel.setBorder( new LineBorder( Color.BLACK ) );
windowJPanel.setLayout( null );
contentPane.add( windowJPanel );

// set up oneIconJLabel
oneIconJLabel = new JLabel();
oneIconJLabel.setBounds( 10, 20, 100, 65 );
oneIconJLabel.setIcon( new ImageIcon( "images/阿斯頓馬丁.jpg" ) );
windowJPanel.add( oneIconJLabel );

// set up oneJLabel
oneJLabel = new JLabel();
oneJLabel.setBounds( 10, 60, 100, 70 );
oneJLabel.setText( "阿斯頓馬丁" );
oneJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( oneJLabel );

// set up twoIconJLabel
twoIconJLabel = new JLabel();
twoIconJLabel.setBounds( 120, 20, 100, 65 );
twoIconJLabel.setIcon( new ImageIcon( "images/美洲虎.jpg" ) );
windowJPanel.add( twoIconJLabel );

// set up twoJLabel
twoJLabel = new JLabel();
twoJLabel.setBounds( 110, 60, 100, 70 );
twoJLabel.setText( "美洲虎" );
twoJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( twoJLabel );

// set up threeIconJLabel
threeIconJLabel = new JLabel();
threeIconJLabel.setBounds( 230, 20, 100, 65 );
threeIconJLabel.setIcon( new ImageIcon(
"images/凱迪拉克.jpg" ) );
windowJPanel.add( threeIconJLabel );

// set up threeJLabel
threeJLabel = new JLabel();
threeJLabel.setBounds( 230, 60, 100, 70);
threeJLabel.setText( "凱迪拉克" );
threeJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( threeJLabel );

// set up fourIconJLabel
fourIconJLabel = new JLabel();
fourIconJLabel.setBounds( 10, 100, 100, 65 );
fourIconJLabel.setIcon( new ImageIcon( "images/羅孚.jpg" ) );
windowJPanel.add( fourIconJLabel );

// set up fourJLabel
fourJLabel = new JLabel();
fourJLabel.setBounds( 10, 150, 50, 70 );
fourJLabel.setText( "羅孚" );
fourJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( fourJLabel );

// set up fiveIconJLabel
fiveIconJLabel = new JLabel();
fiveIconJLabel.setBounds( 120, 100, 100, 65 );
fiveIconJLabel.setIcon( new ImageIcon(
"images/勞斯萊斯.jpg" ) );
windowJPanel.add( fiveIconJLabel );

// set up fiveJLabel
fiveJLabel = new JLabel();
fiveJLabel.setBounds( 110, 150, 100, 70 );
fiveJLabel.setText( "勞斯萊斯" );
fiveJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( fiveJLabel );

// set up sixIconJLabel
sixIconJLabel = new JLabel();
sixIconJLabel.setBounds( 230, 100, 100, 65 );
sixIconJLabel.setIcon( new ImageIcon( "images/別克.jpg" ) );
windowJPanel.add( sixIconJLabel );

// set up sixJLabel
sixJLabel = new JLabel();
sixJLabel.setBounds( 230, 150, 100, 70 );
sixJLabel.setText( "別克" );
sixJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( sixJLabel );

// set up enterJButton
enterJButton = new JButton();
enterJButton.setBounds( 390, 160, 135, 30 );
enterJButton.setText( "Enter" );
contentPane.add( enterJButton );
enterJButton.addActionListener(

new ActionListener() // anonymous inner class
{
// event handler called when enterJButton is clicked
public void actionPerformed( ActionEvent event )
{
enterJButtonActionPerformed( event );
}

} // end anonymous inner class

); // end call to addActionListener

// set up clearJButton
clearJButton = new JButton();
clearJButton.setBounds( 390, 200, 135, 30 );
clearJButton.setText( "Clear" );

contentPane.add( clearJButton );

// set up inputJLabel

inputJLabel = new JLabel();
inputJLabel.setBounds( 390, 25, 135, 25 );
inputJLabel.setText( "Please make selection:" );
contentPane.add( inputJLabel );

selectCountryJComboBox = new JComboBox( cars );
selectCountryJComboBox.setBounds( 390, 50, 135, 21 );
selectCountryJComboBox.setMaximumRowCount( 3 );
contentPane.add( selectCountryJComboBox );
// set up inputJTextField

inputJLabel2 = new JLabel();
inputJLabel2.setBounds( 390, 80, 150, 20 );
inputJLabel2.setText( "Input the Numble:" );
contentPane.add( inputJLabel2 );

// set up inputJTextField
inputJTextField2 = new JTextField();
inputJTextField2.setBounds( 390, 100, 135, 25 );
inputJTextField2.setHorizontalAlignment( JTextField.RIGHT );
contentPane.add( inputJTextField2 );

clearJButton.addActionListener(

new ActionListener() // anonymous inner class
{
// event handler called when clearJButton is clicked
public void actionPerformed( ActionEvent event )
{
clearJButtonActionPerformed( event );
}

} // end anonymous inner class
);

// set up displayJTextField
displayJTextArea = new JTextArea();
displayJTextArea.setBounds( 10, 237,515, 70 );
displayJTextArea.setEditable( false );
contentPane.add( displayJTextArea );
// set properties of application's window
setTitle( "My car Shop" ); // set title bar string
setSize( 550, 360 ); // set window size
setVisible( true ); // display window

} // end method createUserInterface

private void clearJButtonActionPerformed( ActionEvent event )
{
// clear the JTextFields
inputJTextField2.setText( "" );
displayJTextArea.setText("");

} // end method clearJButtonActionPerformed

private void enterJButtonActionPerformed( ActionEvent event )
{
double z;
double c;
int x;
int y;
x=selectCountryJComboBox.getSelectedIndex();
y=Integer.parseInt(inputJTextField2.getText());
double discountRate;
int amount = Integer.parseInt( inputJTextField2.getText());
switch (amount/5)
{
case 0:
discountRate = 0;
break;

case 1:
discountRate = 1;
break;

case 2:
discountRate = 2;
break;
case 3:
discountRate = 3;
break;

default:
discountRate = 4;

} // end switch statement
c=1-discountRate/100;
z=jiage[x]*y*c;
displayJTextArea.append("你選擇的是:"+cars[x]+";"+
"它的單價是:"+jiage[x]+";" +"你購買該產品的數量是:"+y+"," +"\n"+"該數量的折扣是:"
+discountRate + " %"+";"+"本次消費的總價格是:"+z+"元"+"!"+"\n");

}
public static void main( String args[] )
{
carshop application = new carshop();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

} // end method main

} // end class carshop

⑶ 常見JAVA運行時異常有哪些

1,java.lang.NullPointerException

這個異常的解釋是 "程序遇上了空指針 ",簡單地說就是調用了未經初始化的對象或者是不存在的對象,這個錯誤經常出現在創建圖片,調用數組這些操作中,比如圖片未經初始化,或者圖片創建時的路徑錯誤等等。

2,java.lang.ClassNotFoundException

異常的解釋是"指定的類不存在",這里主要考慮一下類的名稱和路徑是否正確即可

3,java.lang.

這個異常的解釋是"數組下標越界",現在程序中大多都有對數組的操作,因此在調用數組的時候一定要認真檢查,看自己調用的下標是不是超出了數組的范圍,一般來說,顯示(即直接用常數當下標)調用不太容易出這樣的錯,但隱式(即用變數表示下標)調用就經常出錯了.

4,java.lang.NoSuchMethodError

方法不存在錯誤。當應用試圖調用某類的某個方法,而該類的定義中沒有該方法的定義時拋出該錯誤。

5,java.lang.IndexOutOfBoundsException

索引越界異常。當訪問某個序列的索引值小於0或大於等於序列大小時,拋出該異常。

6,java.lang.NumberFormatException

數字格式異常。當試圖將一個String轉換為指定的數字類型,而該字元串確不滿足數字類型要求的格式時,拋出該異常。

7,java.sql.SQLException

Sql語句執行異常

8,java.io.IOException

輸入輸出異常

9,java.lang.IllegalArgumentException

方法參數錯誤

10java.lang.IllegalAccessException

無訪問許可權異常

(3)noargumentjava擴展閱讀:

Java技術應用領域:

1、Android應用

許多的 Android應用都是Java程序員開發者開發。雖然 Android運用了不同的JVM以及不同的封裝方式,但是代碼還是用Java語言所編寫。相當一部分的手機中都支持JAVA游戲,這就使很多非編程人員都認識了JAVA。

2、在金融業應用的伺服器程序

Java在金融服務業的應用非常廣泛,很多第三方交易系統、銀行、金融機構都選擇用Java開發,因為相對而言,Java較安全 。大型跨國投資銀行用Java來編寫前台和後台的電子交易系統,結算和確認系統,數據處理項目以及其他項目。

3、網站

Java 在電子商務領域以及網站開發領域占據了一定的席位。開發人員可以運用許多不同的框架來創建web項目,SpringMVC,Struts2.0以及frameworks。即使是簡單的 servlet,jsp和以struts為基礎的網站在政府項目中也經常被用到。例如醫療救護、保險、教育、國防以及其他的不同部門網站都是以Java為基礎來開發的。

4、嵌入式領域

Java在嵌入式領域發展空間很大。在這個平台上,只需130KB就能夠使用Java技術(在智能卡或者感測器上)。

5、大數據技術

Hadoop以及其他大數據處理技術很多都是用Java,例如Apache的基於Java的HBase和Accumulo以及 ElasticSearchas。

6、高頻交易的空間

Java平台提高了這個平台的特性和即使編譯,他同時也能夠像 C++ 一樣傳遞數據。正是由於這個原因,Java成為的程序員編寫交易平台的語言,因為雖然性能不比C++,但開發人員可以避開安全性,可移植性和可維護性等問題。

7、科學應用

Java在科學應用中是很好選擇,包括自然語言處理。最主要的原因是因為Java比C++或者其他語言相對其安全性、便攜性、可維護性以及其他高級語言的並發性更好。

⑷ 在Java中使用鍵盤輸入數據的幾種方法

在Java中,有多種方法可以實現鍵盤輸入數據,以下是一些常用的技巧:
1. 使用控制台輸入數據
1.1. 使用主方法的形式參數
在Java中,可以通過`main(String[] args)`方法接受命令行參數。
```java
package InputTest;
public class DataKeyboardInput1 {
/**
* 使用主方法的形式參數來輸入數據
* DataKeyboardInput1.java
* @param args
*/
public static void main(String[] args) {
// 輸出傳遞給程序的第一個參數
if (args.length > 0) {
System.out.println(args[0]);
} else {
System.out.println("No argument provided.");
}
}
}
```
在命令行中運行程序並傳遞參數:`java DataKeyboardInput1 HelloWorld`,輸出將是 `HelloWorld`。
1.2. 利用位元組輸入流
使用`System.in`作為`InputStream`的實例,調用`read()`方法讀取數據。
```java
package InputTest;
import java.io.*;
public class DataKeyboardInput2 {
/**
* 利用位元組輸入流來輸入數據
* DataKeyboardInput2.java
* @param args
*/
public static void main(String[] args) {
// 定義位元組數組以讀取輸入
byte[] buf = new byte[10];
String str;
int num = 0;
try {
// 讀取到位元組數組中
int count = System.in.read(buf);
// 轉換為字元串
str = new String(buf, 0, count);
// 轉換為整型數據
num = Integer.parseInt(str.trim());
} catch (Exception e) {
System.out.print(e);
}
System.out.println(num);
}
}
```
1.3. 利用字元輸入流
`BufferedReader`類提供了緩沖字元輸入流的功能,常用`readLine()`方法讀取一行文本。
```java
package InputTest;
import java.io.*;
public class DataKeyboardInput3 {
/**
* 利用字元輸入流來進行輸入處理
* @param args
*/
public static void main(String[] args) throws IOException {
// 使用BufferedReader讀取輸入
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str;
int num = 0;
try {
str = br.readLine();
num = Integer.parseInt(str);
} catch (IOException e) {
System.out.println(e.toString());
}
System.out.println(num);
}
}
```
1.4. 利用文本掃描類
`Scanner`類可以從字元串中解析出不同類型的數據,使用正則表達式進行分隔。
```java
package InputTest;
import java.util.Scanner;
public class DataKeyboardInput4 {
/**
* 利用文本掃描類來進行輸入處理
* @param args
*/
public static void main(String[] args) {
// 使用Scanner類讀取輸入
Scanner input = new Scanner(System.in);
int num = input.nextInt();
System.out.println(num);
}
}
```
2. 對話框輸入數據
使用`JOptionPane`創建輸入對話框,實現鍵盤輸入。
```java
package InputTest;
import javax.swing.JOptionPane;
public class DataInputDialog {
/**
* 對話框輸入數據
* @param args
*/
public static void main(String[] args) {
// 使用JOptionPane顯示輸入對話框
String str;
str = JOptionPane.showInputDialog("input data:");
if (str != null) {
int num = Integer.parseInt(str);
System.out.println(num);
}
}
}
```
以上示例代碼展示了在Java中獲取用戶輸入的幾種不同方式。

閱讀全文

與noargumentjava相關的資料

熱點內容
伺服器如何支持大量數據的讀寫 瀏覽:599
汽車壓縮機磁吸不轉 瀏覽:547
python做網站登錄 瀏覽:240
查看javaapi 瀏覽:952
編程貓電子表格 瀏覽:523
扣扣如何解除綁定的app 瀏覽:779
樂橙監控app如何用 瀏覽:196
編程最重要的是什麼 瀏覽:972
excel函數大全pdf 瀏覽:525
便宜雲伺服器服務 瀏覽:111
三星pdf軟體 瀏覽:290
子菜單里建立文件夾 瀏覽:777
用命令方塊驅除生物 瀏覽:723
老男孩python怎麼樣 瀏覽:86
為什麼python中etree報錯 瀏覽:958
普米康APP怎麼下載 瀏覽:877
抖音小店怎麼看加密訂單的信息 瀏覽:683
linux時間同步設置 瀏覽:462
數控車床實驗編程 瀏覽:109
百分三百的演算法 瀏覽:994