Showing posts with label java. Show all posts
Showing posts with label java. Show all posts
Wednesday, May 17, 2017
OpenGL and Java
OpenGL and Java
While some programmers might still dont like this idea, developing a OpenGL-based 3D application using Java is possible. One option is to use the OpenGL implementation of Java3D, and the other is using an external library. JOGL (Java Binding for OpenGL) belongs to the latter category.
So, if you are a programmer who like to make a 3D application using OpenGL and also still want to take the advantage of Javas windowing system (AWT and Swing), JOGL is a great solution. JOGL allows access to most features available to C programming language programmers, obviously excluding GLUT. A quick example about how to work with JOGL could be found on wiki. For more detailed tutorial (my favourite) you can always visit NeHe. Though the sources related to the tutorial originally written in C++ but the Java version is also provided by other users.
Happy coding!
Available link for download
Sunday, March 12, 2017
Object in Java
Object in Java
In java we can define object as the instance of class. Object is used to instantiate all the non-static members. In java everything is based on Object, it means memory are allocating for the objects only. Everything we are dealing with is the help of object only , it may be calling method, accessing instance variable and many more.
Important point regarding Object in java
1> Object creation is with the use of new operator.
2> All the objects are created in the heap memory which is a part of main memory.
3> Whenever we are creating JVM will first call to default constructor if no constructor in defined in the class to initialize the instance variable.
4>We can define object for any class, it may be predefined class or use-defined class.
For ex-There is predefined classes available for every primitive data type in Object class so that we can use create object for primitive type as well called as wrapper class.
Syntax for defining Object :
< class_name > <reference_variable > = new < class_name >( [value] ) ;
for ex- Hello h = new Hello( ) ;
In the above syntax we can see that class_name is user defined class and with the new operator we had defined a constructor of the class where we can pass value as well but it is optional.
5> Reference value is always pointing to the object of the class with contain the reference value where the object is stored in the memory.
6> If not object is created then reference variable is containing NULL as the reference value indicating not pointing any object.
Let me make you more understood with the help of an example :
public class prog{
int x ; // instance variable
String name ; // instance variable
long ln ; // instance variable
float f ; // instance variable
void display(){ // Instance method
System.out.println("Display method");
}
public static void main(String sush[ ]) {
prog p = new prog( ); // Object created
p.display(); // Instance method called
}
}
Here variable " x ", " ln "," f " and " name " is instance variable and display ( ) is an instance method . It is only called with the help of object only.
Diagrammatic representation of Object

You all must be wondering that what happened to instance method ?
Instance method will be called by the object and get executed in the stack memory always. And it is only executed when we are calling method manually in our program with the help an object otherwise it wont execute self.
Note : If we are not using any new operator then it will remain as a reference value which store null, means not pointing any object.
Available link for download
Thursday, February 23, 2017
Operators in Java
Operators in Java
Basically we can treat operators in three category on the basis of operand used with the operators i.e
1> Unary Operator
2> Binary Operator
3> Ternary Operator
Unary Operator
It is the operator used with the single operand . As its name indicate " unary " that means " single ".
Some of the unary operators are increments ( ++ ) and decrements ( -- ) operators. We will study in details about these operators in their respective topic later in this tutorial.
We can also use " + " operator as unary operator which is in java formally called as " string concatenation operator ".
for ex-
int x = + 10 ; // Here x represents +ve 10 value but itself by default it is +ve.
byte b = +x ; // Invalid. Here it will give compilation error because we are storing int value " x " in byte type" b " so be careful by assigning any variable to
another variable.
another variable.
int x = -10 ; // valid statement represent -10.
byte b = -x; // invalid same reason as above.
int x = ++10 ; // Here ++ represents the increments operator .
int x = --10 ; // Here -- represents the decrements operator.
Binary Operator
It is the operator used with two operands and we all know that binary represent two. So we need to operate with this kind of operator.
For example we are using following operator as an binary operator.
String concatenation operator ( + ), Assignment Operator ( = ), Relational Operator ( Both equality and comparison operators ) , Logical operators , Bitwise operators and shift operators.
int x = 10 + 20 ; // Here" + " represents the use of Binary operator .
int x = 20 ; // Here " = " is an Assignment operator used left side as an variable and
right side is a value of it.
right side is a value of it.
if ( 10 < 20 ) // Here " < " is an Comparison operator , which returns true or false and it
must have value as an operand not variable as an operand .
must have value as an operand not variable as an operand .
if ( 10 >= 20 ) // Here " >= " is also an Comparison operator , which returns true or false
and it must have value as an operand not variable as an operand .
and it must have value as an operand not variable as an operand .
if ( 10 == 10) //Here " == " is also an Equality operator , which returns true or false and it
must have as an operand not variable as an operand .
must have as an operand not variable as an operand .
if ( 10 != 10) //Here " != " is also an Equality operator , which returns true or false and it
must have value as an operand not variable as an operand .
must have value as an operand not variable as an operand .
Ternary Operators
It a kind of operator which is used with three operands for example conditional operator is one of the ternary operator.
Syntax :-
<operand 1 > ? <operand 2 > : <operand 3 >
Here the condition is < operand 1 > must return boolean value i.e true or false .
If < operand 1> returns true then < operand 2> will be displayed as an output and if false then < operand 3> will be displayed as an output.
for ex-
int x = ( 20 > 10 ) ? 20 : 10 ; // here condition is true that means 20 is displayed as an output.
Available link for download
Subscribe to:
Posts (Atom)