Posts

What is Variable-Length Arguments in Java Language?

Variable-Length Arguments is Java Language J2SE 7 added new Feature that simplifies creation of methods that need to take a Variable number of arguments. This Feature is known as Varargs short for Variable-Length Arguments. In some situations require that variable number of arguments passed to method are not unique. ________________________________________________________ Example: A method for opening internet connection take this information: User name. Password Filename Protocol etc etc If some information is not supplied by supply defaults. ___________________________________________________________________ A variable-length arguments is specified by three term. For example: How vaTest()//(Method) is written using vararg. v is implicitly declare as array of int type. Inside vaTest() v is accessed by using normal array syntax. ___________________________________________________________________ Decl...

What is Nested and Inner Classes in Java Language?

                                 Nested and Inner Classes It is possible in Java language to define a one class within another class these classes are called as nested classes. Scope of Nested Classes: The Scope of all Nested class is bounded by the scope of its inserting  class. Example: If  B class is Define within class A then the class B is only Known to A and not outside of class A and the scope is in class only class A. Nested class has access all members including private members. But inserting class does not have access the nested class members. Type of Nested Classes: There are two types of Nested classes: Static Nested Class. Non-Static Nested Class. 1.Static Nested Class: Static Nested class is one in which static modifier applied. Member of inserting class must access by an object. Static Nested Class can't refer to members of its inserting ...

Access Control in Java

How a member can be accessed is determine by the access specifier that modifies its declaration. Java's Access Specifiers are public private protected default If no access specifies is used then by default the member of a class is public within its own package but cannot be accessed outside of its package. Some difference Between Access Control: 1.Public: The public Access specifies are  visible in full project or code. Declaration:                                public int a; 2. Private:                  The private Access specifies are  visible only in class you can not access these specifies outside the class or method if declare in method. Declaration:                             private int a; 3.Protected:     ...

this keyword in Java

   What problems to need this keyword in Java?                    It is illegal in Java Language to declare two variables with same name inside the same scopes. When the local variables and instance variables has same name then local variables hides the instance variables. Solution of problems: The this keyword lets us refer directly  to the object we can use it to resolve any name-space collisions that occurs between local and instance variables. In Java Language Java define the  this keyword. this keyword is used to resolve the name-space collisions. The this keyword is used to inside any method to refer to the any object. Sometimes a method need to refer to the object that invoked it.  this keyword is always a reference to the object on which the method was invoked     Use this keyword to resolve name-space collisions: Box(double width, double heigh...

Tool for Java Coding

Image
Short or Simple Overview of Java Tool NetBeans IDE 8.0.2: NetBeans IDE 8.0.2 look this this: Interface of NetBeans IDE 8.0.2 look this this:   You can create your Project select file in left corner and then select New Project or in short key  Press Ctrl+Shift+N your project is create. Now interface look like this select Java. When select Java click Next button. When you click Next button interface change and look like this now you can change your project name if u want otherwise project name is that which is in arrow box. Now then click Finish button your Project is created. Your Project First time always Look like this.   In Boxes these are all Comments you can remove from if u want and Now you can code and make your Project.

Constructor

 Constructor rules: Constructor has the same name as the class in which it locate. Constructors have no return type, not even void. This is because type of a class constructor is the class type itself . Here constructor of Student class. class Student{ string name; int age; //Here Default constructor or without parameter Student(){  name="abc"; age=20; } } When we don’t clearly define a constructor for a class, then Java creates a default constructor for the class. The default constructor automatically initializes all instance variables to zero. Once we define our own constructor, the default constructor is no longer used in class. Parameterized Constructor: class Student{ string name; int age; //Here constructor Student(string n,int a){  name=n; age=a; } }

Classes in Java

Class? Class is template or blueprint. The most important thing to understand about a class is that it  defines  a new data type. Variables defined within a class are called instance variables because each instance of the class contains its copy of these variables.   Class declaration Method : class ClassName { Instance Variables:   type instanceVariable1;   type instanceVariable2;   . . .   type instanceVariableN; Methods in Class:   type methodName1(parameterList){   //body of method and code   }   type methodName2(parameterList){   //body of method   }   . . .   type methodNameN(parameterList){   //body of method and code   } } Declare Object of class: Classname objectname = new classname(); For Example Student stud = new Student();