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 global variable in java?

A local class is declared locally within a block of Java code.

You can even have classes declared inside a method. such classes are called local classes.

What is the need of object oriented programming?

Structured programming is task-centric, object oriented programming is data-centric.Task-centric vs. Data-centricStructured programming is based around data structures and subroutines. The subroutines are where stuff actually "happens", and the data structures are simply containers for the information needed by those subroutines.

Object oriented programming, on the other hand, shifts your primary focus to the data itself. Instead of asking "what do I want to do and what will I need to know to do it", you ask "what kind of things do I want to have and what can those things do for me". Instead of designing your functions first and then coming up with data structures to support them, you design types first and then come up with the operations needed to work with them.

Three OOP PrinciplesPerhaps the most important feature of OOP is polymorphism, the ability to identify certain aspects that several data types have in common, and write code that works equally well with all of them by ignoring the differences in situations where they don't matter.

For example, consider a simple drawing program where you have a set of shapes (circles, rectangles, etc.) that share certain things in common (they all have a location, size, and color) but are different in other ways (how they look or whether they can be rotated). In a structured program, you'd write a function to draw a shape, containing logic like "if the shape is a circle, do ABC; if it's a rectangle, do XYZ" and so on.

But in an OO program, you'd simply tell the shape to draw itself, and the shape would know, based on its own type, what to do: you write a specialized drawing function when you define each shape, and when you send a "draw" message to any shape, it automatically calls the one for the correct shape type. Polymorphism eliminates the need for you to check what kind of shape it is: you just have to know that shapes can draw themselves, and let the shape worry about how it actually happens.

Another important OO principle is encapsulation, the ability to bundle code and data together in one place and hide that data from the outside world, forcing anyone who wants to access it to go through the associated code. For example, all shapes have a location and a size, but the best representation might be different. A circle only needs three numbers (center X, center Y, and radius) but a rectangle needs four (top, bottom, left, right). Structured programming encourages code everywhere to deal directly with the innards of data structures, so most likely you'd need to use the same representation for all shapes in order to avoid checking the type every time you wanted to measure a shape, even though that representation is wasteful for circles.

Object oriented programming addresses that problem two ways: first, encapsulation says that the internal representation of a shape is off-limits to anyone else, so if you want to know how big a shape is, you have to call its getSize() method instead of reading its size directly out of memory. Second, polymorphism allows different shapes to implement their getSize() methods differently, allowing circles to use a more efficient version while presenting the same interface to the outside world.

Finally, there's inheritance, which makes it easy to extend existing structures to produce new structures with slightly different behavior. For example, a filled circle is mostly the same as a regular circle, but it draws itself differently and also has a fill color. In a structured program, you'd probably handle filled circles by adding a fill color to all shapes and a flag that indicates whether the shape is filled or not, and the fill color would simply go unused (wasting memory) in unfilled shapes. In an object-oriented program, you can make FilledCircle a subclass of Circle, inheriting all the existing circle behavior, and then replace the draw() method and add a place to store the fill color. Then if you changed something about Circle later, the change would automatically propagate to FilledCircle, while changes you made to FilledCircle would not affect any other shapes.

Design vs. LanguageWhether your code is object oriented or merely structured depends partly on your choice of language, but also on your design. For example, the C language doesn't offer any features for object oriented programming, but with enough discipline you can still write object-oriented code in C, such as the GTK windowing library. On the other hand, you can write a Java program that completely fails to take advantage of Java's OOP features, by putting all your code in a single class and using classes with public members just as you'd use structs in C. One organizes code by comprehensiveness while the other organizes code by the data affected.Structured programming consists of breaking big problems into smaller problems, then further breaking those into still smaller problems, and so on, until a level of such simplicity is reached that the implementation is obvious to the programmer expected to do the coding. Object-oriented programming consists of grouping code with the data on which it operates so that this "object" can function independently of the rest of the software system. Structured programming and object-oriented programming are not mutually exclusive. You can structure the code in an object, and you can use objects to implement the modules of code in a structured program. Procedural (Structure) vs. OO programming require different approachesSimilarities: Both require a rudimentary understanding of programming concepts and basic control flow. Loops, conditional statements, and variables are concepts that are important whether you are using a procedural language or an object oriented language.

Differences: Typically object oriented is viewed as more difficult. This is because an entirely different problem solving approach must be taking. In addition, there are a variety of object-oriented-only concepts such as classes and inheritance. For simple programs, procedural is often preferred. The more complicated the project, the easier it is to leverage the strengths of object oriented design.

