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 is arithmeticexception?

the errors arriving during the execution of a program when there is a mistake of the programmer in applying the correct mathematical logic

eg: int a= 5;

int b=0;

System.out.print(a/b);

System.out.print("correct answer");

in this eg. a runtime error will be shown and to remove it we can use try catch block

Write a java program that implements stack ADT converts infix expression to postfix form evaluates the postfix expression?

// made by vijay NITJ

#include<iostream.h>

#include<string.h>

#include<stdio.h>

#include<math.h>

int precedence(char);

void main()

{

char q[20];

char p[20];

char stack[20];

int tp=-1,ts=0;

stack[0]='(';

cout<<stack;

int i=0, f=1;

cout<<"enter the prefix expression ";

gets(q);

int l=strlen(q);

q[l]=')';

while(ts!=-1)

{

if(q[i]>=47 && q[i]<=58 q[i]<=65 && q[i]<=90 q[i]<=97 && q[i]>=122)

{

p[++tp]=q[i];

}

else if(q[i]=='(')

stack[++ts]=q[i];

else if(q[i]=='+' q[i]=='-' q[i]=='*' q[i]=='/')

{

if(stack[ts]=='(')

stack[++ts]=q[i];

else

{

while(stack[ts]!='(')

{

int p1=precedence(q[i]);

int p2=precedence(stack[ts]);

if(p2>=p1)

p[++tp]=stack[ts--];

else

{

f=0;

break;

}

}

if(f==0)

stack[++ts]=q[i];

}

}

else if(q[i]==')')

{

while(stack[ts]!='(')

{

p[++tp]=stack[ts--];

}

ts--;

}

i++;

}

for(int j=0; j<=tp;j++)

{

cout<<p[j];

}

//precedence program

int precedence(char a)

{

if(a=='+' a=='-')

return 1;

else if(a=='*' a=='/')

return 2;

}

Which statements are nedded to control loop?

A For loop requires 3 parameters:

for( int i = 0; i < 10; ++i )

{

}

So, the first parameter - int i = 0 - shows the integer that you will be using to cycle with. This variable sometimes corresponds with what you're cycling through, so if you're using an array, array notation dictates that you can access the array with integers.

The second parameter - i < 10 - says that if the i variable is less than 10, do the for loop.

The third parameter - ++i - shows by how many you want to increment or decrement the variable by. This means that the for loop I have provided will run 10 times. (Remember: if you start at 0 - which all arrays and vectors e.t.c will do - you need to start your For loop at 0)

What is Java Runtime used for?

A Java Runtime Environment (JRE) is the base set of data files and programs (executables) which are required to run Java Applications. Typically, this consists of a Java Virtual Machine (a virtual computer/processor which the Java program runs 'on'), the Java Libraries (definitions of objects and functionality which Java programs can utilise), and any additional supporting software.

If you have been instructed to get java so that you may use a certain website or piece of software, this means you are required to install a JRE.

The 'standard' JRE is developed by Sun Microsystems, the original developers of Java, and is available at http://java.sun.com/

Typically, each JRE version has had multiple updates since its initial release, so you will probably need to download a file called something like Java 6 update 2, or JRE 6 update 2, or even referred to via shorthand like Java 6u2.

To test which version of a JRE is installed (if any), run the command "java -version" in a command-line (Windows) or Terminal (Unix/Linux/Mac).

Other run-time implementations of Java are available under different license conditions, although most focus on the actual JVM itself, rather than completely re-implementing all of the additional tools and libraries.

The JRE is distinct from the JDK (Java Development Kit) in that the JDK contains additional software which is required only for developing Java applications - such as the Java Compiler javac, and which most users will not require.

How do you execute a package in java?

You don't execute a package; you execute a class. A package is just a grouping of classes.

You don't execute a package; you execute a class. A package is just a grouping of classes.

You don't execute a package; you execute a class. A package is just a grouping of classes.

You don't execute a package; you execute a class. A package is just a grouping of classes.

What is mean by parse in java?

It is used to convert the value of one datatype into a value of another datatype. Example- Integer.parseInt(in.readLine); It converts given value to Integer datatype.

Why path and class-path in java?

1))What is the difference between "path" and "classpath"? Ans:: We keep all "executable files"(like .exe files) and "batch files"(like .bat) in path variable. And we keep all jar files and class files in classpath variables. So path is set according to the .exe files & .bat files And classpath is set according to the .jar files & .class files.

Operating system tries to find .exe and .bat files in path and JVM tries to find all classes in classpath.

What is the future scope of java programming?

Certainly, here's an expanded section on the future scope of Java programming with a reference to your institute, "AchieversIT":

The Future Scope of Java Programming with AchieversIT:

Java programming, often dubbed as the "king" of programming languages, has a remarkably promising future in the world of technology. As technology continues to evolve, so does the relevance and demand for Java expertise. At AchieversIT, we recognize the enduring significance of Java and are committed to equipping our students with the skills needed to excel in this dynamic landscape.

**1. Robustness and Versatility:

Java's reputation for stability, reliability, and cross-platform compatibility remains unshaken. Its ability to run on diverse devices and operating systems makes it an ideal choice for developing applications ranging from web and mobile to desktop and embedded systems. AchieversIT ensures you're well-versed in these foundational concepts, preparing you for diverse software development roles.

**2. Enterprise-Grade Applications:

Java is the backbone of many enterprise-level applications, making it a key player in the corporate world. As an AchieversIT student, you'll gain insights into building robust, scalable, and secure applications that meet the rigorous demands of modern businesses.

**3. Big Data and Data Science:

Java seamlessly integrates with big data technologies like Hadoop and Spark, enabling efficient data processing and analysis. The skills you acquire at AchieversIT will empower you to contribute to the booming field of data science and analytics.

**4. Cloud Computing:

Java powers numerous cloud-based applications and services. As the cloud computing landscape expands, so does the demand for professionals skilled in developing cloud-native applications. Our comprehensive training ensures you're well-prepared for this cloud-driven future.

**5. Android App Development:

Java remains the primary programming language for Android app development. With AchieversIT, you'll master the art of creating captivating and functional Android applications, positioning you for success in the ever-growing mobile app market.

**6. Internet of Things (IoT):

As IoT devices become more prevalent, Java's role in creating embedded software for these devices becomes increasingly vital. Our IoT-focused training equips you to contribute to this exciting and rapidly evolving domain.

**7. Career Opportunities:

With Java's continued dominance in various domains, your proficiency in this language will open doors to a wide array of career opportunities. AchieversIT ensures you're not only proficient in Java but also well-prepared to thrive in your chosen career path.

In conclusion, the future of Java programming is remarkably bright and diverse. With AchieversIT's comprehensive training and support, you'll be well-prepared to harness the endless possibilities that Java offers. Join us in shaping the future of technology through Java expertise. Enroll at AchieversIT today and embark on a journey toward a fulfilling and successful career in the world of Java programming.

Is jvm a compiler?

Basically they do the same: converting from one level of language into another. A compiler converts high level language (programming language like java) into machine-language. That is language a computer understands.

An interpreter converts high level language into an intermediate level. When a program is exectuted, that intermediate level is reconverted to machine language.

Is the loop control variable initialized after entering entering the loop?

Uninitialised variables take on whatever value happens to reside at the memory address to which the variable was allocated at the point of instantiation. It is a "garbage value" because we cannot predict what the initial value will actually be at runtime. All variables must be initialised before they are used (read); if we use an uninitialised variable our program has undefined behaviour.

Ideally, initialisation should always occur at the point of instantiation. However, there can be valid reasons for delaying initialisation. For instance, when we read data from a disk file into a memory buffer, it doesn't make any sense to waste time initialising the buffer with values we're about to overwrite:

