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 synchronized methods and synchronized statements in java?

Synchronized Methods are methods that have the keyword synchronized in the method signature.

Synchronized statements are pieces of java code that are surrounded by brackets which have the keyword synchronized qualifying them.

Both cases mean that - only one thread will be able to access the method or the statement that is synchronized

What is bin in JDK?

Bin contains all tools such as javac,appletviewer,awt tool etc where as lib contains API and all packages.

The bin folder contains the binaries - the actual executable programs. The lib folder contains the libraries upon which the binaries are built.

A program to explain the Exception Handling mechanisms in Java using the keywords try catch and finally?

Here is a code snippet illustrating exception handling:

try {

int a= 3 / 0 ;

} catch ( ArithmeticException e ) {

System.out.println ("An ArithmeticException has occured");

} finally {

// some code

}

Tell you difference between c and java?

Apart from the obvious differences in syntax the single biggest difference is that Java is an object orientated programming language while C is not (C's big brother C++ is though). C simply executes code line by line with its variables defined in the main body of the program or within functions. Java, like other object orientated languages, is concerned with objects that hold their own variables and functions. For example, if you want to draw 3 squares on your screen, each of a different colour, in C you would define variables like SquRedLength, SquRedHeight, squRedColour, and the same for the other colour squares. Nine separate variables need to be coded and accessed by name. In Java you would simply define an object 'square' and then create three square objects. This is a much more powerful approach (imagine if you wanted 10,000 squares!).

Differences Between Java, C And C++This article aims to set out some of the differences between C, C++ and Java. What it does not aim to do is conclude that one language is always the best one to use. Language choice depends upon a range of factors including field of application (operating systems, desktop software, web applications etc), what programming paradigm suits the application (OOP, procedural, etc), the target platform and available programmer expertise. What follows should help you decide where it might be suitable to use C, C++ or Java.

Paradigm

C is geared towards procedural programming. That is, you write a number of procedures to do certain tasks and build up a program by calling those procedures as needed.

Java, on the other hand, is geared towards OOP (object oriented programming). With OOP, you define classes which represent an entity (for example, a window, a button, a string of text, a file). From one class many objects may be created, with every object of a certain class having the fields (places to store data) and methods (named blocks of code associated with the object) as defined by the class.

It is possible to write in an object oriented style in C and in a procedural style in Java, but in each case the language will somewhat get in your way. C++ is designed to support both paradigms.

Preprocessor

All C and C++ compilers implement a stage of compilation known as the preprocessor. The preprocessor basically performs an intelligent search and replace on identifiers that have been declared using the #define or #typedef directives. #define can also be used to declare macros. For example, a macro MAX(x,y) could be defined to return whichever of x or y holds the greatest value. This is not like calling a function as the substitution is done before the code is compiled. Most of the preprocessor definitions in C and C++ are stored in header files, which complement the actual source code files.

Java does not have a preprocessor. Constant data members are used in place of the #define directive and class definitions are used in lieu of the #typedef directive, however there is no substitute for macros, which can be useful. The Java approach to defining constants and naming types of data structures is probably conceptually simpler for the programmer. Additionally, Java programs don't use header files; the Java compiler builds class definitions directly from the source code files, which contain both class definitions and method implementations.

Memory Management

In C and C++, any memory that is allocated on the heap (e.g. using malloc or new) must be explicitly freed by the programmer (e.g. using free or delete). Forgetting to free memory leads to memory leaks, and in long-running programs can lead to the memory usage of the program growing very large.

Java provides garbage collection, meaning that memory is freed automatically when it is no longer reachable by any references. This prevents memory leaks, but can lead to pauses in execution while the garbage collector runs. Also, there is no promise of timely destruction in Java.

Pointers

Most developers agree that the misuse of pointers causes the majority of bugs in C and C++ programs. Put simply, when you have pointers, you have the ability to attempt to access memory that isn't yours and modify memory relating to a different data structure than the one you intended by accident. C/C++ programmers regularly use complex pointer arithmetic to create and maintain dynamic data structures. It's powerful, but can lead to a lot of time spent hunting down complex and often subtle bugs that arise as a result of having unguarded memory access.

The Java language does not support pointers. Instead, it provides similar functionality by making heavy use of references. A reference can be thought of as a "safe pointer" - the programmer can not directly manipulate the memory address. Java passes all arrays and objects by reference. This approach prevents common errors due to pointer mismanagement. It also makes programming easier in a lot of ways simply because the correct usage of pointers is easily misunderstood by inexperienced programmers.

C++ does provide references too. It considers them as aliases to another variable or object. They are safer than pointers where they can be used.

Bounds Checking

An array in C or C++ is not bounds checked, so attempts to access the sixth element of a 5-element array will appear to work - that is, no runtime error will occur. This means the programmer needs to code very carefully, especially considering the potential for buffer overflow attacks.

Java will bounds check arrays to prevent this from happening, of course with a little extra runtime cost.

Portability And Performance

C and C++ both compile to native machine code. This means that, with a good compiler, programs written in these languages will perform very well. However, it also restricts them to running on the platform they were compiled to run on.

Java generally compiles to Java bytecode, which then runs on top of a virtual machine (the JVM). The JVM has to turn instructions in the bytecode into instructions that are understood by the machine that the bytecode is running on. This gives a runtime performance penalty (although this is getting less significant as the JVM improves and computers get faster). However, now only the virtual machine (and standard library) have to be ported to different platforms, then the bytecode for many Java programs can be executed on that platform. So bytecode is portable accross different operating systems and processors.

Complex Data Types

There are two types of complex data types in C: structures and unions. C++ adds classes to this list. Java only implements one of these data types: classes.

A structure can be emulated by a class - simply write a class without any methods and make all the fields public. However, emulating a union is not always possible in Java, and the memory saving advantages unions hold in C may not carry accross. Java presents a simpler model but at the cost of not being able to save a little memory. For many applications this will be a non-issue.

Strings

C has no built-in string data type. The standard technique adopted among C programmers is that of using null-terminated arrays of characters to represent strings. This practice if often seen in C++ programs too.

Neither C++ or Java have string as a primitive type, but they do both have string objects that are a standard part of the language. In Java this type is called String, and in C++ it is called CString.

Multiple Inheritance

Multiple inheritance is a feature of some object oriented languages that allows you to derive a class from multiple parent classes. Although multiple inheritance is indeed powerful (and sometimes the logical way to define a class hierachy), it is complicated to use correctly and can create situations where it's uncertain which method will be executed. For example, if each of the parent classes provide a method X and the derived class does not, it is unclear which X should be invoked. It is also complicated to implement from the compiler perspective.

C++ supports multiple inheritance. Java provides no direct support for multiple inheritance, but you can implement functionality similar to multiple inheritance by using interfaces in Java. Java interfaces provide method descriptions but contain no implementations. Therefore implementations can only be inherited from one class, so there is no ambiguity over which method to invoke.

Operator Overloading

Operator overloading enables a class to define special behaviour for built-in operators when they are applied to objects of that class. For example, if the * (multiply) operator was to be used on two objects of type Matrix, then matrix multiplication could be implemented. This allows object types to feel much more tightly integrated into the language and can deliver much clearer code. However, sometimes it is not clear what a particular operator would sensibly do for a particular type, whereas a well-named method call would be clear.

Operator overloading is considered a prominent feature in C++. It is not supported in Java, probably in an effort to keep the language as simple as possible and help ensure it is obvious what code does, even though it may take longer to type and read.

Automatic Coercions

Automatic coercion refers to the implicit casting of data types that sometimes occurs in C and C++. For example, in C++ you can assign a float value to an int variable, which can result in a loss of information, although a compiler warning will be given about this. Java does not support C++ style automatic coercions. In Java, if coercion will result in a loss of data, you must always explicitly cast the data element to the new type.

Goto Statement

The goto statement is rarely used these days in C and C++, but it is a standard part of the language. The goto statement has historically been cited as the cause for messy, difficult to understand, and sometimes near impossible to predict code known as "spaghetti code." The primary bad usage of the goto statement has merely been as a convenience to substitute not thinking through an alternative, more structured branching technique. Very occasionally, it can lead to clearer code.

To avoid the potential for "spaghetti code", Java does not provide a goto statement. The Java language specifies goto as a keyword, but its usage is not supported. This is consistent with Java's desire to make programmers write clear, non-messy code.

Variadic Arguments

C and C++ let you declare functions, such as printf, that take a variable number of arguments. Although this is a convenient feature, it is impossible for the compiler to thoroughly type check the arguments, which means problems can arise at runtime without you knowing. Java doesn't support variable arguments at all, though if it did it would likely be able to handle subsequent runtime problems better than C or C++.

Command-line Arguments

The command-line arguments passed from the system into a Java program differ in a couple of ways from the command-line arguments passed into a C++ program. First, the number of parameters passed differs between the two languages.

In C and C++, the system passes two arguments to a program: argc and argv. argc specifies the number of arguments stored in argv. argv is a pointer to an array of characters containing the actual arguments. In Java, the system passes a single value to a program: args. 'args' is an array of Strings that contains the command-line arguments.

Table Comparing C, C++ and Java

This table is a summary of the differences found in the article.

Feature C C++ Java Paradigms Procedural Procedural, OOP, Generic Programming OOP, Generic Programming (from Java 5) Form of Compiled Source Code Executable Native Code Executable Native Code Java bytecode Memory management Manual Manual Managed, using a garbage collector Pointers Yes, very commonly used. Yes, very commonly used, but some form of references available too. No pointers; references are used instead. Preprocessor Yes Yes No String Type Character arrays Character arrays, objects Objects Complex Data Types Structures, unions Structures, unions, classes Classes Inheritance N/A Multiple class inheritance Single class inheritance, multiple interface implementation Operator Overloading N/A Yes No Automatic coercions Yes, with warnings if loss could occur Yes, with warnings if loss could occur Not at all if loss could occur; msut cast explicitly Variadic Parameters Yes Yes No Goto Statement Yes Yes No

How do you achieve multiple inheritance?

Any class can extend one class and/or implement multiple interfaces.

For example:

public class TestClass extends SuperTestClass implements InterfaceA, InterfaceB {

// implementations of interface methods in here

}

What is an essential of Object Oriented Programming?

The 3 essential concepts of Object Oriented Programming are:

  1. Inheritance
  2. Encapsulation &
  3. Polymorphism

What is the name of java compiler?

It is simply called the Java compiler. The actual program is usually called Javac.

What is jqsiestartdetectorimpl class as an add on?

It appears to be the Java Quickstater browser plugin. As mentioned before, it shows up in a lot of hijack this entries, but not as a threat (lots of people have this as it is installed in the latest versions of java). If you are concerned, feel free to disable it or remove it. The only downside is you may have to wait an extra second or two for a web java application to start up (ex: chat rooms).

What are the codes examples for multi level inheritance?

1. Single Inheritance

A Scenario where one class is inheriting/extending the behavior of just one super class.

Ex: public class Ferrari extends Car {…}

2. Multilevel Inheritance

A Scenario where one class is inheriting/extending the bahavior of another class which in turn is inheriting behavior from yet another class.

Ex: public class Automobile {…}

Public class Car extends Automobile {…}

Public class Ferrari extends Car {…}

This multilevel inheritance actually has no limitations on the number of levels it can go. So as far as java goes, it is limitless. But for maintenance and ease of use sakes it is better to keep the inheritance levels to a single digit number.

How do you define constant in java?

The null literal can be assigned to any Object reference in Java, and is usually used to indicate the absence of something. The main use of it is to indicate that a reference has yet to be instantiated. It can also be used as a return type for things like Collections to indicate that the object you're looking for doesn't exist in that particular Collection.

How do you declare an int array?

we define the array is

Array array[]={1,2,3,4,5} this is the integer Array

Array array[]={"apple","banana","carrot","mango"} this is the String Array

Differences between Java Applet and Java Beans?

Java applet is a program used to run java applications while beans is a compiler used to design java programs (IDE, GUI) :-) GilbertC