Other notes: Not all languages fall strictly into procedural or object oriented baskets. In actuality, it is more of a spectrum. Languages like Basic and C are pretty much entirely procedural. Languages like C++ and Pascal can be written in either procedural or object oriented styles. Languages like Java and Python adhere much more strictly to object oriented design (although some programmers argue these aren't TRUE object oriented languages).

Is java high performance?

The performance of any program depends to a great degree on the skill of the programmer.

What is MVC framework in java?

Framework is set of reusable software program that forms the basis for an application. Frameworks helps the programmers to build the application quickly. Earlier it was very hard to develop complex web applications. Now its very easy to develop such application using different kinds of frameworks such as Struts, Struts 2, Hibernate, JSF, Tapestry, JUnit, Log4j, Spring etc.

In Java technology there are so many frameworks that helps the programmers to build complex applications easily. You can choose these frameworks for building your applications.

What are the similarities betyween colonial management of the forest in bastar and in java?

A) i) In both cases, they started forest management.

ii) The British wanted timber from Bastar to build ships. Like the British, the Dutch wanted timber to build ships.

iii) From Bastar many communities were forced to leave their old regions and forest areas. In Java, also many villagers were forced to leave the fertile forests and move to the mountains and gave up practicing shifting agriculture.

iv) In some forests and areas of Java the people of several communities raised the banner of rebellion as the same was done by different people of Bastar in India, but colonial government in Java as well as Bastar were successful in crushing the rebellions.

Example of encapsulation and abstraction in an object oriented programming language?

Encapsulation example:

Ink is the important component in pen but it is hiding by some other material.

Abstraction example: ATM is a good example of abstraction, we doesn't know what are all the internal processes that are going when we access it..instead we know only the inquiries, deposit, withdrawl etc...

What are symbolic constants and how they are useful in developing programs?

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

Answer given By Sushil Mittal..........

Program to reverse a string in java?

package sara78;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.Scanner;

import java.lang.IndexOutOfBoundsException;

public class node extends RuntimeException{

private static String string;

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

InputStreamReader input = new InputStreamReader(System.in);

BufferedReader reader = new BufferedReader(input);

try {

string = reader.readLine();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

char[] c=string.toCharArray();

int k=c.length;

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

{

System.out.println(""+c[i]);

}

for(int i=k;i<=k;--i)

{

System.out.println(""+c[i]);

}

}

}

As well, you could do it with a different approach, same idea:

import java.util.*;

public class Example

{

public static void main(String[] args)

{

Scanner in = new Scanner(System.in);

System.out.println("Please enter a String to reverse:");

String toReverse = in.next();

String Reversed = "";

for (int i = toReverse.length()-1; i>=0; i--)

{

Reversed = Reversed + toReverse.charAt(i);

}

System.out.println(Reversed);

}

}

Explain why a class might provide a set method and a get method for an instance variable?

A class might provide a set method (setter) and a get method (getter) for an instance variable in order to encapsulate the internal implementation of the class, and to isolate that implementation from the public interface of the class.

Even if the setter and getter does no more than directly set and get the instance variable, the public interface should use that paradigm in order to allow for possible future alteration of the implementation, while minimizing the impact of doing so.

Proper OOD/P (Object Oriented Design/Programming) should always make the implementation be private, even for derived classes. This reduces error, and reduces "lazy" coding techniques.

Which data type can store any data?

There is no such data type.
However, when we use user-defined data types of our own type, then that type of data can be stored in a variable. So as a term, you may say that user-defined data type can store any data. As the data-type used in any variable will be depending upon us.

What is the difference between a characteristic property and non-characteristic property?

PHYSICAL (smell, color, texture, size, etc)--NON CHARACTERISTIC

GENERAL (general stuff about the substance all together)-CHARACTERISTIC

Characteristic properties help us identify pure substances or the group it belongs to. Non-characteristic properties cannot help us identify pure substances or the group it belongs to.

How do you use the pullout method correctly?

Guy withdraws nowhere near his orgasm and has urinated beforehand.Pre-ejaculation can come any time though and he will not feel it. It works as lubrication and it does contain sperm.

Why are attributes of a class usually hidden from other users?

This is called "encapsulation", and there are two main reasons. (1) To be able to change the internals of the class at any time, without breaking compatibility with programs that use the class. (2) To be able to do some processing on any data that goes in or out of the class. For example, when assigning a value to a field (attribute), it is possible to check whether the parameter is within the allowed range of values.

Why do you use interfaces in java?

An interface is used in java to outline specific behaviors of a group of classes, i.e. Comparable (able to be compared). These common behaviors translate into methods that are all public and unimplemented (since an interface lists what can be done not how). An interface is usually used when it doesn't make sense for something to be a class but it does have general behaviors that other classes should implement, i.e. there is not much sense to implement a Comparable class, since many different objects have vastly different ways to compare each other; thus, the behavior is outlined, and future classes can implement said behaviors (the methods).

What is the difference between C and java?

