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 the definition of a base-class constructor?

A base class constructor is simply a constructor that is declared within a base class. There is nothing particularly special about them since all constructors are only of relevence and applicable to the classes in which they are declared.

How do you empty a file using C programming?

That depends on the type of file and what you mean by "empty". Generally, fopen() called on an existing file, with the "w" option instead of the "a" option will truncate the file to zero length. To delete a file completely is a different process. Function truncate is your friend.

What is hyper text markup language and describe its role in implementation of java applets?

Short for HyperText Markup Language, the authoring language for creating documents on the world wide web.HTML defines the structure and layout of a Web document by using a variety of tags and attributes.

The correct structure for an HTML document starts with (enter here what document is about) and ends with < All the information you'd like to include in your Web page fits in between the and tags.

HTML is very important in describe of java applets and its implementation.

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a page. When you use a Java technology-enabled browser to view a page that contains an applet, the applet's code is transferred to your system and executed by the browser's Java Virtual Machine (JVM).

What are the best ways to learn and understand Java and what books are good for this?

Best way to learn Java is start from basic.Get a clear picture about JVM and JRE.Even if you write a simple program,try to understand what happens behind your code.I suggest you to read more about java at http://allinalljava.blogspot.com. At first while writing your code attach java source behind ,due to that you can easily admire real scenario happen in it.

I suggest you try http://academicjava.com. It's a resource of many example programs with explanations and there's a very good tutorial.

"Head first JAVA" is the book I recommend but it's a question of what's best for you. Go to a good bookshop and browse what's available.

At first, i would like to tell you the BEST way to learn JAVA is just "Type Java programs n execute them". start with simple programs...

"Head first JAVA" - It is the one of the best book to learn Java.

If you want to understand Java's advantages elaborately , then u can refer this page too

http://www.artima.com/insidejvm/ed2/

Best way to learn java is think of something real-world that you understand well and can automate. Write something like an electronic recipe organizer. The best book? Do a google search for "Java, The Complete Reference, J2se" Good luck!

That is a good book. Also try "Java In A Nutshell" from O'Reiley books. It makes an excellent quick reference and is very straightforward.

Yes, these are great resources and adding one more resource to the list which i found helpful while starting with Java --> the tutorials from Sun. You can find them here http://java.sun.com/docs/books/tutorial/

Happy Learning : )

What is sub class in Java?

A sub class is paired up with its super class. These can also be called a child and parent class.

The subclass will inherit all of the variables and methods from its superclass. And one superclass can have multiple subclasses, but a subclass can only have one superclass.

Here's an example:

public class childName extends parentName {

...

}

This means that childName will inherit everything from its superclass, which is parentName.

The advantage of this inheritance is that you do not need to copy/paste lots of code for many similar subclasses, and if you want to change something you only need to make one change in the superclass.

Describe three advantages of Java programming language?

Java has many more than 3 characteristics, which can be labelled "advantages"; of course, most of the following are shared by several other languages.

  • Java is object oriented (I wouldn't want to program on any language that doesn't!)
  • Java runs on multiple platforms (Windows, Linux, etc. - some languages work only for Windows, for example).
  • Java has native support for Unicode - this is the standard for strings. (This makes it easy to use Java with different languages, including languages that don't use the Latin alphabet.)
  • Java has built-in support for multithreading. This makes it possible to run several things at once.
  • The designers of Java have put a lot of effort into detecting many error situations during compilation. That will increase the quality (stability) of the finished product.
  • Java is free.
  • There is a huge collection of components already written in Java, for different aspects. This means that in many cases, you don't have to design everything from scratch.

What is the use of throws io exception in java?

an IOException is any unexpected problem the compiler encounters while attempting to run a program. Possible problems the compiler may encounter are attempting to read from a file that does not exist, write to a file which has an invalid name (a slash or a question mark in the title should do it), or attempting to read the next token in a file when there are no more tokens.

What is classNotFound Exception in java?

If you are getting this error message, it means you are trying to use a class that is not located in your JVM classpath. In order to resolve this error, you must find the .class or the .jar file that contains the class you need, and add it to your classpath.

Depending on the application, it might be as simple as changing your CLASSPATH environment variable. Here is a good article on the Java classpath:

http://en.wikipedia.org/wiki/Classpath_(Java)

Here is a good online utility to help you quickly find the right jar and download it. It will save you hours of searching through various blog posts on the internet trying to find out which jar contains which class file!

http://www.ClassNotFound.com/

Write a program which uses Command Line Arguments?

IN C++

#include <iostream> int main(int argc, char *argv[]) { using namespace std; cout << "There are " << argc << " arguments:" << endl; // Loop through each argument and print its number and value for (int nArg=0; nArg < argc; nArg++) cout << nArg << " " << argv[nArg] << endl; return 0; }

What is the need of package in java?

Packages are containers-for-classes used to keep the class namespace compartmentalized.

Using Package,

1. We can define classes inside a package that are notaccessible by the code outside that package.

2. We can define class members that are only accessible by code inside that package.

3. We can have a class stored in a package withoutconcern that it will collide with some other class (havin same name), stored else where.

Package is basically a collection of predefined or ready-made classes that can be used in your java program to make shorter as well as easier. Package- import java.lang.*; is always implicitly called when you write a java program.

What is standalone application?

It means that it is by itself - as opposed to being bundled with other applications for example.

Java program that prints prime numbers between 1 to n?

The easiest way is to use a prime sieve (google Sieve of Eratosthenes).

Here is pseudo-code for the algorithm.

- create a boolean array of size n

- for every true index 2 through n

- - keep the index as true, mark all multiples of the index as false.

So, for example, if n=10

start with 2, keep 2 true. Mark 4,6,8,10 as false.

next is 3, keep it true. mark 6,9 as false (6 was already false).

next is 4, it is false, skip it.

next is 5, keep it true. mark 10 as false (it was already false).

6 is false, skip it

7 is true, keep it true. the next multiple of 7 is greater than 10

8,9, 10 are all false.

you are done - the values marked true (1,2, 3,5,7) are your primes.

Which keyword is used to declare a class?

There is no keyword for it. You can use a variable of 1 class in another only id the other class is derived from the 1st class.

Although you can use the variable of an object of a class in another class using object.variable

Inheritence and its types in object oriented programmings?

There are only two types of inheritance in object oriented programming:

Single inheritance: where a class inherits directly from just one base class.

Multiple inheritance: where a class inherits directly from two or more base classes.

Multi-level inheritance is often thought of as being a separate type of inheritance, however inheritance relates to a derived class and those that it directly inherits from. If a base class is itself a derived class (an intermediate class), then its base class or classes are simply indirect base classes of the derivative. But in isolation, the intermediate class either uses single or multiple inheritance, even if its base class or classes are also intermediates.

Virtual inheritance is also thought of as being a separate type, however virtual inheritance doesn't change the relationship between classes within the hierarchy. the only difference virtual inheritance makes is that the virtual base class or classes are constructed by the most-derived class within the current hierarchy, rather than by their most direct descendants. In this way, only one instance of each virtual base exists in the hierarchy, rather than multiple instance as would normally exist. The actual inheritance is still single or multiple, however.

How and where is the Java programming language used?

The computer-programming language Java is used when a powerful object-oriented programming language that can execute on a variety of operating systems, with little or no alterations to the code, is needed. Java "applets" are ideal for distribution over the internet owing to the diversity of systems that support Java and the inherently small size of the applet download.

How do you use sub string in java?

Substring method creates smaller string form bigger string , every time a new string is created but original character array buffer is used. so even if original string is 1G in size and substring is just 1K memory held by substring is 1G because of backed array. this can cause memory leak and prevent original string from garbage collection even if there is no direct reference.

How can you use abstract classes instead of interfaces?

In most cases, you will want to use abstract classes IN ADDITION to interfaces.

You should use an abstract class in the following circumstance:

  1. the abstract class is clearly part of class hierarchy, and does not just describe some sort of basic functionality. Specifically, abstract classes are a good idea where they will be directly inherited from to create a concrete concept, but the abstract class itself is too indistinct to have any specific instance of it created.
  2. You want to provide an implementation for a set of methods that will be reused by a significant number of other classes, all of which can be fit into a class hierarchy.

In practice, abstract classes are a good way to collect common code into one place, to make maintenance easier.

For instance, say you have a class and interface structure like this:

Class A

Interface X

Class B extends A implements X

Class C extends A implements X

Both B and C will have the all the methods declared in X; if the implementation of those methods is the same (or can be made the same), then X is a good candidate for changing to an abstract method:

Class A

Abstract Class X extends A

Class B extends X

Class C extends X

Thus, you have removed the code duplication that was happening when using interfaces.

Note that doing the above is NOT a good idea if any class which implement interface X cannot be made a subclass of the new abstract class X.

What is the purpose of the finally clause of a try-catch-finally statement?

The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught. It is usually used in places where we are connecting to a database so that, we can close the connection or perform any cleanup even if the query execution in the try block caused an exception

How is Ajax better than Javascript?

For the most part Javascript is used to make web pages dynamic, move elements on the page, highlighting areas of the page, bringing in new content from the server, etc. There are other cases though like node.js where it's used as a server to make the web pages themselves. There are also a few cases outside of the web world where javascript can be used, some robotics, etc.

What happens when you declare class as a static in Java?

Declaring an inner class static means that class only has access to the "outer" class public and private static fields. A non-static inner class has access to the outer class's instance data. Top-level classes cannot be declared static.

The advantage of a static inner class is that it doesn't need an instance of the containing class to work and it's bytecode class size is smaller for that reason - less overhead.

How do you write method in Alice programming?

Alice is an innovative 3D programming environment that makes it easy to create an animation for telling a story, playing an interactive game, or a video to share on the web. Alice is a freely available teaching tool designed to be a student's first exposure to object-oriented programming. It allows students to learn fundamental programming concepts in the context of creating animated movies and simple video games. In Alice, 3-D objects (e.g., people, animals, and vehicles) populate a virtual world and students create a program to animate the objects.

In Alice's interactive interface, students drag and drop graphic tiles to create a program, where the instructions correspond to standard statements in a production oriented programming language, such as Java, C++, and C#. Alice allows students to immediately see how their animation programs run, enabling them to easily understand the relationship between the programming statements and the behavior of objects in their animation. By manipulating the objects in their virtual world, students gain experience with all the programming constructs typically taught in an introductory programming course.

Primitive methods in Alice 2.0
  1. move(direction,amount)
  2. turn(direction,amount)
  3. roll(direction,amount)
  4. resize(amount)
  5. say(what)
  6. think(what)
  7. playSound(sound)
  8. moveTo(asSeenBy)
  9. moveToward(target,amount)
  10. moveAwayFrom(target,amount)
  11. orientTo(asSeenBy)
  12. turnToFace(target)
  13. pointAt(target)
  14. setPointOfView(asSeenBy)
  15. setPose(pose)
  16. standUp()
  17. moveAtSpeed(direction,speed)
  18. turnAtSpeed(direction,speed)
  19. rollAtSpeed(direction,speed)
  20. constrainToPointAt(target)

Methods in Alice

Methods in Alice can exist at either the world level or at the class (object) level. The closest analogy that I can draw to more conventional programming languages such as Java is that world-level methods are sort of like class methods in Java while class-level methods are definitely like instance methods in Java.

For this program, I defined two additional methods at the world level named:

  1. setTheStage
  2. playTheShow

As the names imply, the purpose of the first method is to get everything ready for the show and the second method actually presents the show. As you can see, the code in Listing 2 calls these two methods in sequence.

Where can one find a Java Jdk download?

Java is a programming language that allows users to play games, chat with other users, and perform financial calculations among other things. The online site "Oracle" is excellent for downloading all Java software, including Java JDK.

Why do we need constructor?

when the object is instantiated(created) and delared,it has to assigned with variables.constructor is used for this purpose. syntax: classname ojbectname=new classname(); here classname() is a constructor. eg: box bb=new box(5,10); when this object is instantiated,it can be directly accessed by the constructor(similar to method but without a void because the instance variables are directly used) box(5,10) { }

What is c plus plus data type?

The C++ string classes are derived from the std::basic_string<T> template class, where T is a character type. The standard provides the two most common string types, std::string (std::basic_string<char>) and std::wstring (std::basic_string<wchar_t>). The former is used for ASCII strings (which includes UTF-8 strings) while the latter is used for wide-character strings, particularly UNICODE strings.

All standard library strings are represented by an array of some character type (such as char or wchar_t) however, unlike an ordinary array, the individual character elements cannot be re-ordered other by overwriting each character. If you simply need an array of characters that can be re-ordered then use a std::vector<char> or std::vector<wchar_t> rather than a string.

The standard library strings include a rich set of methods, operations and algorithms that are commonly used with strings, such as std::string::find() to locate a character within a string, std::string::substr() to extract a substring from a string, and operator+= to concatenate one string onto another. Most implementations include the short string optimisation so that short strings (up to around 14 characters or so) may be stored in local memory rather than on the heap. Many strings tend to be short so this can provide enormous performance benefits with little cost in terms of memory.