What is java
What is java Java is a computer programming language. It enables programmers to write computer instructions using English based commands, instead of having to write in numeric codes. It’s known as a “high-level” language because it can be read and written easily by humans. Like English, Java has a set of rules that determine how the instructions are written. These rules are known as its syntax. Once a program has been written, the high-level instructions are translated into numeric codes that computers can understand and execute.
What is java Java is a computer programming language. It enables programmers to write computer instructions using English based commands, instead of having to write in numeric codes. It’s known as a “high-level” language because it can be read and written easily by humans. Like English, Java has a set of rules that determine how the instructions are written. These rules are known as its syntax. Once a program has been written, the high-level instructions are translated into numeric codes that computers can understand and execute.
In the Java programming language,
all source code is first written in plain text files ending with
the .java extension. Those source files are then compiled
into .class files by the javaccompiler. A .class file
does not contain code that is native to your processor; it instead
contains bytecodes — the machine language of the Java Virtual
Machine (Java VM). The javalauncher tool then runs your application
with an instance of the Java Virtual Machine.

Because the Java VM is available on
many different operating systems, the same .class files are capable
of running on Microsoft Windows, the Solaris™ Operating System (Solaris OS),
Linux, or Mac OS. Some virtual machines, such as the java SE HotSpot at a Glance perform
additional steps at runtime to give your application a performance boost. This
includes various tasks such as finding performance bottlenecks and recompiling
(to native code) frequently used sections of code
ArathmaticException
ReplyDeleteis it spring bean is thread safe or not
ReplyDeleteSpring Beans are not thread safe because. we can declere the beans in different scopes
Deletethats why spring beans are not thread safe
Example: suppose i have declare bean as singleton at that time only one object is created and i have declare bean asa prototype at that time for each and every request superate object is created thats why we can say Spring bean is not thread safe
How do you do sorting of user defined objects in Java?Give one example?
Deletepackage com.opps;
Deleteimport java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class UserDefinedObjectSorting {
public static void main(String[] args) {
List list = new ArrayList();
list.add(new Person("srinu",24));
list.add(new Person("rama",29));
list.add(new Person("krishna",30));
list.add(new Person("suresh",4));
list.add(new Person("hari",14));
for (Person person : list) {
System.out.println(person.getName()+ " "+ person.getAge());
}
Collections.sort(list,new PersonComparator());
System.out.println("After sorting");
for (Person person : list) {
System.out.println(person.getName()+ " "+ person.getAge());
}
}
}
================
package com.opps;
import java.util.Comparator;
public class Person {
private int age;
private String name;
Person (String name, int age){
setName(name);
setAge(age);
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
=================
package com.opps;
import java.util.Comparator;
public class PersonComparator implements Comparator {
@Override
public int compare(Person obj1, Person obj2) {
return obj1.getAge() - obj2.getAge();
}
}
If an Array contains duplicate values like 1 2 2 5 6 3 3 7 7.
ReplyDeleteHow can you remove that duplicates?
import java.util.*;
Deletepublic class RemoveDuplicates {
public static void main(String args[])
{
ArrayList arrayList=new ArrayList();
arrayList.add(1);
arrayList.add(2);
arrayList.add(2);
arrayList.add(6);
arrayList.add(3);
arrayList.add(3);
arrayList.add(7);
arrayList.add(7);
System.out.println(arrayList);
Set set=new HashSet(arrayList);
System.out.println(set);
}}
Basically ArrayList allows duplicate values but in collection we have Set interface it doesnot allow duplicate values
Deletein this case i have created ArrayList and i have added duplicate values to the arraylist and i created Set and i have passed ArrayList object through HashSet class
That means set elliminate duplicate values
finally we will get without duplicate values
OutPut:
DeleteBefore Deleting Duplicate Values
[1, 2, 2, 6, 3, 3, 7, 7]
After Deleting Duplicate Values
[1, 2, 3, 6, 7]
package com.opps;
ReplyDeletepublic class RemovingDuplicatesFromArray {
public static void main(String[] args)
{
int a[]={3,2,1,4,2,1};
System.out.print("Before Sorting:");
for (int i=0;ia[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
//After sorting
for(int i=0;i<a.length;i++)
{
System.out.print(a[i]+"\t");
}
System.out.print("\nAfter removing duplicates:");
int b=0;
a[b]=a[0];
for(int i=0;i<a.length;i++)
{
if (a[b]!=a[i])
{
b++;
a[b]=a[i];
}
}
for (int i=0;i<=b;i++ )
{
System.out.print(a[i]+"\t");
}
}
}
what is connection pool
ReplyDeleteThe connection pool within a JDBC data source contains a group of JDBC connections that applications reserve, use, and then return to the pool. The connection pool and the connections within it are created when the connection pool is registered, usually when starting up WebLogic Server or when deploying the data source to a new target.