##########################################
JAVA:---------
statically typed:>>>>>>>>>>>>>>
The classic "Hello, world!" program illustrates the relative verbosity of Java.
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.
PYTHON:--------
dynamically typed:>>>>>>>>>>>>>
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.
#########################################
JAVA:--------
verbose:>>>>>>>>>>>>>>
"abounding in words; using or containing more words than are necessary"
PYTHON:--------
concise (aka terse)>>>>>>>>>>>
"expressing much in a few words. Implies clean-cut brevity, attained by excision of the superfluous"
#########################################
JAVA:-----
public class HelloWorld
{
public static void main (String[] args)
{
System.out.println("Hello, world!");
}
}
Python:----
print "Hello, world!"
&
print("Hello, world!") # Python version 3
##########################################
EXAMPLE:>>>>>>>>>>>>>>>>>>>>
In the following example, we initialize an integer to zero, then convert it to a string, then check to see if it is empty. Note the data declaration (highlighted), which is necessary in Java but not in Python. Notice also how verbose Java is, even in an operation as basic as comparing two strings for equality.
JAVA:---------
int myCounter = 0;
String myString = String.valueOf(myCounter);
if (myString.equals("0")) ...
// print the integers from 1 to 9
for (int i = 1; i < 10; i++) {
System.out.println(i);
}
PYTHON:----------
myCounter = 0
myString = str(myCounter)
if myString == "0": ...
# print the integers from 1 to 9
for i in range(1,10):
print i
#########################################
BEST EXAMPLE:>>>>>>>>>>>>>>>
Your application has an Employee class. When an instance of Employee is created, the constructor may be passed one, two, or three arguments.
If you are programming in Java, this means that you write three constructors, with three different signatures. If you are programming in Python, you write only a single constructor, with default values for the optional arguments.
JAVA:>>>>>>>
No response to “guess...????? About java and python”
Leave a reply