Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

There are two ways of declaring an array in java:
***type variable-name[];
OR
type[] variable-name;
***
There are two ways of initializing an array in java:
1. Without assigning values
***datatype [ ] arrayName = new datatype [size];***
2. By assigning values
***
datatype [ ] arrayName={value1, value2, value3};
***
4 years ago
The best way is
***b = mystring.encode()***
This will also be faster because the default argument results not in the string "utf-8" in the C code, but NULL, which is much faster to check.
4 years ago
In Python 3, **call print(..., flush=True)**
Or else Call **file.flush()** on the output file (we can wrap python 2's print function to do this)
4 years ago
A pointer variable in C++ is a variable that holds the memory address of another variable whereas the reference is an alias for an already existing variable.
Pointers dereferenced with a * whereas references can be used simply, by name.
A pointer can be changed to point to any variable of the same type whereas a reference if once initialized to a variable, it cannot be changed to refer to a variable object.
A pointer can be assigned to point to a NULL value whereas a reference cannot be NULL.
4 years ago
Big-O notation basically is a mathematical notation that describes the limiting behavior of a function when the argument tends towards a particular value or infinity. It is an Asymptotic Notation for the worst case, which is also the ceiling of growth for a given function. It provides us with what is called an asymptotic upper bound for the growth rate of runtime of an algorithm or program.
4 years ago
Yes, the concept of ternary operator was added in version 2.5.
For example,
***
>>> def find_max(a,b):
return a if (a>b) else b
>>> find_max(2, 3)
3
***
4 years ago
The best approach to get a unique collection of items is to use a set. Sets are basically the unordered collections of distinct objects. If you want to create a set from any iterable, then simply pass it to the built-in set() function.
For example,
***>>> t = [1, 2, 3, 1, 2, 5, 6, 7, 8]
>>> t
[1, 2, 3, 1, 2, 5, 6, 7, 8]
>>> list(set(t))
[1, 2, 3, 5, 6, 7, 8]
>>> s = [1, 2, 3]
>>> list(set(t) - set(s))
[8, 5, 6, 7]***
4 years ago
To iterate over JSON structure we can use for...of:
***var mycars = [{name:'Susita'}, {name:'BMW'}];

for (var car of mycars)
{
document.write(car.name + "
");
}***
4 years ago
A named block can be used to overcome this situation:
***search: {
for (Type type : types) {
for (Type t : types2) {
if (some condition) {
// Do something and break...
break search;
}
}
}
}***
4 years ago
Context represents environment data that provides access to things such as databases. It provides services like resolving resources, obtaining access to preferences, and so on. Generally, things like Loading a resource, Launching a new activity, Creating views, and obtaining system service, involve context.
4 years ago
px stands for pixels and it refers to the actual pixels on the screen.

dp or dip stands for Density-independent Pixels. It is an abstract unit that corresponds to more or fewer pixels depending on the physical density.
1dp = 1px on mdpi

sp stands for Scaleable Pixels OR scale-independent pixels. This is like the dp unit, but it is also scaled by the user's font size preference. They are scaled when the Large Text option is turned on in Settings > Accessibility
1sp = 1dp
1sp = 1.2dp with accessibility Large Text
4 years ago
There are two ways of solving this Problem.

1. Don't write network call in Main UI Thread, Use Async Task for that.

2. Write below code into your MainActivity file after setContentView(R.layout.activity_main);
***if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}***

The below import statement should be added in the java file.
***import android.os.StrictMode;***
4 years ago