Java驱动程序? [英] Java Driver Program?

查看:143
本文介绍了Java驱动程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对java类和驱动程序感到困惑。驱动程序代码的语法是什么,应该和不应该包含哪些内容?对于驱动程序,我们可能需要在其中包含一个主程序,但是对于java类,我们不需要有任何......?
我是否需要为java类和驱动程序或仅在驱动程序中使用它:

I'm really confused about java classes and driver programs. What is the syntax of the code for a driver program and what should and should not be inside it? For the driver program we need perhaps to have a main program inside it but what about the java class , don't we need to have any ...? Do i need to have this for both the java class and the driver program or only in the driver:

public static void main(String [] args) {
}

public static void main(String[] args) { }

推荐答案

从这里引用:

什么是驱动程序类? (Java)


驱动程序类通常只是包含main的类。在一个
的真实项目中,你可能经常有很多驱动程序类来测试
和诸如此类的东西,或者你可以在你的任何对象中构建一个main,并且
通过你的IDE选择runnable类,或简单地指定
java classname。

A "Driver class" is often just the class that contains a main. In a real project, you may often have numerous "Driver classes" for testing and whatnot, or you can build a main into any of your objects and select the runnable class through your IDE, or by simply specifying "java classname."

示例:

这不是驱动程序类,因为它不包含任何main方法。在这种情况下,它具有方法hello:

This is not a driver class since it doesn't contain any main method. In this case, it has the method "hello":

public class HelloWorld {
  public void hello() {
    System.out.println("Hello, world!");
  }
}

与此相比 - 这是一个驱动程序类,因为它包含一个主要方法,运行的类 HelloWorld:

versus this one - which is a driver class since it contains a main method, and is the class that runs HelloWorld:

public class HelloWorldDriver {
  public static void main(String[] args) {
    HelloWorld sayhello = new HelloWorld();
    sayhello.hello();
  }
}

因此名称为驱动程序类 - 作为类HelloWorldDriver drives 或更确切地说,控制 HelloWorld类的实例化和使用。

Hence the name "driver class" - as the class HelloWorldDriver "drives" or rather, controls the instantiation and usage of the class HelloWorld.

这篇关于Java驱动程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