void read_file (std::ifstream& file) {

char buffer[1024]; // uninitialised!

while (file.good()) {

size_t index=0;

while (file.good() && index<1024) {

file >> buffer[index++]; // fill the buffer one character at a time

}

if (!file.good()) {

if (file.eof()) --index; // index is off-by-one, so adjust

else throw std::exception ("Unknown error in read_file()");

}

// use the buffer...

}

}

In the above example, index is used as a loop control variable in the inner loop and ultimately tells us how many characters were read into the buffer (such that index<=1024 upon exiting the inner loop). If EOF was reached, index will be off by one because we attempted to read one more character than actually exists, so we decrement accordingly. We could handle other read errors here but, for the sake of brevity, we throw an exception and let the caller deal with it. Assuming no read errors occurred, we can safely use the buffer (all indices less than index are valid). If the file contains more than 1024 characters, the next iteration of the outer loop will overwrite the buffer, so there's no need to flush it.

Now, consider what happens if we (accidently) fail to initialise index with the value 0:

void read_file (std::ifstream& file) {

char buffer[1024]; // uninitialised!

while (file.good()) {

size_t index; // WARNING: uninitialised

while (file.good() && index<1024) {

file >> buffer[index++]; // fill the buffer one character at a time

}

if (!file.good()) {

if (file.eof()) --index; // index is off-by-one, so adjust

else throw std::exception ("Unknown error in read_file()");

}

// use the buffer...

}

}

This code has undefined behaviour. Hope for a compiler warning!

If we suppose that the code compiles without warning (or we unwisely choose to ignore such warnings), there are several possible outcomes. Note that it is reasonable to assume that index will always be allocated the same address so, regardless of the initial value, it will hold whatever value was generated upon the previous iteration of the inner loop.

1. If index happens to hold the (correct) value zero, then the inner loop will read up to 1024 characters. However, any subsequent iteration will incur undefined behaviour because index would then be 1024 which is beyond the valid range of buffer.

2. If index happens to hold a value greater than zero but less than 1024, all characters before buffer[index] will remain uninitialised. Upon exiting the inner loop, there is no way to determine where writing began and index will tell us we've read more characters than were actually read. Any subsequent iteration will incur undefined behaviour because index would then be 1024 which is beyond the valid range of buffer.

3. If index happens to hold a value greater than or equal to 1024, the inner loop will never execute (nothing will be read from the file), thus file.good() can never become false and the outer loop becomes an infinite loop. Any attempt to read buffer[index] or any value beyond buffer[1023] incurs undefined behaviour.

How do you declare symbolic constants in Java?

Symbolic constants are named constants

like :

final double PI = 3.14 ;

They are constants because of the 'final' keywords, so they canNOT be reassigned a new value after being declared as final

And they are symbolic , because they have a name

A NON symbolic constant is like the value of '2' in expression

int foo = 2 * 3

How do you synchronize java?

Synchronizaion is the process by which only one Thread can access an object at a time,until and unless thread releases it's lock no other thread can acess the object. there are two forms of syncronization method and statement.

to make a method synchronized just add the keyword synchronized to the signature ie: public synchronized void increment() {

c++;

}

to create syncrhonized statements are like this:

synchronized(this) {

lastName = name;

nameCount++;

}

note: constructors can not be syncronized

Can you call an abstract method from a non abstract method in java?

We can't call (i.e, execute) an abstract method in java because these methods don't contain any code to execute!

In some special cases like when an abstract method is overridden in a subclass, and when we are using super class reference variable( which is referring that subclass object), it appears that we are calling abstract method in super class. But actually the code in the subclass method is being executed.

Example:

abstract class SuperClass{

abstract void show(); //abstract method in super class

}

class SubClass extends SuperClass{

void show(){ //show() of SuperClass overridden in SubClass

System.out.println("SubClass Method");

}

}

class Example{

public static void main(String... args){

SuperClass sup=new SubClass();

sup.show(); //SubClass show() will be executed !!!

}

}

What is static void Main?

The String array args refers to the arguments that the program may require before starting. In many cases you may want the program to take some values as input for processing. this string array is for that purpose.

What does private int mean in java?

The private keyword denotes that the field or method is hidden from view of any other class.

class MyClass {

private int n; // n cannot be accessed by any class except MyClass

private void doSomething(){} // doSomething cannot be accessed by any class except MyClass

}

What is the class of a barnacle?

Barnacles are shrimp-like arthropods that swim free when young then glue themselves to some hard surface and spend the rest of their life kicking food into their mouths with their feather-like legs.

What is different between inheritance and encapsulation?

wrapping up of data and function into a single unit is called encapsulation where polymorphism is the ability to take more than one form

What function initializes variables in a class?

you have to initialize it into the "Constructor" which is a function without dataType and it's name is the same with the class name

EX:-

class Exforsys

{

private:

int a,b;

public:

Exforsys();

...

};

Exforsys :: Exforsys()

{

a=0;

b=0;

}

the EX from : http://www.exforsys.com/tutorials/c-plus-plus/class-constructors-and-destructors-in-c.html

I recommend this link for You Under the title "Constructors and destructors" :

http://www.cplusplus.com/doc/tutorial/classes/

You can also See : http://www.win.tue.nl/~maubach/university/education/online-references/cpp/swartz/notescpp/oop-condestructors/constructors.html

What is a java destructor?

A destructor is exactly the opposite... it gives the object a chance to grab any objects that need to be free'd prior to being freed itself. If care is not taken to "free" objects that have been used but are no longer required this is what is sometimes called a "memory leak". The memory allocated to that object is lost for use. It cannot be re-used for anything else because it is considered "still allocated" even though it is not in use. Generally, this type of program runs out of memory if it is something that runs for days without being restarted.

smartlink4u@hotmail.com

Usama Ikhlaq

How do you stop the error Java is not recognized as an internal or external command operable program or batch file?

If you are getting that error, it means that either Java is not installed, or is not in your path.

If Java is not installed, go to http://www.java.com to install the most recent version of the JRE.

If you're sure you have already installed Java ensure the Java executable is in your system's path. You can do this by first finding the directory it is installed in. For example, mine is installed in C:\Program Files\Java\jre6. The executables are located in the bin directory.

In order to set your path (Assuming Windows Vista), go to Start -> Control Panel -> System, then click on the 'Advanced System Settings' link on the left, then the 'Environment Variables' button. In the lower section (Labeled 'System Variables'), scroll through and find the item labeled 'Path' and double click it. In the field labeled 'Variable value' go to the end and add a semicolon (;), and then the path your installation of Java is located. Using the example I gave above, I would have added ;C:\Program Files\Java\jre6\bin to the end of the line.

The procedure for 64-bit Windows Vista or Windows 7 is the same, except the text you will add to the Path variable is ";C:\Program Files (x86)\Java\jre6\bin". Notice there is still a semi-colon at the beginning of the line.

Once you have done this, you will need to close and reopen the command prompt if it is already open, and you should be able to run java without getting this error message.

When do you use template or prototype?

a template is in business when you are making different models based around the same idea and a prototype is a product used when giving a pitch to some investors or consumers about to buy the product before it goes on sale and gets mass produced

What is the difference between sign and unsign in Java?

Normally, signed and unsigned data types just refer to whether or not a value can be negative or not.

An unsigned 4-bit value can be the values 0 to 15

A signed 4-bit value can be the values -8 to 7

However, there is no such thing as an unsigned value in Java*. All primitive types are signed by default and cannot change.

*Note that technically a char value can be considered an unsigned type. The only way to see this is to declare a char with value '\uffff' (or 65535) and try to print it out as both a short and an int. If you try this with any other data types, the larger values will display the same as the smaller values. Not so with the char example.

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.