answersLogoWhite

0

📱

Java Programming

The Java programming language was released in 1995 as a core component of the Java platform of Sun Microsystems. It is a general-purpose, class-based, object-oriented language that is widely used in application software and web applications.

5,203 Questions

How to write a java program to extract the last digit from the input?

Assuming you've entered a multi-digit number whole number (an integer), then take the modus (%) of the number and 10. E.g., if the number input was 1234, then 1234 % 10 is 4. Thus the final digit is 4. Note that modus 10 is the same as dividing the number by 10 and taking the remainder.

What is the difference between Java developer and Java programmer?

Here I am sharing Some difference between web developer and application developer as follows:

Web Developer:

  • Develops a website or web applications.

  • The programming languages used are HTML, CSS, JavaScript, etc.

  • Web applications need to be hosted via the internet or internet.

  • In web development, an application is developed to be compatible across browsers.

  • The average salary for a Web Developer is $76,298 per year in the United States.

Application Developer:

  • Develops any kind of software.

  • Applications developed could be client or client-server based.

  • The programming languages used are C++, Java, Python, etc.

  • Developed software may or may not require to be hosted.

  • In software development, an application is developed to be compatible across different OS/platforms.

  • The average salary for a Software Engineer is $107,909 per year in the United States.

Creating a program using switch statement and if and else statement?

Not that difficult...

int main (int argc, char **argv)

{

if (argc==1) printf ("No arguments\n");

else printf ("%d arguments\n", argc-1);

goto END;

END:

return 0;

}

Is encapsulation a characteristic of procedural or object oriented programming?

Encapsulation is one of the four pillars of object-oriented programming. The other three are inheritance, polymorphism and abstraction.

Explain the difference between public and protected access specifier?

A private variable is only accessible in the class where it was declared

A protected variable is accessible to sub classes and classes in the same package as where they were declared

What are the types of data in science?

A data is classified as scientific if the cultivation came from a scientific process and research. This means the conclusion in every experiment is a scientific data or those that are taken to account before the experiment occurs.

Giving an example explain what is Operator Overloading?

Overloading refers to use of something for different purposes.

Function Overloading - It refers to the design of family of functions with one function name but with different argument list. The correct function will be invoked by checking the number and type of the arguments.

Operator Overloading - The mechanism of giving the additional property to the operator is known as operator overloading. We can overload all the operators except the following:

1.)Class members access operators

2.)Scope resolution operator

3.)Sizeof operator

4.)Conditional operator

How do you use an interface?

When you implement an interface, you're agreeing to adhere to the contract defined in the interface. That means you're agreeing to provide legal implementations for every method defined in the interface, and that anyone who knows what the interface methods look like can rest assured that they can invoke those methods on an instance of your implementing class. (Thy need not bother much about how you have implemented it. All they bother about is whether a method of the name mentioned in the interface is available or not)

Now, you might stop me and ask, what if I implement an interface and opt not to write code for a method that I am supposed to? The answer is simple. The compiler wouldn't let you do that. You cannot successfully implement an interface without providing method implementation for all the methods declared inside the interface. This is how the java system ensures that when someone knows a certain method name in an interface and has an instance of a class that implements it, can actually call that method without fear that the method isn't implemented inside the class.

Assuming an interface, Convertible, with two methods: openHood(), and setOpenHoodFactor(), the following class will compile:

public class Ball implements Convertible { // Keyword 'implements'

public void openHood() { }

public void setOpenHoodFactor(int bf) { }

}

Ok, I know what you are thinking now. "This has got to be the worst implementation class that you have seen". Though it compiles and runs as well, it is actually doing nothing… the interface contract guarantees that the class implementing it will have a method of a particular name but it never guaranteed a good implementation. In other words, the compiler does not bother whether you have code inside your method or not. All it cares is if you have methods of the matching names as in the interface. That's all…

Implementation classes must adhere to the same rules for method implementation as a class extending an abstract class. In order to be a legal implementation class, a nonabstract implementation class must do the following:

• Provide concrete (nonabstract) implementations for all methods from the declared interface.

• Follow all the rules for legal overrides.

• Declare no checked exceptions on implementation methods other than those declared by the interface method, or subclasses of those declared by the interface method.

• Maintain the signature of the interface method, and maintain the same return type (or a subtype).

• It does not have to declare the exceptions declared in the interface method declaration

What is the size of void data type?

Data-type void has some special features:

- it doesn't have values

- it doesn't have size

- you cannot declare variables with it

- void *pointers cannot be dereferenced

What is the difference between cc plus plus and java?

C is a procedure oriented language ,Where C++ & java are object oriented language.
But java is platform independent.
So generally C is called POP.
C++ is called OOP.
But java is OOP , which is platform independent.
If java does not support primitive data type then it is called as pure object oriented language.

What are the advantages and disadvantages of a compiler?

The advantages are that the compiler can see each translation unit as a whole and can therefore optimise the resultant machine code accordingly. For instance, trivial functions that are accessed often, such as array suffix operators, can benefit from inline expansion, thus eliminating the need for an otherwise costly function call.

Also, constant expressions can be evaluated at compile time using compile-time evaluation. For instance, consider the following code:

constexpr int fac (constexpr num) {

return num==1?1:fac (num-1);

}

void f() {

int x {fac (7)};

// ...

}

A good compiler will replace the recursive function call fac(7) with the constant value 5040.

