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

The first part of java basics tutorial, covering the concept of 'everything is an object' with examples of 'hellodate' and 'exec' classes. It also introduces controlling program flow with operators, if-else, while, do-while, for, and switch statements. Examples are given for vowels and consonants identification.

Typology: Study notes

Pre 2010

Uploaded on 02/12/2009

koofers-user-gjt
koofers-user-gjt 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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