Monday, December 17, 2012

Operation i+=j

Operation i +=j other than being shortcut of i= i+j
It is also i = (type of i) (i+j)

Saturday, October 20, 2012

Why do we have only public static final variables in interfaces?

Why do we have only public static final variables in interfaces?

Interfaces are protocol, templates. Classes implementing the interfaces, decide about the implementation
public: So that all the classes implementing the interface have access to everything inside class
static:So that the variables, methods inside interface belong to the interface
final:so that implementing classes don't modify the constants

Java passes all the values...as cally by value....not call by reference


Composition vs Inheritance in java


Sunday, October 14, 2012

Core Java Faq

1)  Difference between path and classPath in java 
2)  Dynamic Loading vs Static Class Loading in java 
3)  Overloading in java
4) Overriding in java
5) static variables in java
6) static methods in java
7) can static methods be overloaded
8) can static methods be overrided
9) can static methods be overloaded by non-static methods
10) can static methods be overrided by non-static methods
11)  static class

Saturday, October 13, 2012

Dynamic Loading vs Static Class Loading in java

Class in java can be loaded in two ways

Static means at compile time means using new operator.

Dynamic means using class.forname() a class is loaded dynamically during run time

so a decision to load a class dynamically at run time can be taken based on certain logic using property file etc.
getClass(); getName(); getDeclaredFields();
Instance can also be created using forName() method. It loads the class into the current class memory.  
it is similar like Reflection.

Difference between path and classPath in java

We always set a path and classpath while coding using java.

Path is for the OS to know where the java exe's are. by setting path you can execute java program from anywhere if not set then u need to go to bin directory of java and only then u can execute a java program.
Classpath is for the java program to know where the .class file are.

Classpath location points to where the .class file of your java programs are and /or the jar files (they contain the .class file used to code a specific functionality/usage)

Monday, July 30, 2012

public static void main (String[] args)

public : as it is accessible from anywhere for jvm
static: no need to create objects to call method.
void: no returning of value
main: syntax- main method - name to be followed
String[] args - syntax- to be followed

== vs equals in java

public class EqualsTest {
public static void main(String[] args) {

String s1 = "abc";

String s2 = s1;

String s5 = "abc";

String s3 = new String("abc");

String s4 = new String("abc");

System.out.println("== comparison : " + (s2 == s4));

System.out.println("== comparison : " + (s1 == s2));

System.out.println("Using equals method : " + s1.equals(s2));

System.out.println("== comparison : " + s3 == s5);

System.out.println("Using equals method : " + s3.equals(s4));

}

}
 
Output
 
== comparison : false


== comparison : true

Using equals method : true

false

Using equals method : true

Equals comapares the content, == compares the references(memory location), hence when new keyword is used to create string, == shows false.


Friday, March 9, 2012

Exception Rules in Java

It's just opposite in the case of constructors and methods. A overriding method cannot throw broader checked exceptions than the overridden method in the super class. But in case of constructors, subclass constructor can throw broader checked exception but not narrower checked exception of the super class constructor. This behavior is opposite as constructors are not overridden...

Thursday, March 8, 2012

How many ways we can create objects in Java

there are 4 ways
1) using new operator and default constructor
MyObject object = new MyObject();
2) using Class.forname
MyObject object = (MyObject) Class.forName(MyObject).newInstance();
3) using clone
MyObject object = anotherObject.clone();

4) using deserialization
ObjectInputStream inStream = new ObjectInputStream(anInputStream ); MyObject object = (MyObject) inStream.readObject();

Can we override a main method in Java

Yes, you can override a main method in Java
class Abc{
public static void main(String args[]){

System.out.println("Abc method ");
}
}
class Xyz extends Abc{
public static void main(String args[]){
System.out.println("Xyz method");
}

}
class Example{
public static void main(String args[]){
String S[]=new String[10] ;

Abc.main(S);
Xyz.main(S);
}
}

Language Basics

String default value is null and not "null"
Boolean default value is false
Float & double are same only float has a F literal in value.
Declaring int array

int myList [] = {4, 3, 7};
public abstract methods in interface
constants in interface

Wednesday, March 7, 2012

Final Variables and static

Final Variables need to be initialized when declared.

Class final variables can be initialized in static block.
Instance variables can be initialized in Constructor.

static final variables are constants.


Static methods can acess other static methods and static variables only.

Monday, February 27, 2012

Reflection in Java

Collection in Java

Collections in Java

Java OOPS Concept ....Encapsulation

Encapsulation to encapsulate or hide the data
for e.g Declare class variables as final; its data will be accessed by public methods.
by default default access modifier -->in packages
protected-->in package and subclasses
private-->in same class
public--->global

Java OOPS Concept .... Inheritance

Inheritance...inheriting from parent class.
Re usability....

Java OOPS Concept ....Abstraction

Abstraction means hiding the complexities.
Abstract class or interface...
We cannot instantiate this classes.
We need to extend them
We are only concerned about calling the methods for using the functionality.
for e.g stop and start method to stop and start a car...how is it implemented we are not bothered.
Its Closely associated with Encapsulation.

Assigning Child object to parent

We can assign Child object to Parent but not vice-a-versa
class Employee;
class Developer extends Employee
class Tester extends Employee
Employee e= new Employee();
Employee e = new Developer ();--->Developer is a employee
Developer d= new Employee();---->What if Employee is a tester

Java OOPS ...PolyMorphism

1)Static Polymorphism
Method overloading
methods overloaded in class with same name, but different datatype and no of argument
int test(int a, intb);
double test(double y);
2)Dynamic Polymorphism
Method overriding
Overriding the method of parent class.
class A{
int method (int x){}

}
class B extends A{
int method (int x){}
}
All the interfaces are example of method overriding


Monday, January 23, 2012

JBoss Admin Console Security

JBoss Admin Console Security
Follow the steps mentioned below to secure jboss admin console
1)\deploy\jmx-console.war\WEB-INF\jboss-web.xml java:/jaas/jmx-console
2)\deploy\jmx-console.war\WEB-INF\web.xml HtmlAdaptor An example security config that only allows users with the role JBossAdmin to access the HTML JMX console web application /* GET POST JBossAdmin
BASIC JBoss JMX Console
JBossAdmin
3)\conf\login-config props/jmx-console-users.properties props/jmx-console-roles.properties 4)conf\props\jmx-console-usersadmin=admin
5)conf\props\jmx-console-rolesadmin=JBossAdmin,HttpInvoker