WDD_lec_03 - Web Design & Development Lecture 3...

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

View Full Document Right Arrow Icon
Lecture 3
Background image of page 1

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

View Full DocumentRight Arrow Icon
Performing Basic Tasks in Java
Background image of page 2
Topics We Will Cover Today Things to Remember Taking in command line arguments Primitives vs. Objects Wrapper classes and Conversions Taking Input and Output using Swing Selection and Control Structures OOP in java (Defining and using class)
Background image of page 3

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

View Full DocumentRight Arrow Icon
Last Lecture Example File: HelloWorldApp.java public class HelloWorldApp{ public static void main(String[] args) { System.out.println("Hello world"); } }
Background image of page 4
Compile and Execute
Background image of page 5

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

View Full DocumentRight Arrow Icon
Things to remember Name of file must match name of class It is case sensitive Processing starts in main public static void main(String[] args) Printing is done with System.out System.out.println, System.out.print Compile with “javac” Open DOS/command prompt window; work from there Supply full case-sensitive file name (with file extension) Execute with “java” Supply base class name (no file extension)
Background image of page 6
An idiom explained You will see the following line of code often: public static void main(String args[]) { …} About main() “main” is the function from which your program starts Why public? So that run time can call it from outside Why static ? it is made static so that we can call it without creating an object What is String args[] ? Way of specifying input at startup of application
Background image of page 7

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

View Full DocumentRight Arrow Icon
Things to Remember “+” operator when used with Strings concatenates them System.out.pritln(“Hello” + “World”) will produce Hello World on console String concatenated with any other data type such as int will also convert that datatype to String and the result will be a concatenated String displayed on console For Example int i = 4 int j = 5 ; System .out.println (“Hello” + i) // will print Hello 4 on screen However System,.out. .println( i+j) ; // will print 9 on the console For comparing Strings never use == operator, use equals methos. == compares addresses (shallow comparison) while equals compares values (deep comparison) E.g string1.equals(string2)
Background image of page 8
public class StringTest { public static void main(String[] args) { int i = 4; int j = 5; System.out.println("Hello" + i); System.out.println(i + j); String s1 = new String (“pakistan”); String s2 = “pakistan”; if (s1 == s2) { System.out.println(“comparing string using == operator”); } if (s1.equals( s2) ) { System.out.println(“comparing string using equal method”); } } } String Concatenation
Background image of page 9

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

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

Page1 / 41

WDD_lec_03 - Web Design & Development Lecture 3...

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

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