assignments backup
assignments backup
program.
1 )variable declaration
2) basic syntax
4) flow control
5) iteration (loop)
6) functional programming
7) debugging
1) Variable Declaration
Python: Variables are dynamically typed, so they’re declared without specifying a data type. For
example:
x=5
y = "Hello"
Java: Variables are statically typed, meaning you must declare the data type explicitly:
int x = 5;
String y = "Hello";
---
Basic Syntax
Python: Emphasizes readability, using indentation to define code blocks, and avoids braces {}
or semicolons ;.
if x > 0:
print("Positive")
Java: Uses braces {} to define code blocks and requires semicolons ; at the end of statements.
if (x > 0) {
System.out.println("Positive");
---
Java: Offers primitive types (int, double, char, etc.) and complex data structures (such as
ArrayList, HashMap, etc.) through the Collections framework.
---
4) Flow Control
Python: Uses conditional statements like if, elif, and else. Also includes for and while loops.
if x > 0:
print("Positive")
elif x == 0:
print("Zero")
else:
print("Negative")
Java: Also uses if, else if, and else, but adds switch statements for multiple conditions.
if (x > 0) {
System.out.println("Positive");
} else if (x == 0) {
System.out.println("Zero");
} else {
System.out.println("Negative");
---
5) Iteration (Loop)
Python: Supports for and while loops. for loops in Python are typically used to iterate over
collections (like lists and strings).
for i in range(5):
print(i)
Java: Supports for, while, and do-while loops, including enhanced for loops for collections.
System.out.println(i);
}
---
6) Functional Programming
Java: Supports functional programming with Java 8’s introduction of lambda expressions and
the Stream API, which offers methods like map, filter, and reduce.
.map(x -> x * x)
.boxed()
.collect(Collectors.toList());
---
7) Debugging
Python: Comes with pdb (Python Debugger) for command-line debugging, and most IDEs (like
PyCharm) support advanced debugging tools.
Java: Has jdb (Java Debugger) and extensive support in IDEs like Eclipse and IntelliJ, with
powerful debugging tools for step-by-step code inspection.
---
Both Python and Java have their strengths and approaches tailored to different programming
styles and use cases.