• Tidak ada hasil yang ditemukan

Chapter 2: Java Fundamentals

N/A
N/A
Protected

Academic year: 2025

Membagikan "Chapter 2: Java Fundamentals"

Copied!
6
0
0

Teks penuh

(1)

Chapter 2: Java Fundamentals

Java Program

Structure

(2)

Content

• Java Program Structure

• Salam Program

• Saving, Compiling and Running Java Programs

• Comments

(3)

Introduction to OOP Dr. S. GANNOUNI & Dr. A. TOUIR

Page 3

// import Section – import used java libraries public class MyProgramName {

// main method

public static void main( String args[] ){

// Declaration section – Declare needed variables // Input section – Enter required data

// Processing section – Processing Statements // Output section – Display expected results } // end main

} // end class

Java Program Structure

(4)

// import section: Empty

public class MySalamProgram { // main method

public static void main( String args[] ){

// Declaration section: Empty // Input section: Empty

// Processing section: Empty // Output section

System.out.println(“… Assalamo Alaikom …”);

} // end main

Salam Program

(5)

Introduction to OOP Dr. S. GANNOUNI & Dr. A. TOUIR

Page 5

Saving, Compiling and Running Java Programs

• Saving a Java program.

– A file having a name same as the class name should be used to save the program. The extension of this file is ”.java”.

– Salam program should be saved in a file called

“MySalamProgram.java”.

• Compiling a Java program.

– Call the Java compiler javac:

javac MySalamProgram.java

– The Java compiler generates a file called ” MySalamProgram.class”

(the bytecode).

• Running a Java program

– Call the Java Virtual Machine java:

java MySalamProgram.class

(6)

Comments in a Java Program

• Comments are used to describe what your code does and aid reading your code.

• The Java compiler ignores them.

• Comments are made using

– //, which comments to the end of the line,

or /* */, everything inside of it is considered a comment

(including multiple lines). The comment begins after the first /*.

It ends just before the first */.

• Examples:

/* This comment begins at this line.

This line is included in this comment It ends at this line. */

// This comment starts here and ends at the end of this line.

Referensi

Dokumen terkait

public static void main (String[] args) throws IOException{. System.out.println("masukkan nama file

Pada saat pembuatan blok, Anda dapat meletakkan kurung kurawal buka pada baris dengan pernyataan seperti contoh sebagai berikut ,. public static void main( String[]

public class ContohJLabel extends JFrame{ public static void main(String[] args) {. ContohJLabel apl = new

Method yang digunakan pada program tersebut adalah public static void main (String []args){.. Static pada method main berarti metodh main tidak mengubah

// // class TestPC.java // import person.*; class TestPC { public static void mainString args[] { // Initialize the eyedb package and parse the default eyedb options // on the

การใช ้ตัวแปร import java.util.Scanner; // โปรแกรมคํานวณดัชนีมวลกาย // โปรแกรมคานวณดชนมวลกาย public class BodyMassIndex { public static void mainString[] args { public static void

void bark{System.out.println"barking...";} } class TestInheritance{ public static void mainString args[]{ Dog d=new Dog; d.bark; d.eat; }} Polymorphism in Java

Server Program in Java RMI 2 Class ShapeListServer with main method 9 import java.rmi.*; public class ShapeListServer{ public static void mainString args[]{