Java Tutorial 1

来源:互联网 发布:校园app 软件下载 编辑:程序博客网 时间:2024/06/07 21:13
 

  • Java is a OOP language

  • object is a self-contained entity which has its own private collection of properties (ie. data) and methods (ie. operations) that encapsulate functionality into a reusable and dynamically loaded structure.

  • Applications are stand alone and are invoked (or executed) by using a Java interpreter.


/**
* The HelloWorldApp class implements an application
* that displays "Hello World!" to the standard output.
*/
public class HelloWorldApp {
public static void main(String args[])
{
// Display Hello World! now
System.out.println("Hello World!");
}
}



  • First fore lins are Comments. A long ons starts with /* or /** and ends with */ . A short one starts with // and end with
  • Fifth line, Class Title...Object name is case-sensitive,capitalize first letter of each word.
  • Sixth line, MAIN method.
  • Ninth line, call System.out object and its println() method.

/* The HelloWorld class implements an applet that
displays "Hello World!" within an XHTML document. */


import java.awt.Graphics; import java.applet.Applet;
public class HelloWorld extends Applet
{
public void init() // Initialize the canvas
{
resize(150,10);
}
public void paint(Graphics g) // Display Hello World!
{
g.drawString("Hello World!",50,25);
}
}

  • A Java applet produces object code which restricts local user resource access and can be normally be interpreted within the user's browser.
  • The JApplet class is used instead of Applet whenever Swing GUI objects are used
  • Extend Applet object, and override the methods.

Your browser does not support Java!

  • All applets are intended to be viewed from XHTML documents. In XHTML the object or applet element is placed where desired in the body of the document
  • Life Cycle of an Applet
  • Initialization - init()
  • Display - paint()
  • Starting - start()
  • Stopping - stop()
  • Destruction - destory()
i wanna run away never say goodbey
原创粉丝点击