What is the difference between the constructor to and destructor?

Functions and Constructors are similar in many ways. They can have arguments, they can have any amount of code, they can access the class's variables etc. the only difference is that a method in java needs to mandatorily have a return type but a Constructor in java cannot have a return type. It always creates and returns an object of the class for which it is the constructor. You cannot return a value from a constructor explicitly and if you try to do that, the compiler will give an error. The system knows that the purpose of the constructor is to create an object of the class and it will do the same irrespective of whether you declare a return type or not.

Why java is called purely object oriented language?

Java is called a "pure" object-oriented language because it requires that all code written in it be wrapped in objects.

This differs from the more common meaning of "pure" object-oriented (everything is an object) in that Java has primitive types and primitive operations on them - int, char, double, float, long and addition, subtraction, multiplication, division. A real example of a PURE object-oriented language is Smalltalk, one of Java's predecessors.

Where can one find information on implementing a Javascript alert?

You could open a new window instead and set it to a certain size using window.open(). You would have to program a button that closes the window but that is quite easy.

You could also insert lots of new lines with '\n' in the alert text, but there's no way to change the width.

What is Pascal Java and C?

its just a different programming language, different programming languages are like real languages its just a different way of saying things however some are more complex, sophisticated, than others and some can do more than others

How much does a programming language generally cost?

