Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

Easy Learn Java: Programming Articles, Examples and Tips - Page 514


Previous 1060 Stories (530 Pages, 2 Per Page) Next

How to compile source code with a switch

Go to all tips in Murachs Java SE6 book

How to compile source code with a switch

Most of the time, you can use TextPad's compile command or the plain javac command shown in the last figure to compile Java source code. Sometimes, however, you need to supply a switch to use certain features of the javac command as summarized in figure 1-13.

Note in the syntax summary in this figure that the brackets around the switch name indicate that it's optional. In addition, the ellipsis (...) indicates that you can code as many switches as you need. You'll see this notation used throughout this book.

When new versions of Java become available, the designers of Java mark some older features as deprecated. When a feature is deprecated, it means that its use is not recommended and it may not be supported in future versions of Java. As a result, you should try to avoid using deprecated features whenever possible.


The first example in this figure shows how to use the deprecation switch to get more information about code that uses deprecated features of the JDK. As you can see, if you don't use this switch, you'll get a brief message that indicates that your code uses deprecated features. On the other hand, if you use this switch, you'll get detailed information about the code that uses deprecated features including the line number for that code. That makes it easier to modify your code so it doesn't use these features.

The second example shows how to use the source switch to compile code so it can run on another computer that's using an older Java interpreter. In particular, this example shows how to compile code so it can run on a computer with version 1.4 of the JRE. When you use this switch, though, you won't be able to use the new features of Java 5 or 6. As a result, you shouldn't use this switch if want to use the new Java features that are presented in this book.

This figure also shows how to use a switch with TextPad. To do that, you begin by selecting the Configure Preferences command, which displays the Preferences dialog box. Then, you expand the Tools group and select Compile Java, which displays the options for compiling Java. At that point, you can add a switch by typing it at the end of the parameters in the Parameters text box. In this figure, for example, the deprecation switch has been added to the end of the Parameters text box. As a result, the deprecation feature will be on for future TextPad sessions until you remove it from this dialog box.

Keep in mind, though, that you don't need to use either of the two switches shown in this figure as you use this book. Since the book is designed to teach you Java 6, you shouldn't need the source switch to specify the use of an earlier version. Since this book doesn't teach the deprecated features, you shouldn't need more information about them. However, you may occasionally need to use one or both of these switches.

Syntax to compile source code with a switch

javac ProgramName.java -switch1Name [-switch2Name]...

Two javac switches

Name
Description
deprecation You can use this switch to get additional information about any deprecated features that your source code uses.
source You can use this switch followed by the version number (1.3 or 1.4) to compile code that works with older versions of the Java interpreter.


How to compile code that uses deprecated features

Without the deprecation switch (you get notes)
C:\java\ch01>javac LoanCalculatorFrame.java
Note: LoanCalculatorFrame.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
With the deprecation switch (you get details)
C:\java\ch01>javac LoanCalculatorFrame.java -deprecation
LoanCalculatorFrame.java:34: warning: [deprecation] show() in
java.awt.Window has been deprecated
frame.show();
^
1 warning

How to compile code with the source and deprecation switches

C:\java1.6\ch01>javac TestApp.java -source 1.4 -deprecation

The Preferences dialog box for TextPad with the deprecation switch on


Description

  • If you want to use the Java 1.6 features and you don't want to get the extra information for deprecated features, you don't need to set any switches.
  • To use a switch with TextPad, select Configure Preferences, expand the Tools group, select the Compile Java group, and add the switch to the end of the Parameters text box.

Introduction to Java ...................................................................... 4
Toolkits and platforms ....................................................................... 4
Java compared to C++ ...................................................................... 4
Java compared to C# ........................................................................ 4
Applications, applets, and servlets ....................................................... 6
How Java compiles and interprets code ................................................ 8
How to prepare your system for using Java .................................. 10
How to install the JDK ..........................................................................10
A summary of the directories and files of the JDK ...................................12
How to set the command path ...............................................................14
How to set the class path ..................................................................... 16
How to use TextPad to work with Java ........................................... 18
How to install TextPad ......................................................................... 18
How to use TextPad to save and edit source code ................................... 20
How to use TextPad to compile source code ........................................... 22
How to use TextPad to run an application ............................................... 22
Common error messages and solutions ................................................. 24
How to use the command prompt to work with Java ...................... 26
How to compile source code ................................................................. 26
How to run an application ..................................................................... 26
How to compile source code with a switch .............................................. 28
Essential DOS skills for working with Java ............................................. 30
How to use the documentation for the Java SE API ....................... 32
How to install the API documentation ..................................................... 32
How to navigate the API documentation ................................................. 34
Introduction to Java IDEs ................................................................ 36
The Eclipse IDE for Java ....................................................................... 36
The NetBeans IDE ................................................................................ 38
The BlueJ IDE ...................................................................................... 38
Perspective ....................................................................................... 40

The chapter 1 of Murach's Java SE 6 excellent book (it is a MUST for all newbees!) is published on our site with written permission of the copyright owner. It was slightly adapted to our site layout. If you want to take a look at PDF version please follow the link here.

11125 bytes more | comments? | Printer Friendly Page  Send to a Friend | Score: 0
Posted by jalex on Friday, August 17, 2007 (21:26:58) (10556 reads)

Essential DOS skills for working with Java

Go to all tips in Murachs Java SE6 book

Essential DOS skills for working with Java

Figure 1-14 summarizes some of the most useful commands and keystrokes for working with DOS. In addition, it shows how to install and use a DOS program called DOSKey, which makes entering and editing DOS commands easier. If you're going to use DOS to work with Java, you should review these DOS commands and keystrokes, and you will probably want to turn on the DOSKey program if it isn't already on. If you aren't going to use DOS, of course, you can skip this figure.

At the top of this figure, you can see a DOS window that shows two DOS commands and a directory listing. Here, the first command changes the current directory to c:\java\exercises\ch01. The next command displays a directory listing. If you study this listing, you can see that this directory contains two files with one line of information for each file. At the right side of each line, you can see the complete file names for these two files (TestApp.class and TestApp.java), and you can see the capitalization for these files as well.


If you master the DOS commands summarized in this figure, you should be able to use DOS to work with Java. To switch to another drive, type the letter of the drive followed by a colon. To change the current directory to another directory, use the cd command. To display a directory listing for the current directory, use the dir command. Although DOS provides many more commands that let you create directories, move files, copy files, and rename files, you can also use the Windows Explorer to perform those types of tasks.

Although you don't need to use the DOSKey program, it can save you a lot of typing and frustration. If, for example, you compile a program and you encounter a syntax error, you will need to use a text editor to fix the error in the source code. Then, you will need to compile the program again. If you're using DOSKey, you can do that by pressing the up-arrow key to display the last command that was executed and then pressing the Enter key to execute the command. And if you make a mistake when entering a command, you can use
the left- and right-arrow keys to edit the command instead of having to enter the entire command again.

A directory listing


A review of DOS commands and keystrokes

Command
Description
dir Displays a directory listing.
dir /p Displays a directory listing that pauses if the listing is too long to fit on one screen.
cd \ Changes the current directory to the root directory for the current drive.
cd .. Changes the current directory to the parent directory.
cd directory name Changes the current directory to the subdirectory with the specified name.
letter: Changes the current drive to the drive specified by the letter. For example, entering d: changes the current drive to the d drive.

 

How to start the DOSKey program

  • To start the DOSKey program, enter "doskey /insert" at the command prompt.
  • To automatically start the DOSKey program for all future sessions, add the "doskey/insert" statement after the "path" statement in the autoexec.bat file. For help on editing the autoexec.bat file, see the second procedure in figure 1-6.

How to use the DOSKey program

Key
Description
Up or down arrow Cycles through previous DOS commands in the current session.
Left or right arrow Moves cursor to allow normal editing of the text on the command prompt.

Introduction to Java ...................................................................... 4
Toolkits and platforms ....................................................................... 4
Java compared to C++ ...................................................................... 4
Java compared to C# ........................................................................ 4
Applications, applets, and servlets ....................................................... 6
How Java compiles and interprets code ................................................ 8
How to prepare your system for using Java .................................. 10
How to install the JDK ..........................................................................10
A summary of the directories and files of the JDK ...................................12
How to set the command path ...............................................................14
How to set the class path ..................................................................... 16
How to use TextPad to work with Java ........................................... 18
How to install TextPad ......................................................................... 18
How to use TextPad to save and edit source code ................................... 20
How to use TextPad to compile source code ........................................... 22
How to use TextPad to run an application ............................................... 22
Common error messages and solutions ................................................. 24
How to use the command prompt to work with Java ...................... 26
How to compile source code ................................................................. 26
How to run an application ..................................................................... 26
How to compile source code with a switch .............................................. 28
Essential DOS skills for working with Java ............................................. 30
How to use the documentation for the Java SE API ....................... 32
How to install the API documentation ..................................................... 32
How to navigate the API documentation ................................................. 34
Introduction to Java IDEs ................................................................ 36
The Eclipse IDE for Java ....................................................................... 36
The NetBeans IDE ................................................................................ 38
The BlueJ IDE ...................................................................................... 38
Perspective ....................................................................................... 40

The chapter 1 of Murach's Java SE 6 excellent book (it is a MUST for all newbees!) is published on our site with written permission of the copyright owner. It was slightly adapted to our site layout. If you want to take a look at PDF version please follow the link here.

10084 bytes more | comments? | Printer Friendly Page  Send to a Friend | Score: 0
Posted by jalex on Friday, August 17, 2007 (21:24:45) (4317 reads)

Previous 1060 Stories (530 Pages, 2 Per Page) Next

530| 529| 528| 527| 526| 525| 524| 523| 522| 521| 520| 519| 518| 517| 516| 515|
514
| 513| 512| 511| 510| 509| 508| 507| 506| 505| 504| 503| 502| 501| 500| 499| 498| 497| 496| 495| 494| 493| 492| 491| 490| 489| 488| 487| 486| 485| 484| 483| 482| 481| 480| 479| 478| 477| 476| 475| 474| 473| 472| 471| 470| 469| 468| 467| 466| 465| 464| 463| 462| 461| 460| 459| 458| 457| 456| 455| 454| 453| 452| 451| 450| 449| 448| 447| 446| 445| 444| 443| 442| 441| 440| 439| 438| 437| 436| 435| 434| 433| 432| 431| 430| 429| 428| 427| 426| 425| 424| 423| 422| 421| 420| 419| 418| 417| 416| 415| 414| 413| 412| 411| 410| 409| 408| 407| 406| 405| 404| 403| 402| 401| 400| 399| 398| 397| 396| 395| 394| 393| 392| 391| 390| 389| 388| 387| 386| 385| 384| 383| 382| 381| 380| 379| 378| 377| 376| 375| 374| 373| 372| 371| 370| 369| 368| 367| 366| 365| 364| 363| 362| 361| 360| 359| 358| 357| 356| 355| 354| 353| 352| 351| 350| 349| 348| 347| 346| 345| 344| 343| 342| 341| 340| 339| 338| 337| 336| 335| 334| 333| 332| 331| 330| 329| 328| 327| 326| 325| 324| 323| 322| 321| 320| 319| 318| 317| 316| 315| 314| 313| 312| 311| 310| 309| 308| 307| 306| 305| 304| 303| 302| 301| 300| 299| 298| 297| 296| 295| 294| 293| 292| 291| 290| 289| 288| 287| 286| 285| 284| 283| 282| 281| 280| 279| 278| 277| 276| 275| 274| 273| 272| 271| 270| 269| 268| 267| 266| 265| 264| 263| 262| 261| 260| 259| 258| 257| 256| 255| 254| 253| 252| 251| 250| 249| 248| 247| 246| 245| 244| 243| 242| 241| 240| 239| 238| 237| 236| 235| 234| 233| 232| 231| 230| 229| 228| 227| 226| 225| 224| 223| 222| 221| 220| 219| 218| 217| 216| 215| 214| 213| 212| 211| 210| 209| 208| 207| 206| 205| 204| 203| 202| 201| 200| 199| 198| 197| 196| 195| 194| 193| 192| 191| 190| 189| 188| 187| 186| 185| 184| 183| 182| 181| 180| 179| 178| 177| 176| 175| 174| 173| 172| 171| 170| 169| 168| 167| 166| 165| 164| 163| 162| 161| 160| 159| 158| 157| 156| 155| 154| 153| 152| 151| 150| 149| 148| 147| 146| 145| 144| 143| 142| 141| 140| 139| 138| 137| 136| 135| 134| 133| 132| 131| 130| 129| 128| 127| 126| 125| 124| 123| 122| 121| 120| 119| 118| 117| 116| 115| 114| 113| 112| 111| 110| 109| 108| 107| 106| 105| 104| 103| 102| 101| 100| 99| 98| 97| 96| 95| 94| 93| 92| 91| 90| 89| 88| 87| 86| 85| 84| 83| 82| 81| 80| 79| 78| 77| 76| 75| 74| 73| 72| 71| 70| 69| 68| 67| 66| 65| 64| 63| 62| 61| 60| 59| 58| 57| 56| 55| 54| 53| 52| 51| 50| 49| 48| 47| 46| 45| 44| 43| 42| 41| 40| 39| 38| 37| 36| 35| 34| 33| 32| 31| 30| 29| 28| 27| 26| 25| 24| 23| 22| 21| 20| 19| 18| 17| 16| 15| 14| 13| 12| 11| 10| 9| 8| 7| 6| 5| 4| 3| 2| 1|


Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy