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

What are the try catch and finally?

final is a keyword that is used for variables, methods and classes. It means that the variable cannot be modified, the method cannot be overridden and the class cannot be inherited.

finally is a keyword that is used in try-catch blocks to ensure that a certain piece of code will execute irrespective of whether an exception occurred or not. For example in places where we access the database, we will close the connection in the finally block to ensure that the connection is released to the connection pool even if the query failed with some exception.

How can user defined operator overloading harm the readability of the program?

Because the built in operator has the precision and compiler knows all the precision between the operators, and it works on that precision.

User can also create its own operator but the compiler does not come to know thow to make precision of this operator.

Therefore we dont use user defined operator

Write a program that stores vowels in an array When you program is given a character it should indicate whether the character is vowel or not?

That's easy to do!

This script will get the POST data from an HTML form and check if it is a vowel.

$vowels = array('a','e','i','o','u'); // Make variable "vowels" an array with all vowels in it

$_POST['string'] = $string;

if (strlen($string) != 1) { // String is not one character.

echo 'The "character" is not one character!";

} else if (in_array($string, $vowels)) { // Check if string is a vowel based on array

echo $string.' is a vowel!'; // Is a vowel

} else {

echo $string.' is not a vowel.'; // Is not a vowel

}

?>

NOTE: Sorry about horrible looking code, Wiki messed up my indenting.

What are object oriented Programs?

There are two types of programmes related to objects that i know.

Pradip: object base means : realted only with object where u can find the encapsulation ,abstraction data hiding is possible but Inheritance,polymorphism, wil not be possible in case of object base programme. all are core object oriented programming.

What is RPC and RMI?

RMI architecture consists of four layers and each layer
performs specific functions:
1. Application Layer : contains the actual object definition
2. Proxy layer : consists of stub and skeleton
3.Remote Reference Layer : gets the stream of bytes from the
transperent layer and sends it to the proxy layer.
4. Transportation layer : Responsible for handling the
actual machine-to-machine communication.

Concatenation of string with number in java?

The concatenation can be done using the "+" operator. The output of this concatenation would be a String.

Ex:

public String concatenate(int val, String phrase) {

return val + phrase;

}

If you invoke this method with 10 and years as the arguments the ouput would be

10 years.

Use and importance of programming languages?

Answer If it weren't for computer languages where would we be today. Can you imagine writing a program as simply as writing a sentence instead of using computer language, it would be impossible. CD/delete means one thing, CD:/change direction and if the double dots aren't there the computer won't recognise the command. That's why so many people especially Computer Programmers spend years in Schools learning computer language so that the every day joe can't do their jobs.

Difference between function and method?

Constructor will be automatically invoked when an object is created whereas method has to be called explicitly. Constructor needs to have the same name as that of the class whereas functions need not be the same. * There is no return type given in a constructor signature (header). The value is this object itself so there is no need to indicate a return value. * There is no return statement in the body of the constructor. * The first line of a constructor must either be a call on another constructor in the same class (using this), or a call on the superclass constructor (using super). If the first line is neither of these, the compiler automatically inserts a call to the parameterless super class constructor.

Can you initialize an object without constructor in java?

No. if you wish to create an object that you plan on using in a java program then the answer is NO. You cannot initialize an object of a Java class without calling the constructor.

What are inner classes?

Quite simply, an inner class is one class within another. Typically the inner class will be a private inner class, and will only be used by the outer class.

class MyOuterClass {

class MyInnerClass {

}

}

What are decision statements in java?

Decision statements are statements that are used for taking logical decisions. They contain a condition whose output is a boolean true or false.

Ex:

if (name.equals("Rock")) {

System.out.println("Hi Rocky!!!");

}

The output of the if condition will depend on the value that the variable name holds. This is a decision statement

Why main method is static?

Main method in java is always static as main method id the only method from where the program execution starts,and as we all know that main method is defined inside a class so JVM needs to make a object of the class to call the method and objects are build inside the main method ,so to execute the main method it has to make objects of the class but objects are build inside main method so that's the reason that main method is static so that JVM can execute the main method without making its object as static members can be called by class anme only

In Java where do instance variables stored in memory?

An instance variable is part of an object. Therefore, it gets stored together with the object, on the heap. The heap is the part of memory which is used to store objects.

An instance variable is part of an object. Therefore, it gets stored together with the object, on the heap. The heap is the part of memory which is used to store objects.

An instance variable is part of an object. Therefore, it gets stored together with the object, on the heap. The heap is the part of memory which is used to store objects.

An instance variable is part of an object. Therefore, it gets stored together with the object, on the heap. The heap is the part of memory which is used to store objects.

A java do while loop to count even numbers from one to ten?

The while loop is good for scenarios where you don't know how many times a block or statement should repeat, but you want to continue looping as long as some condition is true. A while statement looks like this:

while (expression) {

// do stuff

}

In this case, as in all loops, the expression (test) must evaluate to a boolean result. The body of the while loop will only execute if the expression (sometimes called the "condition") results in a value of true. Once inside the loop, the loop body will repeat until the condition is no longer met because it evaluates to false.

Any variables used in the expression of a while loop must be declared before the expression is evaluated. In other words, you can't say

while (int x = 2) { } // This is not legal

The key point to remember about a while loop is that it might not run at all. If the test expression is false the first time the while expression is checked, the loop body will be skipped and the program will begin executing at the first statement after the while loop. Look at the following example:

int x = 8;

while (x > 8) {

System.out.println("in the loop");

x = 10;

}

System.out.println("past the loop");

Running this code produces

past the loop

Because the expression (x > 8) evaluates to false, none of the code within the while loop ever executes.

What two steps are needed to create an array?

For example we have a class :

public class Test()

{

public void print()

{

System.out.println("Hello");

}

}

So, if you want to create array from Test type. You can try something like this :

Test[]myTestArray=new Test[2];

myTestArray[0]=new Test();

myTestArray[1]=new Test();

I hope it will help.

What are the advantages of PHP over Java?

HTML - displays data. That's it. That's all it can and will ever do.

as for PHP, I'll list a few things that it's capable of:

-database interaction (add, modify, delete data. Alter database structures and more)

-Output dynamic contents. (ie, do different things according to the time of day, number of time the user has logged in, number of files in a directory, entries in database, etc.). And it's not just text and numbers either. It can generated images, output PDF and more~

-string/text/date manipulation

-error checks

-sessions and cookies (where website remembers you for a period of time)

-compressions and archives

-Cryptography extensions

-maths

and MUCH, MUCH more.

Why do you need a constructor as a class member?

A constructor is not a mandatory member that we need to code specifically for a class. While creating a class, even if we miss out coding the constructor, Java would create a default constructor all by itself.

The constructor is usually the place where we initialize things that are required by the class. Hence it is a good practice to code the constructor for our class.

Tip: If you do not want anyone to instantiate your class, you can declare the constructor as private. In that way no other class can instantiate your class.

What is the purpose of transient keyword in Java?

A variable which is declared as transient will not be serialized. This means that when you use an ObjectOutputStream to store the current state of a class, anything labeled as transient will be skipped over.

A common use of this keyword is to ensure that sensitive user information (usernames, passwords, etc.) is not accidentally saved to a file.

How the equals operator differs from the equals equals operator?

obj2 = true only if both has same memory location.

on the other hand equals() is a method defined in Object class and has overridden in many classes including String, Integer and provides logical equality e.g. two strings are equal by equals() method if there content are same.

Java program to display factors of a number?

One solution is to use a for-loop counting from 1 to half of the number. If the modulus of the number and the current value in the loop is zero, the current value is a factor of the number. The number divided by the current value is also a factor.

What does java generate after compiling the java source code?

Java compiles to Java byte code; the native language of the Java virtual machine (JVM). The JVM is essentially just an interpreter for Java byte code. Each supported platform has its own JVM implementation so the same Java byte code can be executed upon any platform without further compilation, unlike C++ where source code must be compiled separately for each supported platform. However, interpretation results in slower execution speed and higher resource consumption than with C++ which compiles to native machine code.

What are different types of data called?

Some different types of data are real-valued, integer, or Boolean. Boolean Data is data that represents true or false statements Fixed point data types are convenient for representing monetary values

How do you copy a string from one method into another string in another method in java?

You can have two String variables (note that String variables are object references) refer to the same String object like so:

String str1 = "Hello";

String str2 = str1;

Now the str1 and str2 are references for the same String object containing the word "Hello".

If you actually want a new String object with a copy of the contents of the original String, you use the String constructor that takes a String argument, like so:

String str3 = new String(str1);

Now str1 and str3 refer to SEPARATE String objects that happen to contain the same sequence of characters (the word "Hello").

Since Strings objects in Java are immutable, they can be shared without worrying about the contents used by one variable being upset by the use through another variable as might happen with char[] arrays in C or C++ so the first method is probably sufficient for most cases.

Explain the term identifier in java?

Identifiers are the strings you use in Java source code to identify unique things, such as variables, classes, and methods. Identifiers may be any word beginning with a letter or underscore, and continuing with letters, numbers, and underscores. Identifiers are case sensitive.

Advantages of Exception handling in java?

Exception handling helps us catch or identify abnormal scenarios in our code and handle them appropriately instead of throwing up a random error on the front-end (User Interface) of the application.

Exception handling allows developers to detect errors easily without writing special code to test return values. Even better, it lets us keep exception-handling code cleanly separated from the exception-generating code. It also lets us use the same exception-handling code to deal with a range of possible exceptions.