Many programming languages, such as Java, are completely free to use, and being one of the major players in the programming language wars, as well as being cross-platform, in addition to being easy to learn, and in addition to it being free, many choose Java for their first language.

Another question: your question makes no sense: you cannot buy or sell programming languages.

What happens if the static modifier is removed from the signature of the main program in java?

Actually speaking nothing major happens. That method would become just another method in the class. You cannot use that as the method to begin the program execution in your class. Your class will not be a standalone java program and you cannot execute it like you did before using the public static void main() method.

How class accomplish data hiding?

Data hiding is one of the important aspects of a class. Data hiding means to hide the members of the class and providing the access to only some of them. we can make the members of the class private or public. in private,the outside world cannot access those members which been made private.and rest we can make public.only the public members are accessed by the out side world and all the private members can be accessed using only the public members.in this way a class provides security to its data members.

A final class can have instances?

Yes. You cannot inherit a final class but very well instantiate a final class

Why one public class in one source file in java?

The rules of Java state that the top-level main class needs to be declared "public." The idea behind this is probably because if it was not declared "public," then it would have to be either "private" or "protected." Since these other two types of classes can only be used by classes of the same package (or more local), and thus a non-public main class could not be called from the outside.

Give an example of an abstract data type?

some common adt's which prived useful in agreat variety of applications are container, deque ,list, map, multimap ,multiset , queue ,setstack, string, tree

"another answer"

"if we declare an integer value in c++, int x, we can say that the name attribute has value(x) and that the type attribute has value(int x=4) the value of attribute has value four.

What is the use of blue dot receptor in java ring?

  • The R/W operation in java ring is done by blue dot receptor provided by RS232 serial port adapter. DS1402D-DR8 is a 1-wire network cable designed to connect to any serial or USB 1-wire port that has up to two buttons simultaneously.
  • Information is transferred between an iButton and a PC with a momentary contact, at up to 142kbps.We just need to touch our iButton to a Blue Dot receptor or other iButton probe, which is connected to a PC.
  • The Blue Dot receptor is cabled to a 1-wire adapter that is attached to the PC's serial or parallel port.
  • Each receptor contains two Blue Dots to accommodate instances where multiple iButtons are required to complete a transaction.

How do you explain a database?

A database is a server, or storage spot were information is stored. The stored information can range from user information to settings. http://en.wikipedia.org/wiki/Database