Docsity

Java Basics Part I: Everything is an Object - Objects and Program Flow, Study notes of Computer Science

Toggle sidebar
bg1
Java Basics - Part I
(lectures programs)
Sun OnLine Documentations
Chapter 2: Everything is an Object
First Example: HelloDate
Run as applet
public class HelloDate {
public static void main(String[] args) {
System.out.println("Hello, it's: ");
System.out.println(new Date());
}
}
• How to Complie it?
% make
OR % javac HelloDate.java
• How to Run it?
% java HelloDate
• Java Documentation:
% javadoc HelloDate.java
pf3
pf4

Partial preview of the text

Download Java Basics Part I: Everything is an Object - Objects and Program Flow and more Study notes Computer Science in PDF only on Docsity!

Java Basics - Part I

(lectures programs)

Sun OnLine Documentations

Chapter 2: Everything is an Object

First Example: HelloDate

Run as applet

public class HelloDate { public static void main(String[] args) { System.out.println("Hello, it's: "); System.out.println(new Date()); } }

  • How to Complie it?

% make OR % javac HelloDate.java

  • How to Run it?

% java HelloDate

  • Java Documentation:

% javadoc HelloDate.java

(use netscape to look at the documentation HelloDate.html )

Exec Example: Exec

This excute any program, e.g.:

public class Exec { public static void main(String[] args) { try { String command = args[0];

System.out.println("exec: " + command);

Process p = Runtime.getRuntime().exec(command);

p.waitFor(); } catch (InterruptedException e){} catch (IOException e){} } }

Example: % jave Exec prog Where prog can be:

  • C program prog.c
  • Java program progHelloDate.c
  • shell program prog.Whotty

Note that prog.Who produces no output!

Chapter 3: Controlling Program Flow

  • operators, precedence, assignment.

Run as applet