走上开放之路:Windows开发人员的Java Web支持基础(一) - 编程入门网
Java Strings are created and how
* String methods can be used to create
* new String objects. Notice that when you
* call a String method like toUpperCase()
* the original String is not modified. To
* actually change the value of the original
* String, you have to assign the new
* String back to the original reference.
*/
public class StringTest {
public static void main(String[] args) {
String str1 = "Hi there";
String str2 = new String("Hi there");
// Display true if str1 and str2 have the value
System.out.println (str1.equals(str2));
// A new uppercase version of str1
System.out.println(str1.toUpperCase());
// A new lowercase version of str2
System.out.println(str1.toLowerCase ());
System.out.println(str1.substring(1,4));
// A new version of str1 w/o any trailing whitespace chars
System.out.println(str1.trim());
// Display true if str1 start with "Hi"
System.out.println(str1.startsWith("Hi"));
// Display true if str1 ends with "there"
System.out.println(str1.endsWith("there"));
// Replace all i''s with o''s
System.out.println(str1.replace(''i'', ''o''));
}
}
走上开放之路:Windows开发人员的Java Web支持基础(一)(8)时间:2011-04-30 未知 Mark Webermain() 方法 要在命令行中作为应用程序运行的 Java 类必须定义一个 main() 方法才能运行。在 Java 代码中, main() 方法遵循一个严格的命名约定。您可以按照下面的方式声明 main() 方法:
注意 : 您可以保留 public 和 static 修饰符,您也可以将 String 数组命名为任何您喜欢的名 字。然而要记住上面的格式是常规的用法。并不是所有的类都需要一个 main() 方法 —— 只有那些从命令行中运行的程序才需要。一个典型的 Java 应用程序有一个 具有 main() 方法的类和其他几个没有 main() 方法的支持类。 包 像 Java 这种面向对象的语言有助于促进类的重用。由于大部分程序员在自己的类中 都使用非常简单的描述性名字(例如 Invoice 或 User ),因此在重用他人提供的资源时命 名发生冲突的可能性就会很高。Java 语言通过让每一个类都属于一个 包 来解决这个问题。 您可以同时使用不同包中的同名类。要将一个类与一个包关联在一起,您必须在类的源代码 中的第一行就使用 package 语句进行声明。下面是一个例子: package com.ibm.training; 按照约定,您的包名的前缀要采用 Internet 域名反转的形式(例如 com.yourco.somepackage )。要使用其他包中的类,您有两种选择。第一种选择是使用该类 的全名,其中包括包名。清单 6 给出了一个例子。 清单 6. 使用完整的类名
另外一种方法 是在源代码文件中对其他包中的类使用一个 import 语句。这样就不再需要全名了,如清单 7 所示。 清单 7. 使用 import 语 |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |