04-Basic-Syntax

04-Basic-Syntax - 2006 Marty Hall Basic Java Syntax J2EE Training http/courses.coreservlets.com 2 Servlets JSP Struts JSF Hibernate AJAX Java 5 etc

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
2 J2EE Training: http://courses.coreservlets.com/ Servlets, JSP, Struts, JSF, Hibernate, AJAX, Java 5, etc. Developed and taught by well-known author and developer. At public venues or onsite at your location. © 2006 Marty Hall Basic Java Syntax 3 Developed and taught by well-known author and developer. At public venues or onsite at your location. © 2006 Marty Hall For live Java training, please see training courses at http://courses.coreservlets.com/. Servlets, JSP, Struts, JSF, AJAX, Java 5, etc. Taught by the author of Core Servlets and JSP , More Servlets and JSP , and this tutorial. Available at public venues, or customized versions can be held on-site at your organization.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 J2EE training: http://courses.coreservlets.com Agenda Creating, compiling, and executing simple Java programs Accessing arrays Looping Indenting Code Using if statements Comparing strings Building arrays One-step process Two-step process Using multidimensional arrays Performing basic mathematical operations Reading command-line input 5 J2EE training: http://courses.coreservlets.com Getting Started Name of file must match name of class It is case sensitive, even on Windows Processing starts in main public static void main(String[] args) Routines usually called “methods,” not “functions.” Printing is done with System.out System.out.println, System.out.print, System.out.printf Compile with “javac” Use DOS window or editor/IDE If you use DOS window, supply full case-sensitive file name (with file extension) Execute with “java” Supply base class name (no file extension)
Background image of page 2
6 J2EE training: http://courses.coreservlets.com Example File: HelloWorld.java public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world."); } } Compiling DOS> javac HelloWorld.java Executing DOS> java HelloWorld Hello, world. 7 J2EE training: http://courses.coreservlets.com More Basics Use + for string concatenation Arrays are accessed with [] Array indices are zero-based The argument to main is an array of strings that correspond to the command line arguments args[0] returns first command-line argument args[1] returns second command-line argument Etc. Error if you try to access more args than were supplied The length field gives the number of elements in an array Thus, args.length gives the number of command- line arguments Unlike in C/C++, the name of the program is not inserted into the command-line arguments
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 J2EE training: http://courses.coreservlets.com Example File: ShowTwoArgs.java public class ShowTwoArgs { public static void main(String[] args) { System.out.println("First arg: " + args[0]); System.out.println("Second arg: " + args[1]); } } 9 J2EE training: http://courses.coreservlets.com Example (Continued) Compiling DOS> javac ShowTwoArgs.java Executing DOS> java ShowTwoArgs Hello Class First args Hello Second arg: Class DOS> java ShowTwoArgs [Error message]
Background image of page 4
10 J2EE training: http://courses.coreservlets.com
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/16/2009 for the course CSCI 571 taught by Professor Papa during the Summer '07 term at USC.

Page1 / 17

04-Basic-Syntax - 2006 Marty Hall Basic Java Syntax J2EE Training http/courses.coreservlets.com 2 Servlets JSP Struts JSF Hibernate AJAX Java 5 etc

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online