l3b_pr_java2

l3b_pr_java2 - The Basics Basic Structure of a Java Program...

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

View Full Document Right Arrow Icon
1 More fun with Java The Basics Basic Structure of a Java Program Packages Simple Declarations Primitive Types Arrays Classes Class Method Constructors Control Iteration Conditional Expressions Exceptions Tools Basic Structure of a Java Program /* a comment */ // a comment <package declaration> <import declarations> <class definitions> Packages package mit16_410_13.search.uninformed; Package structure matches directory structure mit16_410_13 search uninformed Package must be imported before they can be accessed in a program Import import mit16_410_13.search.uninformed.Myclass; import mit16_410_13.search.uninformed.*; Simple Declarations Primitive Types int x, y, // uninitialized variables z=511, h=0x1FF, oc=0777; // decimal, hex, octal double pi=3.14159265358979323846, ff=6.28e-3; boolean flag=true, done=false; char sep=’ ’; string myfirstname=”paul”, myfamilyname=”robertson”, myfullname=myfirstname+” ”+myfamilyname;
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Arrays Array Variabes int [] ai; // an array of int char [][] aac; // an array of array of char Object[] ao1, ao2; // two arrays of objects int num, nums[], nums[][]; Creating Arrays int [] ai={1, 2, 3} double [] ad=new double [57]; int [][] aai={{1, 2}, {3, 4}, null }; Basic statement structure x=3; { x=3; y=4; z=6; } { int x=2; y=x+1; z=y+2; } Iteration Do do <statement> while (<expression>); do { promptforusername(); } while (readusername()); Iteration While while (<expression>) do <statement>; while (node!=goalnode) do { node=node.next(); } Iteration for for (<initexp> opt ; <expression> opt ; <update> opt ) <stmt> for (int i=1; i<10; i++) System.out.println(i);
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/07/2011 for the course AERO 16.410 taught by Professor Brianwilliams during the Fall '05 term at MIT.

Page1 / 5

l3b_pr_java2 - The Basics Basic Structure of a Java Program...

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

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