Tutor profile: Ummesalma G.
Subject: Python Programming
Consider the following "Point" object in Python. Explain what will happen when this code is executed. point = Point(0,1) class Point: def __init__(self, x, y): self.x = x self.y = y
The program results in a NameError exception at the 'point = Point(0,1)' line as the object Point is not defined. Python is an interpreted language. This means that lines of code are read and executed sequentially. When an exception is encountered, the program stops execution and displays the exception. On line 1, Python does not see the definition of object Point on line 3. Therefore, it raises an exception and stops.
Subject: Java Programming
Consider the snippet of Java code below. Explain what will be printed on screen when this snippet is run. String w = "abc"; String x = "abc"; int y = 1; int z = 1; System.out.println(w == x); // (1) System.out.println(y == z); // (2)
Line 1 would print `false`, while Line 2 would print `true`. The `==` operator in Java compares the references of two objects on the heap. `==` answers the question, 'Do both objects point to the same memory reference on the heap?' and also checks if the object is null. The `w.equals(x)` would have compared the value of both objects. Furthermore, Line 2 prints true because y and z are both objects of primitive types (such as int, double, boolean, etc.) where as String is not a primitive type. When comparing using `==` for primitive types, Java checks their values. Primitive types also do not have a '.equals' method defined for them.
Describe the features of a primary key in a database table.
- A primary key can be defined over a set of unique keys in a table. - While a unique key column can contain NULL values, a primary key cannot be NULL. - For a relational database table, a primary key must be defined. - A relational database table can have multiple unique keys defined, which can be used to enforce data integrity checks.
needs and UmmeSalma will reply soon.