Erinevus lehekülje "JavaPython" redaktsioonide vahel
(ei näidata ühe teise kasutaja 19 vahepealset redaktsiooni) | |||
1. rida: | 1. rida: | ||
+ | {{JavaPython-sisukord}} | ||
+ | |||
+ | <span style="background:#00FF00;font-size:200%"> <b>LEHEKÜLG ON TÄIENDAMISEL!!! </b> </span> | ||
+ | |||
= Sissejuhatus = | = Sissejuhatus = | ||
+ | Selle lehekülje eesmärgiks on võrrelda erinevaid komponente Java ja Pythoni programmeerimiskeelte vahel. Kuigi antud leht on mõeldud Tallinna Tehnikaülikooli informaatikaeriala tudengitele õppevahendiks, sobib seda uurida ka kõigil, kes tahavad võrrelda kahte programmeerimiskeelt. Igal alamleheküljel on toodud võrdlusena komponente nii Java kui ka Pythoni keeles. | ||
+ | |||
+ | Küsimuste korral pöörduda iti0011@cs.ttu.ee | ||
+ | |||
+ | [[Pilt:python-vs-java.jpg|500px]] | ||
+ | |||
+ | == Põhilised erinevused ja sarnasused == | ||
+ | {|class="wikitable" style="color:blue; background-color:#FFE4C4;" cellpadding="14" | ||
+ | !Java | ||
+ | !Python | ||
+ | |- | ||
+ | |<u>Trükkimine</u> | ||
+ | |<u></u> | ||
+ | |- | ||
+ | |In Java, all variable names (along with their types) must be explicitly declared. Attempting to assign an object of the wrong type to a variable name triggers a type exception.That’s what it means to say that Java is a statically typed language. | ||
+ | |||
+ | Java container objects (e.g. Vector and ArrayList) hold objects of the generic type Object, but cannot hold primitives such as int. To store an int in a Vector, you must first convert the int to an Integer. When you retrieve an object from a container, it doesn’t remember its type, and must be explicitly cast to the desired type. | ||
+ | |In Python, you never declare anything. An assignment statement binds a name to an object, and the object can be of any type. If a name is assigned to an object of one type, it may later be assigned to an object of a different type. That’s what it means to say that Python is a dynamically typed language. | ||
+ | |||
+ | Python container objects (e.g. lists and dictionaries) can hold objects of any type, including numbers and lists. When you retrieve an object from a container, it remembers its type, so no casting is required. | ||
+ | |- | ||
+ | |<u>Koodi pikkus</u> | ||
+ | |<u></u> | ||
+ | |- | ||
+ | |abounding in words; using or containing more words than are necessary | ||
+ | |expressing much in a few words. Implies clean-cut brevity, attained by excision of the superfluous | ||
+ | |- | ||
+ | |<u>Kompaktsus</u> | ||
+ | |<u></u> | ||
+ | |- | ||
+ | | | ||
+ | | | ||
+ | |- | ||
+ | |<u>Tabulatsioon</u> | ||
+ | |<u></u> | ||
+ | |- | ||
+ | |Javas ei ole mitte mingit vahet kas joondada koodis iga käsk eri kaugusele, kirjutada nad üksteise järele kõik ühe rea peale või lihtsalt ritta üksteise alla. | ||
+ | |Tabulatsioon on väga oluline | ||
+ | |} | ||
− | |||
− | = | + | == Näide "Hello World" == |
− | + | {| | |
− | + | !Java | |
− | + | !Python | |
− | + | |- | |
− | + | |<syntaxhighlight lang="java" line="1" > | |
− | + | public class HelloWorld | |
− | + | { | |
− | + | public static void main (String[] args) | |
− | + | { | |
− | + | System.out.println("Hello world!"); | |
+ | } | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |<syntaxhighlight lang="python" line="2" > | ||
+ | print("Hello, world!") # Python version 3 | ||
+ | </syntaxhighlight> | ||
+ | |} |
Viimane redaktsioon: 3. veebruar 2016, kell 12:18
Java vs Python |
|
LEHEKÜLG ON TÄIENDAMISEL!!!
Sissejuhatus
Selle lehekülje eesmärgiks on võrrelda erinevaid komponente Java ja Pythoni programmeerimiskeelte vahel. Kuigi antud leht on mõeldud Tallinna Tehnikaülikooli informaatikaeriala tudengitele õppevahendiks, sobib seda uurida ka kõigil, kes tahavad võrrelda kahte programmeerimiskeelt. Igal alamleheküljel on toodud võrdlusena komponente nii Java kui ka Pythoni keeles.
Küsimuste korral pöörduda iti0011@cs.ttu.ee
Põhilised erinevused ja sarnasused
Java | Python |
---|---|
Trükkimine | |
In Java, all variable names (along with their types) must be explicitly declared. Attempting to assign an object of the wrong type to a variable name triggers a type exception.That’s what it means to say that Java is a statically typed language.
Java container objects (e.g. Vector and ArrayList) hold objects of the generic type Object, but cannot hold primitives such as int. To store an int in a Vector, you must first convert the int to an Integer. When you retrieve an object from a container, it doesn’t remember its type, and must be explicitly cast to the desired type. |
In Python, you never declare anything. An assignment statement binds a name to an object, and the object can be of any type. If a name is assigned to an object of one type, it may later be assigned to an object of a different type. That’s what it means to say that Python is a dynamically typed language.
Python container objects (e.g. lists and dictionaries) can hold objects of any type, including numbers and lists. When you retrieve an object from a container, it remembers its type, so no casting is required. |
Koodi pikkus | |
abounding in words; using or containing more words than are necessary | expressing much in a few words. Implies clean-cut brevity, attained by excision of the superfluous |
Kompaktsus | |
Tabulatsioon | |
Javas ei ole mitte mingit vahet kas joondada koodis iga käsk eri kaugusele, kirjutada nad üksteise järele kõik ühe rea peale või lihtsalt ritta üksteise alla. | Tabulatsioon on väga oluline |
Näide "Hello World"
Java | Python |
---|---|
<syntaxhighlight lang="java" line="1" >
public class HelloWorld { public static void main (String[] args) { System.out.println("Hello world!"); } } </syntaxhighlight> |
<syntaxhighlight lang="python" line="2" >
print("Hello, world!") # Python version 3 </syntaxhighlight> |