CIT590 From Python to Java

Declaration and creation look like aha hsmpkyye vleye

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: bject syntax. There are no literals. Declaration and creation look like: aha HsMpkyye vleye vral =nwHsStkyye vleye(; aha<eTp, auTp> aibe e ahe<eTp, auTp>) Some methods: t p p t k y v l e (returns previous value), t p g t k y , b o e n c n a n K y k y . ye u(e, au) ye e(e) ola otise(e) Operators The following operators are basically the same in Python and Java: .+-*/<< = ! > >+ - * / &|^~< > ==== ==== <> When applied to objects, the Java = and ! operators act like Python's i and i n toperators, which is usually not what is wanted = = s so (especially for Strings). Equality testing should be done with the o j . q a s o j )method. b1eul(b2 The %(mod) operator behaves the same for positive integers, but differently for negative integers. Python's i i s a c ( b e t C a s function is the equivalent of Java's o j c i s a c o C a soperator. sntneojc, ls) bet ntnef ls The Java equivalents of Python's a d o , and n tare & , | , and ! respectively. There are no equivalents for i and n t i . n, r o &| , n on Java has + , to increment by one, and - , to decrement by one. These can be either prefix or postfix, and should be used only as + statements, not as part of an expression. Java also has the expression c n i i n ? v l e f r e : v l e f a s to choose odto auITu auIFle between two values. Statem ents Statements end with a semicolon. Rather than trying to give precise syntactical definitions of the various statements, I'll just provide examples. Python Java a=b+c a=b+c ; pit' =,x rn x ' Sse.u.rnl(x="+x; ytmotpitn" ) pitx rn , Sse.u.rn() ytmotpitx; Sanrsanr=nwSanrSse.n;/ dn oc cne cne e cne(ytmi) / oe ne nm =rwipt'ne yu nm:' Sse.u.rn(Etryu nm:"; ae a_nu(Etr or ae ) ytmotpit"ne or ae ) nm =sanrnxLn(; ae cne.etie) ae=ipt'ne yu ae ' g nu(Etr or g: ) Sanrsanr=nwSanrSse.n;/ dn oc cne cne e cne(ytmi) / oe ne Sse.u.rn(Etryu ae "; ytmotpit"ne or g: ) nm =sanrnxIt) ae cne.etn(; wiex<10: hl 00 x=2*x wie( <10){ hl x 00 x=2*x ; } www.cis.upenn.edu/~ matuszek/cit590- 2013/Pag es/python- to- java.html 3/6 3/13/13 CIT590 Fr om Python to Java...
View Full Document

Ask a homework question - tutors are online