— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet32/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   28   29   30   31   32   33   34   35   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

dive In 
A Quick Dip
7
What goes in a 
source 
file?
public class Dog {
}
What goes in a 
class
?
public class Dog {

void bark() { 
}
 
}
What goes in a 
method
?
public class Dog {

void bark() {


 
statement1;
statement2;

}
 


}
A source code fi le (with the .java 
extension) holds one class defi ni-
tion. The class represents a piece 
of your program, although a very 
tiny application might need just 
a single class. The class must go 
within a pair of curly braces.
A class has one or more methods
In the Dog class, the bark method 
will hold instructions for how the 
Dog should bark. Your methods 
must be declared inside a class 
(in other words, within the curly 
braces of the class).
class
method
Within the curly braces of a 
method, write your instructions 
for how that method should be 
performed. Method code is basi-
cally a set of statements, and for 
now you can think of a method 
kind of like a function or proce-
dure.
Code structure in Java
statements
Put a 
class
in a source fi le.
Put 
methods
in a class.
Put 
statements
in a method.


8
 
chapter 1
opening brace 
of the method
public class MyFirstApp {
public static void main (String[] args) {
System.out.print(“I Rule!”);

Anatomy of a class


When the JVM starts running, it looks for the class you give it at the com-
mand line. Then it starts looking for a specially-written method that looks 
exactly like:
public static void main (String[] args) { 
// your code goes here
}
Next, the JVM runs everything between the curly braces { } of your main 
method. Every Java application has to have at least one class, and at least 
one main method (not one main per class; just one main per application). 
public so everyone 
can access it
this is a
class (duh)
the name of 
this class
opening curly brace 
of the class
(we’ll cover this
one later.)
the return type. 
void
means there’s 
no return value.
the name of 
this method
arguments to the method. 
This method must be given 
an array of Strings, and the 
array will be called ‘args’
this says print to standard output 
(defaults to command-line)
the String you 
want to print
every statement MUST 
end in a semicolon!!
closing brace of the main method
closing brace of the MyFirstApp class

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   28   29   30   31   32   33   34   35   ...   555




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish