Java Tutorial

by Dinesh Thakur Category: Data Type

In the Following example OddorEvenNumbers use mod operator to check if the number is even or odd. If the number divided by 2 and the reminder is 0 then number is even, otherwise the number is odd.

 
by Dinesh Thakur Category: Data Type

A variable is a place in memory where we can store a value. The Java programming language defines the following kinds of variables :

 
by Dinesh Thakur Category: Data Type

We know in Class data members and Members Functions are Instantiated, When Object of Class is Created New Memory is Allocated by Each Object .So for Avoiding this New Memory Each Time Creation, We Uses Static Data then data will be Common to all and the static data is used without creating an object of class Static data is used without creating an object Instead with name of class .

 
by Dinesh Thakur Category: Data Type

It is in two types. Those are,

 

1. Command line arguments

2. By using readLine() method

 
by Dinesh Thakur Category: Data Type

Operators work on the same data type. However, Java has wide variety of data types from which we can choose the suitable for a particular purpose. To perform the operation on variables from two different types of data we have to convert Both types to the same .



 
by Dinesh Thakur Category: Data Type

The scope of a variable specifies the region of the source program where that variable is known, accessible and can be used. In Java, the declared variable has a definite scope. When a variable is defined within a class, its scope determines whether it can be used only within the defined class or outside of the class also.

 
by Dinesh Thakur Category: Data Type

This Java Factorial Example shows how to finds factorial of a given number using Java. Entered number is checked first if its negative then an error message is printed.

 
by Dinesh Thakur Category: Data Type

The Exit statement allows you to exit prematurely from a block of statements in a control structure from a loop, or even from a procedure. Suppose you have a For…….Next loop that calculates the square root of negative numbers can't be calculated ( the Sqr() function generates a runtime error,)

 
by Dinesh Thakur Category: Data Type

In the Following example AreaofRectangleExample shows how to Calculate Area of Rectangle is length * width.

 
by Dinesh Thakur Category: Data Type

1. When the variable is declared outside the method, block, and constructor without using any modifier then it is treated as instance variable.
2. If the instance variable is not initialized then it takes the default value of the data type when the object is constructed.
3. Instance variable can use any access specifier.
4. It is accessed within the static method through the object of the class and within the non-static method and constructor directly without creating any object within the class, but outside the class non-static method and constructor invoke instance variable through objects.
5. Instance variable is also known as object level variable as for every instance the value of instance variable is newly initialized.



 
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content