http://www.java-tips.org/java-se-tips/java.util/how-to-read-input-from-console.html
import java.util.Scanner; |
http://www.java-tips.org/java-se-tips/java.util/how-to-read-input-from-console.html
import java.util.Scanner; |
How To Use Command Line Arguments in Eclipse | |
LINKS INTO DOCUMENT BELOW | |
---|---|
Introduction | Detailed Instructions using Welcome.java |
Instructions using Args.java | Instructions using TempConversion.java |
In the window shown below,
notice that the Welcome Java application is highlighted.
In the large subwindow of the Run window, there is a set of tabs,
labelled Main, Arguments, JRE, etc.
Notice that the Main tab is highlighted.
For the Welcome program,
only one input argument value is needed:
the first name of a new Java student.
For this run, we have chosen Sarah as
the name of this student.
Notice where it has been typed in.
This is where all command line arguments should be entered.
These values remain the same for all runs,
until they are changed in this same window.
For the Args program,
eight input argument values are needed.
For this run, we have chosen eight random sets of
characters, some numeric, some alphabetic, as input values:
namely, 101, Joe, Larry, 93214, 3.145, 66, ABCDEF, xxxxx.
Notice that there is at least one space between every two arguments.
For the TempConversionCL program,
only one input argument value is needed:
the value of the Celsius temperature.
For this run, we have chosen 28.5 for
this value of the Celsius temperature.
Stay up to date with the latest versions of Java for your desktop computer.
Get your own copy of the underlying software code for the Java language.
The basic developer kit for Java developers.
The SDK supports Java SE 6 and the latest Java EE 5 technologies.
Get the award-winning, open-source tool suite for developing Java applications.
Visit java.sun.com for everything you need to know about the Java technology.
See and download all software tools available from Sun.
For developing and deploying Java applications for the desktop, servers, embedded, and real-time environments.
For enterprise, server-side Java applications.
For Java applications running on mobile devices.
Sharpen your Java skills with courses from the source.
Get dedicated help from Sun including technical assistance, product support, and support for deployed Java applications.
Download, develop and collaborate with OpenSolaris
Download the most advanced operating system in the world
Optimizing compilers and tools for C/C++/Fortran application development
Explore the resources and community available to the Solaris developer.
Get technical assistance, product support, training, and other services from the source.
A community site with Solaris system administration information, hardware compatibility, a script library, and other resources for administrators of Sun products.
The place to collaborate on the open-source JDK, an implementation of the Java Platform, Standard Edition specification.
The Mobile & Embedded Community enables and empowers developers to collaborate and innovate, driving the evolution and adoption of the Java(TM) Platform, Micro Edition (Java ME) for mobile and embedded devices.
The GlassFish community is building free, open source, production-quality, enterprise software.
You have the opportunity to submit bugs and feature requests in IssueZilla, submit news for the NetBeans Community, and contribute code or even create a project of your own. Welcome to the team!
The OpenSolaris source code is already cutting edge, but innovation happens everywhere, so we welcome your involvement.
OpenSPARC.net is the genesis of a vision to create a larger community where open conversations and collaborative development projects spawn dramatic innovations around chip design.
The OpenSolaris storage community is your gateway to data management related communities and projects - file sharing, file systems, volume managers, data services, storage drivers, and much more.
Project OpenJFX is a community for sharing early versions of the JavaFX Script language and for collaborating on its development.
A gathering place for Java technology enthusiasts and existing communities across industries, platforms, and interest groups.
The SDN Academic Developer Program offers you ready access to tools, resources, and student communities.
The JCP gives you a chance to both have your own work become an official component of the Java platform, and to offer suggestions for improving and growing the technology.
The basic format of the command for creating a JAR file is: jar cf jar-file input-file(s) Let's look at the options and arguments used in this command:
The This command will generate a compressed JAR file and place it in the current directory. The command will also generate a default manifest file for the JAR archive. You can add any of these additional options to the
In version 1.1, the JAR-file format supports only ASCII filenames. Version 1.2 adds support for UTF8-encoded names. An Example Let's look at an example. The JDK demos include a simple The To package this demo into a single JAR file named jar cvf TicTacToe.jar TicTacToe.class audio images The
You can see from this output that the JAR file jar cvf0 TicTacToe.jar TicTacToe.class audio images You might want to avoid compression, for example, to increase the speed with which a JAR file could be loaded by a browser. Uncompressed JAR files can generally be loaded more quickly than compressed files because the need to decompress the files during loading is eliminated. However, there's a tradeoff in that download time over a network may be longer for larger, uncompressed files. The Jar tool will accept arguments that use the wildcard jar cvf TicTacToe.jar * Though the verbose output doesn't indicate it, the Jar tool automatically adds a manifest file to the JAR archive with pathname In the above example, the files in the archive retained their relative pathnames and directory structure. The Jar tool in version 1.2 of the Java Development Kit provides the As an example, suppose you wanted put audio files and gif images used by the TicTacToe demo into a JAR file, and that you wanted all the files to be on the top level, with no directory hierarchy. You could accomplish that by issuing this command from the parent directory of the jar cf ImageAudio.jar -C images * -C audio * The
By contrast, suppose that you used a command that didn't employ the jar cf ImageAudio.jar images audio The resulting JAR file would have this table of contents:
| ||||||||||||||||||
Oracle is reviewing the Sun product roadmap and will provide guidance to customers in accordance with Oracle's standard product communication policies. Any resulting features and timing of release of such features as determined by Oracle's review of roadmaps, are at the sole discretion of Oracle. All product roadmap information, whether communicated by Sun Microsystems or by Oracle, does not represent a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. It is intended for information purposes only, and may not be incorporated into any contract.
|
What is Java technology and why do I need it?
This article applies to:
Platform(s): All Platforms
Java version(s): All JRE Versions
Java is a programming language and computing platform released by Sun Microsystems in 1995. It is the underlying technology that powers state-of-the-art programs including utilities, games, and business applications. Java runs on more than 850 million personal computers worldwide, and on billions of devices worldwide, including mobile and TV devices.
Why do I need Java?
There are lots of applications and websites that won't work unless you have Java installed, and more are created every day. Java is fast, secure, and reliable. From laptops to datacenters, game consoles to scientific supercomputers, cell phones to the Internet, Java is everywhere!
Is Java free to download?
Yes, Java is free to download. Get the latest version at http://java.com.
Why should I upgrade to the latest Java version?
The latest Java version contains important enhancements to improve performance, stability and security of the Java applications that run on your machine. Installing this free update will ensure that your Java applications continue to run safely and efficiently.
MORE TECHNICAL INFORMATION
Originally called OAK, it was renamed as the Java programming language in 1995.
What will I get when I download Java software?
The Java Runtime Environment (JRE) is what you get when you download Java software. The JRE consists of the Java Virtual Machine (JVM), Java platform core classes, and supporting Java platform libraries. The JRE is the runtime portion of Java software, which is all you need to run it in your Web browser. When you download Java software, you only get what you need - no spyware, and no viruses.
What is Java Plug-in software?
The Java Plug-in software is a component of the Java Runtime Environment (JRE). The JRE allows applets written in the Java programming language to run inside various browsers. The Java Plug-in software is not a standalone program and cannot be installed separately.
I've heard the terms Java Virtual Machine and JVM. Is this Java software?
The Java Virtual Machine is only one aspect of Java software that is involved in web interaction. The Java Virtual Machine is built right into your Java software download, and helps the run Java applications.
http://math.hws.edu/javanotes/c1/s6.html
When computers were first introduced, ordinary people -- including most programmers -- couldn't get near them. They were locked up in rooms with white-coated attendants who would take your programs and data, feed them to the computer, and return the computer's response some time later. When timesharing -- where the computer switches its attention rapidly from one person to another -- was invented in the 1960s, it became possible for several people to interact directly with the computer at the same time. On a timesharing system, users sit at "terminals" where they type commands to the computer, and the computer types back its response. Early personal computers also used typed commands and responses, except that there was only one person involved at a time. This type of interaction between a user and a computer is called a command-line interface.
Today, of course, most people interact with computers in a completely different way. They use a Graphical User Interface, or GUI. The computer draws interface components on the screen. The components include things like windows, scroll bars, menus, buttons, and icons. Usually, a mouse is used to manipulate such components. Assuming that you have not just been teleported in from the 1970s, you are no doubt already familiar with the basics of graphical user interfaces!
A lot of GUI interface components have become fairly standard. That is, they have similar appearance and behavior on many different computer platforms including Macintosh, Windows, and Linux. Java programs, which are supposed to run on many different platforms without modification to the program, can use all the standard GUI components. They might vary a little in appearance from platform to platform, but their functionality should be identical on any computer on which the program runs.
Below is a very simple Java program -- actually an "applet," since it is running right here in the middle of a page -- that shows a few standard GUI interface components. There are four components that the user can interact with: a button, a checkbox, a text field, and a pop-up menu. These components are labeled. There are a few other components in the applet. The labels themselves are components (even though you can't interact with them). The right half of the applet is a text area component, which can display multiple lines of text, and a scrollbar component appears alongside the text area when the number of lines of text becomes larger than will fit in the text area. And in fact, in Java terminology, the whole applet is itself considered to be a "component." Try clicking on the button and on the checkbox, and try selecting an item from the pop-up menu. You will see a message in the text area about each action that you perform. You can type in the text field, but you might have to click on it first to activate it. When you press return while typing in the text field, you will see a message in the text area:
Now, Java actually has two complete sets of GUI components. One of these, the AWT or Abstract Windowing Toolkit, was available in the original version of Java. The other, which is known as Swing, is included in Java version 1.2 or later, and is used in preference to the AWT in most modern Java programs. The applet that is shown above uses components that are part of Swing. If your Web browser uses an old version of Java, you might get an error when the browser tries to load the applet. Remember that most of the applets in this textbook require Java 5.0 (or higher).
When a user interacts with the GUI components in this applet, an "event" is generated. For example, clicking a push button generates an event, and pressing return while typing in a text field generates an event. Each time an event is generated, a message is sent to the applet telling it that the event has occurred, and the applet responds according to its program. In fact, the program consists mainly of "event handlers" that tell the applet how to respond to various types of events. In this example, the applet has been programmed to respond to each event by displaying a message in the text area.
The use of the term "message" here is deliberate. Messages, as you saw in the previous section, are sent to objects. In fact, Java GUI components are implemented as objects. Java includes many predefined classes that represent various types of GUI components. Some of these classes are subclasses of others. Here is a diagram showing some of Swing's GUI classes and their relationships:
Don't worry about the details for now, but try to get some feel about how object-oriented programming and inheritance are used here. Note that all the GUI classes are subclasses, directly or indirectly, of a class called JComponent, which represents general properties that are shared by all Swing components. Two of the direct subclasses of JComponent themselves have subclasses. The classes JTextArea and JTextField, which have certain behaviors in common, are grouped together as subclasses of JTextComponent. Similarly JButton and JToggleButton are subclasses of JAbstractButton, which represents properties common to both buttons and checkboxes. (JComboBox, by the way, is the Swing class that represents pop-up menus.)
Just from this brief discussion, perhaps you can see how GUI programming can make effective use of object-oriented design. In fact, GUI's, with their "visible objects," are probably a major factor contributing to the popularity of OOP.
Programming with GUI components and events is one of the most interesting aspects of Java. However, we will spend several chapters on the basics before returning to this topic in Chapter 6.
http://www.java2s.com/Tutorial/Java/0040__Data-Type/isWhitespace.htm isWhitespace():true if the argument is whitespace. | |
which is any one of the following characters: | |
space (' '), tab ('\t'), newline ('\n'), carriage return ('\r'),form feed ('\f') | |
|
http://dnixon.nyclocal.net/qc/cs212/proj-2-hints/TextFileInput.java.html
// TextFileInput.java // Copyright (c) 2000, 2005 Dorothy L. Nixon. All rights reserved. import java.io.BufferedReader; import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.IOException; /** * Simplified buffered character input * stream from an input text file. * Manages an input text file, * handling all IOExceptions by generating * RuntimeExcpetions (run-time error * messages). * * If the text file cannot be created, * a RuntimeException is thrown, * which by default results an an * error message being printed to * the standard error stream. * * @author D. Nixon */ public class TextFileInput { /** Name of text file */ private String filename; /** Buffered character stream from file */ private BufferedReader br; /** Count of lines read so far. */ private int lineCount = 0; /** * Creates a buffered character input * strea, for the specified text file. * * @param filename the input text file. * @exception RuntimeException if an * IOException is thrown when * attempting to open the file. */ public TextFileInput(String filename) { this.filename = filename; try { br = new BufferedReader( new InputStreamReader( new FileInputStream(filename))); } catch ( IOException ioe ) { throw new RuntimeException(ioe); } // catch } // constructor /** * Closes this character input stream. * No more characters can be read from * this TextFileInput once it is closed. * @exception NullPointerException if * the file is already closed. * @exception RuntimeException if an * IOException is thrown when * closing the file. */ public void close() { try { br.close(); br = null; } catch ( NullPointerException npe ) { throw new NullPointerException( filename + "already closed."); } catch ( IOException ioe ) { throw new RuntimeException(ioe); } // catch } // method close /** * Reads a line of text from the file and * positions cursor at 0 for the next line. * Reads from the current cursor position * to end of line. * Implementation does not invoke read. * * @return the line of text, with * end-of-line marker deleted. * @exception RuntimeException if an * IOException is thrown when * attempting to read from the file. */ public String readLine() { return readLineOriginal(); } // method readLine() /** * Returns a count of lines * read from the file so far. */ public int getLineCount() { return lineCount; } /** * Tests whether the specified character is equal, * ignoring case, to one of the specified options. * * @param toBeChecked the character to be tested. * @param options a set of characters * @return true iftoBeChecked
is * equal, ignoring case, to one of the *options
, false otherwise. */ public static boolean isOneOf(char toBeChecked, char[] options) { boolean oneOf = false; for ( int i = 0; i < oneof =" true;">toBeChecked * contains the same sequence of * characters, ignoring case, as one of the *options
, false otherwise. */ public static boolean isOneOf(String toBeChecked, String[] options) { boolean oneOf = false; for ( int i = 0; i < oneof =" true;" options ="="" length ="="" answer =" readLine();" answer ="="" optionstring =" options[0];" i =" 1;">true if the line matches * "Y", "yes", "1" "T", or "true". *false
if the line matches * "N", "no", "0", "F", or "false". * @exception RuntimeException if the line of text * does not match one of "Y", "N", "yes", * "no", "1", "0", "T", "F", "true", or "false", * or if an IOException is thrown when reading * from the file. * @exception NullPointerException if the end of the * file has been reached. */ public boolean readBooleanSelection() { String[] options = {"Y", "N", "yes", "no", "1", "0", "T", "F", "true", "false"}; String answer = readSelection(options); return isOneOf(answer, new String[] {"Y", "yes", "1", "T", "true"} ); } // method askUserYesNo /** * Reads a line of text from the file and * increments line count. (This method * is called by public readLine and is * final to facilitate avoidance of side * effects when public readLine is overridden.) * * @return the line of text, with * end-of-line marker deleted. * @exception RuntimeException if an * IOException is thrown when * attempting to read from the file. */ protected final String readLineOriginal() { try { if ( br == null ) throw new RuntimeException( "Cannot read from closed file " + filename + "."); String line = br.readLine(); if ( line != null ) lineCount++; return line; } catch (IOException ioe) { throw new RuntimeException(ioe); } // catch } // method readLineOriginal } // class TextFileInput
The Java programming language uses exceptions to handle errors and other exceptional events. This lesson describes when and how to use exceptions.
What Is an Exception?
- An exception is an event that occurs during the execution of a program that disrupts the normal flow of instructions.
The Catch or Specify Requirement
- This section covers how to catch and handle exceptions. The discussion includes the try, catch, and finally blocks, as well as chained exceptions and logging.
How to Throw Exceptions
- This section covers the throw statement and the Throwable class and its subclasses.
Unchecked Exceptions — The Controversy
- This section explains the correct and incorrect use of the unchecked exceptions indicated by subclasses of
RuntimeException
.Advantages of Exceptions
- The use of exceptions to manage errors has some advantages over traditional error-management techniques. You'll learn more in this section.
Summary
Questions and Exercises
Your use of this page (http://java.sun.com/docs/books/tutorial (Last Updated 1/12/2010)) and all the material on pages under "The Java Tutorials" banner is subject to the Terms of Use. Additionally, (i) any example code contained in any of these Java Tutorials pages is also licensed under the Code Sample License, and (ii) the entire Java Tutorials content is available for download under the Java Tutorials Limited Non-Commercial License for limited, non-commercial individual and/or research and instructional use at Sun Download Center.
About Sun | About This Site | Terms of Use | Trademarks | A Sun Developer Network Site Copyright 1995,2010 Oracle Corporation and/or is affiliates |
Examples Index This lesson gives you the background information you need to use the Swing components, and then describes every Swing component. It assumes that you have successfully compiled and run a program that uses Swing components, and that you are familiar with basic Swing concepts. These prerequisites are covered in Getting Started with Swing and Learning Swing with the NetBeans IDE.
Before you get started, you may want to check out these pages (from the Graphical User Interfaces lesson in the Core trail) which have pictures of all the standard Swing components, from top-level containers to scroll panes to buttons. To find the section that discusses a particular component, just click the component's picture.
Discusses how to use the features shared by theJFrame
,JDialog
, andJApplet
classes — content panes, menu bars, and root panes. It also discusses the containment hierarchy, which refers to the tree of components contained by a top-level container.
Tells you about the featuresJComponent
provides to its subclasses — which include almost all Swing components — and gives tips on how to take advantage of these features. This section ends with API tables describing the commonly used API defined byJComponent
and its superclasses,Container
andComponent
.
Describes the features and API shared by all components that descend from JTextComponent
. You probably do not need to read this section if you are just using text fields (formatted or not) or text areas.
Sections on how to use each Swing component, in alphabetical order. We do not expect you to read these sections in order. Instead, we recommend reading the relevant "How to" sections once you are ready to start using Swing components in your own programs. For example, if your program needs a frame, a label, a button, and a color chooser, you should read How to Make Frames, How to Use Labels, How to Use Buttons, and How to Use Color Choosers.
Describes how to vary the font, color, or other formatting of text displayed by Swing components by using HTML tags.
Tells you about the Swing model architecture. This variation on Model-View-Controller (MVC) means that you can, if you wish, specify how the data and state of a Swing component are stored and retrieved. The benefits are the ability to share data and state between components, and to greatly improve the performance of components such as tables that display large amounts of data.
Borders are very handy for drawing lines, titles, and empty space around the edges of components. (You might have noticed that the examples in this trail use a lot of borders.) This section tells you how to add a border to any JComponent
.
Many Swing components can display icons. Usually, icons are implemented as instances of the ImageIcon
class.
This section discusses solutions to common component-related problems.
Try these questions and exercises to test what you have learned in this lesson.
Your use of this page (http://java.sun.com/docs/books/tutorial (Last Updated 1/12/2010)) and all the material on pages under "The Java Tutorials" banner is subject to the Terms of Use. Additionally, (i) any example code contained in any of these Java Tutorials pages is also licensed under the Code Sample License, and (ii) the entire Java Tutorials content is available for download under the Java Tutorials Limited Non-Commercial License for limited, non-commercial individual and/or research and instructional use at Sun Download Center.
About Sun | About This Site | Terms of Use | Trademarks | A Sun Developer Network Site Copyright 1995,2010 Oracle Corporation and/or is affiliates |
Admin |
its great can i be updated through ma e-mail all the time