CIT590 From Python to Java

Ytrigehd vi msatnmto od ytrigehd dcaelclvralshr elr

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } vi mSatnMto( { od ytrigehd) / dcaelclvralshr / elr oa aibe ee / saeet g hr;cncl ohrmtos / ttmns o ee a al te ehd } /ohrmtosg hr /te ehd o ee } Strings and com m ents Java string literals are enclosed in double quotes (", never in single quotes. Character literals are enclosed in single quotes (', never in ) ) double quotes. A one- character string is not the same as the single character. Escape sequences (\ , \ , etc.) are single characters. There nt are no triple- quoted strings or raw strings in Java. matuszek/cit590- 2013/Pag es/python- to- java.html 1/6 3/13/13 CIT590 Fr om Python to Java Strings can be concatenated with the + operator. Any object, of any type, may be concatenated to a String; it will be aut omat ically converted to a String (for objects, via their t S r n ( method) before being concatenated. otig) In Python, #starts a single- line comment; in Java, / starts a single- line comment. Java also has multi- line comments, beginning with / / * and ending with * . / In Python a docstring (documentation string) is a string, usually triple- quoted, just af t er a function or method header. In Java, a Javadoc comment begins with / * and ends with * , and is put just bef ore a method header, class header, or variable declaration. * / Variable declarations You must declare the type of every variable that you use. Each variable must be declared once and only once (but the same variable name may be declared in different scopes.) There are eight primitive types; everything else is an object type (defined by a class). Important primitive types Other primitive types Important object types i t- for integers n b t - for very small integers ye S r n - for strings tig d u l - for floating point numbers obe s o t- for small integers hr Arrays - have a fixed size b o e n- values are t u and f l e l n - for integers longer than nine ola re as og (all lowercase) digits c a - for single characters hr f o t- for less accurate floatingla point numbers A r y i t t p > - like Python lists raLs<ye H s M p k y y e v l e y e - like aha<etp, autp> Python dictionaries Example declar ations dul dsac; obe itne Srn frtae tig isNm; itcut=0 n on ; ca[[ ltes=nwca5; hr]] etr e hr5 AryitSrn>suet; raLs<tig tdns fnlitCASLMT=3; ia n LS_II 8 / iiilvle / nta au / dcae a aryo ary ADcetsi / elrs n ra f ras N rae t / dcae btde NTcet a Aryit / elrs u os O rae n raLs / cntn / osat Python list → Java ar r ay An array is indexed like a Pyth...
View Full Document

This document was uploaded on 02/02/2014.

Ask a homework question - tutors are online