In addition, compilers (along with the corresponding linker) help eliminate many common errors such as static type errors, syntax errors and linkage errors. They can also test programmer's assumptions through static assertions. The more errors detected and eliminated at compile time, the fewer errors there will be at runtime, which will primarily consist of logic errors.

The disadvantage of compilers is that compilation can take a long time, particularly with large projects. Each time the program is modified, it must be recompiled. compilation times can be reduced by precompiling headers that are not expected to change very often, creating intermediate files that are much faster to compile. There is also no need to recompile translation units that are unaffected by changes in code, most of which only occur due to changes with a common header. Nevertheless, a non-trivial application can still take several minutes to produce a working executable and the more time spent compiling the less time you can spend debugging the runtime logic.

Interpreted languages are executed in real-time without the need for compilation. However, execution times are very much slower due to the need to constantly translate high-level source code into low-level machine code.

There are, however, languages that are both compiled and interpreted. Java is a typical example. The source code is first compiled to an intermediate code known as Java byte code which can then be interpreted by the Java virtual machine to produce the machine code. Unlike traditional compilers which produce native machine code that only runs one the architecture it was intended for, Java byte code is completely portable and can be executed upon any machine with a suitable Java virtual machine implementation, which is pretty much everything these days. However, interpreted languages (including Java) are not suitable for low-level programming, they are only suitable for applications programming. Compiled languages such as C and C++ are suitable for all types of programming, hence they are termed general purpose languages.

What are the usages of keyword final in java?

It's a built-in keyword that defines an entity that cannot be later modified. It can be used in different aspects within your code (like setting a 'final' class, method (function), or variable).

What are the basic operational concepts of computer?

hardware,software and 3rd is data. explain in detail then this question will be completed.

Simple hierarchical inheritance program in java?

Multilevel inheritance is a java feature where the properties of a class are inherited by a class which extends one or more classes which extend its features...

Example:

public class A {

public String getName(){

return "Rocky";

}

}

public class B extends A {

public int getAge() {

return 24;

}

}

public class C extends B {

public String getAddress(){

return "North Carolina, USA";

}

}

public class D extends C {

public void print {

System.out.println(getName());

System.out.println(getAge());

System.out.println(getAddress());

}

}

This method would print the following in the console:

Rocky

24

North Carolina, USA

Here in class D you are calling methods that are available inside classes A, B & C. Though D extends only class C, it would in turn inherit the properties of the classes extended by C and its parents.

This is multi level inheritance.

What is current instance in java?

Instance refers to one item of a particular type. for ex: you are one instance of a human, similarly I am one instance of human.

An instance in object oriented terms refers to one item of a particular object type.

What is Java Class Libraries?

The Java standard library refers to the set of dynamically loadable libraries that Java applications can call at run time. This is because the Java platform is not dependent on the specific operating system.

Explain strings are immutable in java with example?

Among other things, the immutability of a String give us a few guarantees:

* A String will always be Thread-safe * Duplicate Strings can be multiple pointers to the same data (reduce memory footprint) * substring method is very fast (only need a pointer and an offset, no copying) See http://mindprod.com/jgloss/immutable.html for a full description.

Header files in Java programming?

Java does not require header files like C/C++.

Can you pass object as an argument to a method?

if you have a function or a method that takes Object as a parameter, you can call that function or method and pass an Object as follows:

Let's say you have a class that extends Object and a function as follows

public class A extends Object {

.....

}

void function ( A arg ){

.....

}

To call this function, you need an instance of the class A

A objectInstance = new A();

function(objectInstance);

The next line shows how to pass an instance of the class A to the function.

What is NullPointerException?

A NullPointerException is an exception thrown by the Java Virtual Machine when you try to access a variable as if it were an object when it is contains null. For example, the following code would throw a NullPointerException:

String s;

if (s.charAt(0) == 'c') // this line throws NullPointerException

return "s[0] is 'c'";

Print prime numbers between 1 to 100?

#include <stdio.h>

int main (int argc, char **argv) {

int i, j, prime;

for (i=51; i<=99; i+=2) {

prime=1;

for (j=3; j<=i-2; j+=2) {

if (i%j == 0) {

prime=0;

break;

}

}

if (prime) printf ("%d ", i);

}

printf ("\n");

return 0;

}

What is class and method in java?

Class in Java is a blueprint which is used to create objects in Java. Class contains both methods and variables and that's how it is different with C struct construct. in Java there are built in classes like System Classes and you can also create class by using keyword "class" which we call user defined classes or application classes.

Why is a class called a factory of objects?

A factory class is a class that uses the factory method pattern. Factory method pattern is a creational pattern that uses factory methods to deal with the problem of creating objects without having to specify the exact class of the object that will be created. Google for more info.

In java methods what are arguments?

Let's assume you have a method call, and a method, like this:

// In the main program:
int x = 5;
myMethod(x, 10)
...

// Some lines later:
void myMethod (int parameter1, int parameter2)
{
// Do something here
}

The arguments - values 5 and 10 - are passed to the method, myMethod. This means a copy of these values is passed to the method, for its use. (Technically, the values are placed on the stack, where the other method accesses them.)

The method will then have the values available. This allows for a method to be flexible, being able to processes different sets of data. For example, instead of writing a method to calculate the square root of 2, you write a method that calculates the square root of any number - passed as an argument.