Scrigroup - Documente si articole

Username / Parola inexistente      

Home Documente Upload Resurse Alte limbi doc  


AccessAdobe photoshopAlgoritmiAutocadBaze de dateCC sharp
CalculatoareCorel drawDot netExcelFox proFrontpageHardware
HtmlInternetJavaLinuxMatlabMs dosPascal
PhpPower pointRetele calculatoareSqlTutorialsWebdesignWindows
WordXml

AspAutocadCDot netExcelFox proHtmlJava
LinuxMathcadPhotoshopPhpSqlVisual studioWindowsXml

Your first Java program

java

+ Font mai mare | - Font mai mic



DOCUMENTE SIMILARE

Trimite pe Messenger
Handling Text, Dialogs, And Lists
Seam Contexts
Windowing Components And Layout Classes
The Component Class
AWT Image Processing
AWT Peer Interfaces
Web Applications
Handling URLs And Networking Exceptions
Network And Sockets
Your first Java program


Your first Java program

Finally, here’s the program. It prints out information about the system that it’s running on using various methods of the System object from the Java standard library. Note that an additional style of comment is introduced here: the ‘//’, which is a comment until the end of the line:




// Property.java

import java.util.*;

public class Property

}

At the beginning of each program file, you must place the import statement to bring in any extra classes you’ll need for the code in that file. Note that it is “extra.” That’s because there’s a certain library of classes that are automatically brought into every Java file: java.lang. Start up your Web browser and look at the documentation from Sun. (If you haven’t downloaded it from java.sun.com or otherwise installed the Java documentation, do so now). If you look at the packages.html file, you’ll see a list of all the different class libraries that come with Java. Select java.lang. Under “Class Index” you’ll see a list of all the classes that are part of that library. Since java.lang is implicitly included in every Java code file, these classes are automatically available. In the list, you’ll see System and Runtime, which are used in Property.java. There’s no Date class listed in java.lang, which means you must import another library to use that. If you don’t know the library where a particular class is, or if you want to see all of the classes, you can select “Class Hierarchy” in the Java documentation. In a Web browser, this takes awhile to construct, but you can find every single class that comes with Java. Then you can use the browser’s “find” function to find Date. When you do you’ll see it listed as java.util.Date, which lets you know that it’s in the util library and that you must import java.util.* in order to use Date.

If you look at the documentation starting from the packages.html file (which I’ve set in my Web browser as the default starting page), select java.lang and then System. You’ll see that the System class has several fields, and if you select out you’ll discover that it’s a static PrintStream object. Since it’s static you don’t need to create anything. The out object is always there and you can just use it. What you can do with this out object is determined by the type it is: a PrintStream. Conveniently, PrintStream is shown in the description as a hyperlink, so if you click on that you’ll see a list of all the methods you can call for PrintStream. There are quite a few and these will be covered later in the book. For now all we’re interested in is println( ), which in effect means “print out what I’m giving you to the console and end with a new line.” Thus, in any Java program you write you can say System.out.println(“things”) whenever you want to print something to the console.



The name of the class is the same as the name of the file. When you’re creating a stand-alone program such as this one, one of the classes in the file must have the same name as the file. (The compiler complains if you don’t do this.) That class must contain a method called main( ) with the signature shown:

public static void main(String[] args) catch(InterruptedException e)

}

This will pause the output for five seconds. This code involves concepts that will not be introduced until much later in the book, so you won’t understand it until then, but it will do the trick.






Politica de confidentialitate



DISTRIBUIE DOCUMENTUL

Comentarii


Vizualizari: 472
Importanta: rank

Comenteaza documentul:

Te rugam sa te autentifici sau sa iti faci cont pentru a putea comenta

Creaza cont nou

Termeni si conditii de utilizare | Contact
© SCRIGROUP 2021 . All rights reserved

Distribuie URL

Adauga cod HTML in site