You're comparing apples and oranges. C is a procedural language. You can, using structures and functions to access those structures do everything you can in Java. In fact, if you look into GObject, the object oriented method of programming in GTK (the Linux toolkit) people do this all the time. In fact they have pretty much implemented C++ manually using a programming style and macros.

C++ and Java have a great deal more in common. From a language perspective, they are nearly identical. Java is arguably cleaner as it doesn't depend on forward declaration and therefore all functions are coded directly within the class definitions themselves. C++ is arguably more powerful as you have direct access to the hardware of the system and it's also possible to write code in such a way that it is guaranteed to be compiled an optimized in a specific manor.

For application development, Java is often faster (performance and in the time it takes to get the job done). For system level development, C++ is almost always a clear winner. I won't detail it as it's far beyond the scope of the question.

There are two key differences between Java and C++ to a programmer.

1) Java is a garbage collected language

This means you can allocate memory and just forget about it when you're done. Some people say this leads to ugly code and quite frankly, I agree. Bad programmers can be REALLY bad programmers in Java and get away with it. C++ a C++ program will tend to crash your machine if you write it badly. The selling point of garbage collection is performance. It allows the runtime system of the language to clean up when there's time to do it instead of having to clean up during time critical moments. In C++ this type of behavior has to be coded manually and requires a great deal of strategic planning to accomplish.

2) Java has a "good" defined set of standard class libraries.

C++ has libraries also, but only a small percentage of programmers use them because many of us (me included) consider them to be a plague on the language. They're VERY over-engineered and can be very hard to debug. Java's libraries are a lot cleaner even if they have serious inconsistencies (this may spur a political debate, but I offer my opinion and the arguments I've heard from others).

Neither language is particularly good. Neither runtime is particularly modern. There are newer technologies such as C#/.NET and others which have arguably learn from C++ and Java and built upon what was learned.

If you're learning to program, I recommend using C++ with Qt (from Nokia) as it gives you almost the best of both worlds. If you're using one and looking to switch to the other. It should be a smooth transition, the languages are basically the same.

If you're asking about internal data structure. The two languages aren't comparable as Java doesn't have a strict internal structure definition and therefore can't be compared.

P.S. - For a bonus, Java's best feature is relocatable memory. Because it forces you to never use memory locations directly (pointers), so the java virtual machine can relocate your memory in order to make room for larger allocations that otherwise wouldn't fit without paging or asking the OS for more RAM. This can make your applications more efficient as virtual memory paging is far more expensive than simply defragging the memory occasionally.

What are the different types of Operators available in java?

arithmatic operator +,-,*,/,%

assigment oprator ==

logical operator &,|,^,&&,,!

bitwise opertor &,|,^

left shift <<

right shift >>

left shift zero fill <<

assignment operator +=,-=,*=,/=

Why people generally use oracle as backend of java projects?

there are certain rules to make up a relational data base management system, oracle follows it and so its an rdbms

What a java program for arithmetic operations between two integers?

public static void main(String[] args) {

int a = 5;

int b = 10;

int c;

c = a + b; // addition

c = a - b; // subtraction

c = a * b; // multiplication

c = a / b; // division

}

How ploymorphism and inheritance is different from that in Java and c plus plus?

C++ allows multiple inheritance while Java does not. In my opinion, multiple inheritance is not useful because it can get very confusing very quick.

For polymorphism, C++ does early binding by default, while Java does late binding by default. Late binding is more useful than early binding.

Is it possible to use arrays when using the java programming language?

It is possible to use arrays when employing java programming language. There are many different series of programming choice that can be employed with various end results.

Why is it important to have a solid background in mathematics for programming languages?

You need to to know some basic math to live. right? Likewise you need to know some basic math to start computer programming....beginners start out by learning to do programs like solving a quadratic equation....if you are not thorough with algebra, u can't do it. The way you think is more important.....rather than being good in math, computer programmers are required to think the way math people think - vey very very logically.

Which type of inheritance does not support by java?

Desoola Anil Kumar, Java Faculty: There are 5 types of Inheritance. 1.Single inheritance, 2.Multiple inheritance, 3.Multilevel Inheritance, 4. Hirarichal inheritance and 5. Hybrid inheritance. Java supports multi level inheritance and hirarichal inheritance.

When do you say an exception is handled?

There is no catch block that names either the class of exception that has been thrown or a class of exception that is a parent class of the one that has been thrown, then the exception is considered to be unhandled, in such condition the execution leaves the method directly as if no try has been executed

C program to read a text and count occurrence of a particular word?

#include<stdio.h>

main()

{

int i,words,spaces;

char a[30];

printf("enter the string") ;

scanf("%s",a);

for(i=0;a[0]!="\0";i++)

{

if (a[i]=' ')

spaces++;

}

printf("the no. of spaces in the string is %d",spaces);

printf("the number of words in the string is %d",spaces+1);

}