Posts

Showing posts from January, 2018

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();

Type Casting or Conversion in Java

In Java language type casting or conversion means convert the value of  one data type into another compatible data type variable. In simple word type casting or type conversion means convert int data type value  into long data type. Two conditions for type casting and conversion: Both types are compatible e.g int into long. Destination type is larger then source type. All data types are not compatible and all types of conversions all not allowed automatic or implicitly . For example you can not convert double into byte data type.                               But...... It is still possible in java to convert incompatible data types by using cast ., cast perform explicit conversion between two incompatible data types.   Automatic type conversion: Convert automatically two types like this: byte a=1; byte b=12; int sum=a+b;   Incompatible Types conversion by Casting...

declare variable in java

Variables are basic unit of storage. All variables have scope the scope of variable is define its visibility.Variables are define by data types and  variable name. Declaring a Variable  : In java variable can be declared before its used. Example of  Declaring a Variable: if  Declare one Variable   syntax      int a; if   Declare more then one Variable then syntax is    int a,b,c,d;  Declare Variable with value  :       int a=12; if   Declare more then one Variable then syntax is     int a=12,b=13,c=14,d=15;

Data type's in java language

Java is strongly typed language. Primitive Data Types:    Java has eight primitive Data types but can be put in four groups.  Integer Floating-point Characters Boolean Integer: Java has four integer types  byte  short  int  long       All types are signed, positive and negative values. Name Width Range byte  8bits  128 to 127  short  16bits  –32,768 to 32,76   int  32bits  –2,147,483,648 to 2,147,483,647  l ong  64bits  –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 Floating-point: Java has  two floating-point types Double  float   Name  width   Approx. Range  float  32bits 1.4e–045 to 3.4e+038   double  64bits  4.9e–324 to 1.8e+308 ...

Control Statement's in Java

Control Statements means the control of program is change according to that condtions. Java supports following control statements these are: if statement:      syntax is                    if(condition)//code;                          else//code;   Nested ifs Statement:                syntax is                    if(condition){//code;                        if(condition)//code;                           if(condition)//code;                          else//code;}                         ...

Over View of Java

Java is object Oriented Programming Language (OOP) and OOP is at core of Java. Two Paradigms: All computer programs that consists of two elements Code Data These two Paradigms that describe how Program is created.  One is called Process-Oriented model. This technique describe as a program in steps. In this Technique can be thought of code acting on data. Problem with Process-Oriented Model: The main problem of this technique are: Code goes larger More Complexity The second is called Object Oriented Programming. In this Approach manage program data around its data and program can be describe as data controlling access to code. OOP principle: The three OOP principle are: Encapsulation. Inheritance. Polymorphism. These three Principle are work together. Simple Java Program /* this is simple Java Program*/ class Example{ // your program start with main() public static void main(string args[]){ System.out.println("This is Java."); ...

Java

Short History of Java: History of Java is very interesting to know. History of Java starts by Green Team. Java was developed by Green Team at  Sun Micro_system:   James Gosling  Mike Sheridan   Patrick Naughton Initiated   the project of Java language in 1991 and release in 1995.     First name of Java language is Green_Talk and extension was . gt. Second Name of Java Language is OAK . In 1995 the name of OAK is changed Java. What is Java? Java is concurrent, class based and  object oriented Programming Language. In Java Language we treat every problem with the help of Object. Java is Widely used programming Language. Why use Java? Java is run on different operating system.  Java has rich API. More powerful Development Tool. Great Collection of Libraries.  Types of Java : Java Applet. Applications. JAR File. Servlet. Swing Application. EJB. Features of Java:  Simpl...