In Java what is the difference between heavyweight and lightweight components?
The basic difference between Swing and AWT is that Swing APIs are purely Java libraries i.e. they don't at all depend on the native libraries to draw graphical components. Because of this feature they provide a consistent look and feel on all platforms. AWT libraries require the support of native graphics libraries and some of their GUI components look different on different platforms. Moreover, Swing components are not inherently Thread safe, you explicitly have to write synchronized code to manipulate or redraw them whereas AWT components can be trusted in a multithreaded environment. AWT Components are called heavyweight components because of their dependency on native libraries. Swing components are called lightweight due to their independence of native libraries. Hence Swing operations are much faster because each and every operation is taken care by the Java runtime env and no delegation of events or commands to the native libraries is required.
What is method declaration in Java?
A method declaration is the heading of a method containing the name of the method, its parameters, and its access level. The method heading in Java is organized as such:
[access keywords] [return type] [method name] ( [parameters separated by commas] )
for instance:
public String toString(); is public (accessible by any class), returns a String, is called toString, and takes no parameters.
Other features could be added to the method declaration for a more specialized method such as static (method could be called without an object of that class), native (implemented using the native code, usually what C has already done, i.e. square root, power etc.).
Why should main be declared static and is declaring it public and void not sufficient?
The static modifier means that it does not have to be instantiated to use it. Before a program runs there are technically no objects created yet, so the main method, which is the entry point for the application must be labeled static to tell the JVM that the method can be used without having first to create an instance of that class. Otherwise, it is the "Which came first, the chicken or the egg?" phenomenon. Your main method should be declared as follows: public static void main (String[] args) { lots of your java code... } As we know, java is a pure OOP , that means everything should be in the class, main. Aso, because main is itself a function, static member functions should not refer to objects of that class. But we can access static functions through classname itself, as: class TestMain { public static void main(String args[]) { body; } } Now, cmd>javac TestMain.java cmd>java TestMain as we know the static member functions has to call through its class name. That's why the programme name must be same as the class name ,where we wrote the main function. Another important point is : static variables or member functions will load during class. That means before creating any instances(objects), the main function is the first runnable function of any program which we run manually, such as : cmd>java TestMain(run) if , any sharing information.
void main()
{char a[30] = "India";
//Let the string be stored in a[30];
char b[30]; //declaring another string
for(i=0;i<strlen(a);i++)
{b[strlen(a)-1 - i]=a[i];}
//Now reverse string is stored in b;
//to print it
cout<<b;
getch();
}
Why is Java not a pure OOP Language?
Java is a OOP language and it is not a pure Object Based Programming Language.
Many languages are Object Oriented. There are seven qualities to be satisfied for a programming language to be pure Object Oriented. They are:
Java is not because it supports Primitive datatype such as int, byte, long... etc, to be used, which are not objects.
Contrast with a pure OOP language like Smalltalk, where there are no primitive types, and boolean, int and methods are all objects.
When the constructor is called how many times will it be copied?
constructor is called every times when we create object of class using new keyword
and constructor can not be copied (vinayak shendre)
Which data structure is needed to convert infix notations to pre fix notations?
S: Stack
while(more tokens)
{
x<-next token;
if(x is an operand)
print x
else
{
while(precedence(x) <= precedence(top(s))
print(pop(s))
push(s,x)
}
}
while(!empty(s))
print(pop(s));
Written by: Fabianski Benjamin
Which is the best object oriented programming language for beginners?
I would go with Python.
Python is therefore an ideal backend language due to its simplicity and consistency, where the developers are able to write reliable systems with a vast set of libraries belonging to Machine Learning, Keras, TensorFlow and Scikit-learn
What are various loops available in java?
Java has three kinds of loops
1. For Loop
2. While Loop
3. Do - While Loop
Both For loop and While loop would iterate through a certain lines of code within the loop's limit as long as the loop condition is satisfied.
A do while loop would execute the loop once even before checking the condition. So in a do while loop, even if the loop condition is not satisfied the loop would execute once.
Example Declarations:
for(int i = 0; i < n; i++) {
.....
}
while (i < n) {
...
i++;
}
do {
...
i++;
} while (i < n) ;
How many arguments can be passed to an applet using PARAM tags Explain all the parameters?
two arguments can be passed to applet using param tags
NAMES and VALUES
<PARAM NAME ="name" VALUES = "values">
Parameters are passed to applets in NAME=VALUE pairs in <PARAM> tags between the opening and closing APPLET tags. Inside the applet, you read the values passed through the PARAM tags with the getParameter() method of the java.applet.Appletclass.
How do you use arraylist in java programming?
The java.util.ArrayList class is one of the most commonly used of all the classes in the Collections Framework. Some of the advantages ArrayList has over arrays are
• It can grow dynamically.
• It provides more powerful insertion and search mechanisms than arrays.
Let's take a look at using an ArrayList that contains Strings. A key design goal of the Collections Framework was to provide rich functionality at the level of the main interfaces: List, Set, and Map. In practice, you'll typically want to instantiate an ArrayList polymorphically like this:
List myFirstArrayList = new ArrayList();
As of Java 5 you'll want to say
List myFirstArrayList = new ArrayList();
This kind of declaration follows the object oriented programming principle of "coding to an interface", and it makes use of generics. We'll say lots more about generics in future, but for now just know that, as of Java 5, the syntax is the way that you declare a collection's type. (Prior to Java 5 there was no way to specify the type of a collection, and when we cover generics, we'll talk about the implications of mixing Java 5 (typed) and pre-Java 5 (untyped) collections.)
In many ways, ArrayList is similar to a String[] in that it declares a container that can hold only Strings, but it's more powerful than a String[]. Let's look at some of the capabilities that an ArrayList has
List test = new ArrayList();
String s = "hi";
test.add("string");
test.add(s);
test.add(s+s);
System.out.println(test.size());
System.out.println(test.contains(42));
System.out.println(test.contains("hihi"));
test.remove("hi");
System.out.println(test.size());
which produces
3
false
true
2
There's lots going on in this small program. Notice that when we declared the ArrayList we didn't give it a size. Then we were able to ask the ArrayList for its size, we were able to ask it whether it contained specific objects, we removed an object right out from the middle of it, and then we rechecked its size.
Does the class can extend the class and implement interface at a time?
Yes, classes can implement more than one interface.
To declare a class that implements an interface, you include an implements clause in the class declaration.
Your class can implement more than one interface, so the implements keyword is followed by a comma-separated list of the interfaces implemented by the class.
By convention, the implements clause follows the extends clause, if there is one.
How do you write a Program in java to check whether it is a smith number or not?
import java.io.*;
class MagicNumber
{
public int divide(int x)
{
int a,b=0;
for(int i=x;i>0;i/=10)
{
a=i%10;
b+=a;
}
return b;
}
protected static void main()throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the number: ");
int a =Integer.parseInt(in.readLine()),b=0,x=1;
MagicNumber l=new MagicNumber();
do
{
if(x==1)
{
b=l.divide(a); x++;
}
else
{
b=l.divide(b);
}
}while((b/10)>0);
if(b==1)
System.out.print("Magic Number!!!!!");
else
System.out.print("Not a Magic Number!!!!!");
}
}
What are front-end technologies?
At AchieversIT, we offer comprehensive insights into the dynamic realm of front-end technologies. Front-end technologies form the foundation of user interface (UI) development, enabling the creation of visually appealing and interactive web experiences. Here's how AchieversIT explains front-end technologies:
Front-End Technologies (Taught by AchieversIT):
Front-end technologies, also known as client-side technologies, are the tools and frameworks used to design and build the visual and interactive elements of websites. AchieversIT's front-end curriculum empowers you with the skills to bring web designs to life, making them engaging, responsive, and user-friendly.
HTML (Hypertext Markup Language):
AchieversIT introduces you to HTML, the core language used to structure the content of web pages. You learn to create headings, paragraphs, lists, links, and other structural elements that form the backbone of web documents.
CSS (Cascading Style Sheets):
In our front-end program, you delve into CSS, which is used to style and visually enhance web pages. AchieversIT guides you in applying colors, typography, layouts, and animations to create aesthetically pleasing and consistent designs.
JavaScript:
AchieversIT empowers you with JavaScript skills, enabling you to add interactivity and dynamic behavior to web pages. You learn to manipulate the DOM (Document Object Model), handle user input, and create interactive elements such as sliders, forms, and animations.
Responsive Design:
Our training covers responsive design techniques, ensuring your web creations look and function seamlessly across various devices and screen sizes. AchieversIT helps you master media queries and flexible layouts to deliver a consistent user experience.
CSS Preprocessors:
AchieversIT introduces you to CSS preprocessors like SASS or LESS, which enhance your CSS workflow by enabling variables, mixins, and other advanced features. These tools streamline styling and maintenance.
Front-End Frameworks:
Our curriculum explores popular front-end frameworks like Bootstrap, Foundation, or Materialize. These frameworks provide pre-designed components and responsive grids to accelerate your development process.
Version Control and Collaboration:
AchieversIT emphasizes version control systems like Git and platforms like GitHub, enabling you to collaborate effectively with other developers and manage codebase changes.
Browser Developer Tools:
You learn to leverage browser developer tools to inspect, debug, and optimize your front-end code, ensuring a smooth user experience.
Web Performance Optimization:
AchieversIT guides you in optimizing front-end performance, covering techniques like minification, compression, lazy loading, and caching to enhance website speed and loading times.
Cross-Browser Compatibility:
Our training equips you with strategies to ensure your web creations work consistently across different web browsers, providing a seamless experience for all users.
By enrolling in AchieversIT's front-end technologies program, you embark on a journey to master the art of creating captivating and user-centric web interfaces. Whether you aspire to specialize as a front-end developer or enhance your full-stack skills, AchieversIT empowers you with the knowledge and expertise needed to excel in the dynamic field of front-end technologies.
Example of overriding in java?
For example:
class Speak
{
void SayHello(){};
}
class Boy extends Speak
{
void SayHello(){System.out.println("I'm a boy");}
}
So overriding is usual to rewrite the motheds in subclasses .In subclsses ,you can override the methods acceded from his parent class.
Biggest of three numbers using ternary operator in java?
// largest = largest of a, b, c
public class largest
{
public static void main(String args[])
{
int a,b,c,largest;
a=0;
b=0;
c=0;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
c=Integer.parseInt(args[2]);
largest=a>b?(a>c?a:c):(b>c?b:c);
System.out.println("The largest no. of "+a+","+b+"and"+c+"is"+largest);
}
}
How can a stack determine if a string is a palindrome?
foreach char in string
push on to stack
create new string
foreach char in string
pop off and add to end of new string
if new string equals old string
palindrome
else not palindrome
//when you pop off the stack, the characters come off in reverse order, thus you have reversed the original string
In what order are the class constructors called when a derived class object is created?
We know that constructors are invoked at runtime when you say new on some class type as follows:
Lamborghini h = new Lamborghini();
But what really happens when you say new Lamborghini() ? (Assume Lamborghini extends Car and Car extends Object.)
1. Lamborghini constructor is invoked. Every constructor invokes the constructor of its superclass with an (implicit) call to super(),
2. Car constructor is invoked (Car is the superclass of Lamborghini).
3. Object constructor is invoked (Object is the ultimate superclass of all classes, so class Car extends Object even though you don't actually type "extends Object" into the Car class declaration. It's implicit.) At this point we're on the top of the hierarchy.
4. Object instance variables are given their explicit values. By explicit values, we mean values that are assigned at the time the variables are declared, like "int x = 27", where "27" is the explicit value (as opposed to the default value) of the instance variable.
5. Object constructor completes.
6. Car instance variables are given their explicit values (if any).
7. Car constructor completes.
8. Lamborghini instance variables are given their explicit values (if any).
9. Lamborghini constructor completes.
Derived data is data that is copied or enhanced from operational data sources into an informational database. This is in the information catalog center.
Different controls structures in java?
posted by
Suhit s Kalubarme
Software Developer
Solapur
9260069199
Controls are components that allow the user to interact with your application in various ways e.g. a commonly use the control is command button.
Various controls:
1. Label
2. Button
3. Check Box
4. Choice Box
5. TextArea
6. TextField
Is it possible to have more than one public class in the same file?
No. There can be multiple java classes in the same .java file, but the name of the file must match the name of the public class in the file.
Why you give the constructor name same as class name?
Constructor is just like method in class.it actually used for intialising members of class,
lets consider ex.
class construct
{
constrct(){}
}
in main() you hav to provide..
construct c1=new construct();
new construct() means calling the method of class,and which is used to initailise members of same class implicitly.
this it is necessary for constructor to have same name