例1(JavaScript)
程式碼來源:JavaScript-基本結構 (Structure)
1.複製以下程式碼 貼在一個新WordPad檔 並將紅字處"World"更為自己名字
<html>
<head>
<title> The First Example: Hello, World </title>
</head>
<body>
<h2> This line is HTML </h2>
<script language="JavaScript">
<!--
document.write("Hello, World.This sentence is written using JavaScript.");
// Text on the right of 2 slashes is comment
/* This is comment
that occur more than 1 line
*/
//-->
</script>
<noscript>
Sorry, but your browser doesn't run JavaScript.
</noscript>
<h2> This line is HTML </h2>
</body>
</html>
<head>
<title> The First Example: Hello, World </title>
</head>
<body>
<h2> This line is HTML </h2>
<script language="JavaScript">
<!--
document.write("Hello, World.This sentence is written using JavaScript.");
// Text on the right of 2 slashes is comment
/* This is comment
that occur more than 1 line
*/
//-->
</script>
<noscript>
Sorry, but your browser doesn't run JavaScript.
</noscript>
<h2> This line is HTML </h2>
</body>
</html>
2.儲存檔命名為"index.htm"
3.執行如以下圖即成功
*注意:使用IE瀏覽器可能因無法支援檔案顯示"Sorry, but your browser doesn't run JavaScript."
請使用其他瀏覽器瀏覽
例2(Java SE)
1.複製以下程式碼 貼在一個新WordPad檔
/** * The HelloWorldApp class implements an application that * simply prints "Hello World!" to standard output. */ class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); // Display the string. } }
3.使用命令提示字元作Java編譯如下圖即成功
(二)電腦IP位址(以教室作業用電腦為範例IP)
例1(JavaScript)
1.複製以下程式碼 貼在一個新WordPad檔
<script language="JavaScript"> VIH_BackColor = "palegreen"; VIH_ForeColor = "navy"; VIH_FontPix = "16"; VIH_DisplayFormat = "You are visiting from:<br>IP Address: %%IP%%<br>Host: %%HOST%%"; VIH_DisplayOnPage = "yes"; </script> <script language="JavaScript" src="http://scripts.hashemian.com/js/visitorIPHOST.js.php"></script>
2.儲存檔命名為"IPAdress.htm"
3.執行如以下圖即成功
例2(Java SE)
1.複製以下程式碼 貼在一個新WordPad檔
import java.net.*; public class TestInet1 { public static void main(String argv[]) { try { InetAddress myip = InetAddress.getLocalHost(); System.out.println(myip.getHostName()); System.out.println(myip.getHostAddress()); } catch (UnknownHostException e) { System.out.println("Error: unable to resolve localhost"); } } }
3.使用命令提示字元作Java編譯如下圖即成功
4.額外小常識:使用"ipconfig"指令也能知道自己的電腦IP位址(如下圖)