Can we overload static methods in java

  • Yes. We can overload static methods in java.
  • Method overriding is not possible but method overloading is possible for static methods.
  • Before that lets see about method overloading in java.

Method overloading:

  •  Defining multiple methods with same name and with different arguments is known as method overloading.
  • Multiple methods with same name and different arguments so compile time itself we can tell which method is going to get executed based on method call.
  • Method overloading also known as compile time polymorphism. 

Static methods - method overloading 

  • Its always possibles static method overloading.
  • Defining multiple static methods with same name and different arguments will possible.
  • By this we can define multiple main methods in our class with different arguments but only default main method will be called by the JVM remaining methods we need to call explicitly.
  • Lets see an example java program which explains static method overloading.

  1. class StaticMethodOverloading{
  2.  
  3. public static void staticMethod(){
  4.  
  5. System.out.println("staticMethod(): Zero arguments");
  6.  
  7.  
  8. public static void staticMethod(int a){
  9.  
  10. System.out.println("staticMethod(int a): one argument");
  11.  
  12.  
  13. public static void staticMethod(String str, int x){
  14.  
  15. System.out.println("staticMethod(String str, int x): two arguments");
  16.  
  17. }
  18.  
  19. public static void main(String []args){
  20.   
  21.   StaticMethodOverloading.staticMethod();
  22.   StaticMethodOverloading.staticMethod(12);
  23.   StaticMethodOverloading.staticMethod("Static method overloading",10);
  24.  
  25. }
  26. }


 Output:

  1. staticMethod(): Zero arguments
  2. staticMethod(int a): one argument
  3. staticMethod(String str, int x): two arguments


Java Program to overload main method in java

  1. class mainMethodOverloading{
  2.  
  3. public static void main(boolean x){
  4.  
  5. System.out.println("main(boolean x) called ");
  6.  
  7.  
  8. public static void main(int x){
  9.  
  10. System.out.println("main(int x) called");
  11.  
  12.  
  13. public static void main(int a, int b){
  14.  
  15. System.out.println("main(int a, int b) called");
  16.  
  17. }
  18.  
  19. public static void main(String []args){
  20.    
  21.  
  22. System.out.println("main(String []args) called ");
  23.  
  24.   mainMethodOverloading.main(true);
  25.   mainMethodOverloading.main(10);
  26.  mainMethodOverloading.main(37,46);
  27.  
  28.  
  29. }
  30. }




 Output:

  1. main(String []args) called
  2. main(boolean x) called
  3. main(int x) called
  4. main(int a, int b) called

Can we override static methods in java

  • Exact answer is NO. We can not override static methods.
  • Before discussing this topic lets see what is static in java. 

Static methods in java:

  •  Static means class level if we declare any data or method as static then those data(variables) and methods belongs to that class at class level.
  • Static variables and static methods belongs to class level.
  • Static methods are not the part of objects state . Belongs to class
  • Without using object we can call these static methods.
 here the detailed explanation on static methods

Instance methods in java:


  • Instance methods will be called at run time.
  • Instance variables and instance methods are object level. variables values may change from one object to another where as static variable values are class level so if we access by using any object and changes that values will effect to all objects means its class level variable.
  •  Lets see about overriding in java.

Method overriding in java:


  •  Defining the super class method in sub class with same signature.
  • Even though in inheritance all properties of supers class can access in sub class we have an option of overriding super class methods in sub class known as method overriding.
  • So by this every-time sub-most object method will be called.

Instance methods - Method Overriding

  
  1. class SuperClassDemo{
  2.  
  3. public void instanceMethod(){
  4.  
  5. System.out.println("SuperClassDemo instanceMethodcalled");
  6.  
  7. }
  8.  
  9. }

  1. class SubClassDemo extends SuperClassDemo{
  2.  
  3. public void instanceMethod(){
  4.  
  5. System.out.println("SubClassDemo instanceMethod called");
  6.  
  7. }
  8. public static void main(String []args){
  9.   
  10.   SuperClassDemo superObj= new SuperClassDemo();
  11.   SuperClassDemo  superobj1= new  SubClassDem(); 
  12.   SubClassDemo subObj= new  SubClassDem(); 
  13.   // here no need to create object to call a static method please note that.

  14.   superObj.instanceMethod();
  15.   superObj1.instanceMethod();
  16.   subObj.instanceMethod();
  17.  
  18. }
  19. }

Output

  1. SuperClassDemo instanceMethodcalled
  2. SubClassDemo instanceMethodcalled
  3. SubClassDemo instanceMethodcalled

 Static methods - method overriding:

  • Lest an example program on static methods in method overriding concept and then discus about this clearly.
  1. class SuperClassDemo{
  2.  
  3. public static void staticMethod(){
  4.  
  5. System.out.println("SuperClassDemo staticMethod called");
  6.  
  7. }
  8.  
  9. }

  1. class SubClassDemo extends SuperClassDemo{
  2.  
  3. public static void staticMethod(){
  4.  
  5. System.out.println("SubClassDemo staticMethod called");
  6.  
  7. }
  8. public static void main(String []args){
  9.   
  10.   SuperClassDemo superObj= new SuperClassDemo();
  11.   SuperClassDemo  superobj1= new  SubClassDem(); 
  12.   SubClassDemo subObj= new  SubClassDem(); 
  13.   // here no need to create object to call a static method please note that.

  14.   superObj.staticMethod();
  15.   superObj1.staticMethod();
  16.   subObj.staticMethod();
  17.  
  18. }
  19. }



Output

  1. SuperClassDemo staticMethod called
  2. SuperClassDemo staticMethod called
  3. SubClassDemo staticMethod called

 Method Overriding - Method Hiding:

  • Method overriding : in method overriding we will define super class method in sub class with same signature and these methods will be called at run time based on the object.
  • Method Hiding: In method hiding even though super class methods are accesible in sub class they are not the part of sub class so the methods and these methods will be called based on the class.
  • In method Hiding if we define same static method in super class and sub class they are not same they are unique and distinct from the other.



Return type / return statement in java example

Return type in java: return statement in java

  • Basically return type is used in java methods.
  • Method signature includes this return type.
  • public int show(){ // }
  • we will use methods to do a particular task after completion of task if we want to return something to the calling place these return types will be used.
  • Based on the type of data to be returned will mention it as int , char , float double etc as return type in method signature and return statement should be the last statement of the method body.
  • In Java, the return statement is used to exit a method and return a value to the calling method. The value returned can be of any data type that is specified in the method's return type. 
  • For example, if a method has a return type of int, it can return an integer value. Here's an example of a simple method that uses the return statement to return an int value:


public int add(int a, int b) {
    int sum = a + b;
    return sum;
}

  • In this example, the add method takes two int parameters, a and b, and returns the sum of the two values. The method uses the return statement to return the value of the sum variable back to the calling method.
  • You can also use return statement without returning any value, in this case method should have void return type.


public void printHelloWorld() {
    System.out.println("Hello, World!");
    return;
}

  • In this case the method printHelloWorld doesn't return any value and the calling method doesn't need to assign the return to any variable, just invoking the method will do the job.
  • It is also worth noting that when a return statement is executed, it immediately exits the current method, regardless of where it is in the method's execution flow. So, any code after a return statement will not be executed.

Type of declaration of methods based on return type and arguments:

1.Method with out return type  and without arguments: return statement in java


  1. package com.instanceofjava;
  2. class sample{
  3.  
  4. public void add(){
  5.  
  6. int a=40;
  7. int b=50;
  8. int c=a+b;
  9. System.out.println(c);
  10.  
  11. }

  12. public static void main(String args[]) // ->method prototype.
  13.  
  14. sample obj= new sample();
  15. obj.add();
  16.  
  17.  
  18.  }
  19. }

2.Method with out return type and with arguments.

  1. package com.instanceofjava;
  2. class sample{
  3.  
  4. public void add(int a, int b){
  5.  
  6. int c=a+b;
  7. System.out.println(c);
  8.  
  9. }

  10. public static void main(String args[]) // ->method prototype.
  11.  
  12. sample obj= new sample();
  13. obj.add(13,24);
  14.  
  15.  
  16.  }
  17. }

3.Method with return type  and without arguments.


  1. package com.instanceofjava;
  2. class sample{
  3.  
  4. public int add(){
  5. int a=40;
  6. int b=50;
  7. int c=a+b;
  8. return c;
  9. }

  10. public static void main(String args[]) // ->method prototype.
  11.  
  12. sample obj= new sample();
  13. int x=obj.add(); 
  14. System.out.println(x);
  15.  
  16.  }
  17. }

4.Method with return type and with arguments.

 

  1. package com.instanceofjava;
  2. class sample{
  3.  
  4. public int add(int a, int b){
  5.  
  6. int c=a+b;
  7. return c;
  8. }

  9. public static void main(String args[]) // ->method prototype.
  10.  
  11. sample obj= new sample();
  12.  
  13. int x=obj.add(1,2);
  14. System.out.println(x);
  15.  
  16.  }
  17. }


If Else Statment in Java

If statement :
  • if statement in java is decision making statement in java.
  • if statement will have a condition and if that condition is true then the corresponding block will be executed.
  • if(condition){ //  }
If condition syntax:



  1. if(condition){
  2. //  statements
  3. }
 Sample program on if statement:


  1. package com.instanceofjava; 
  2. import java.lang.*; 
  3.  
  4. public class ifExample { 
  5.  
  6. public static void main(String[] args) {
  7.  
  8. if(true){
  9.  
  10.  System.out.println("if condition executed");
  11.  
  12. }
  13.  
  14. }

Output:
  1. if condition executed

Java program to compare two numbers in java


  1. package com.instanceofjava; 
  2. import java.lang.*; 
  3.  
  4. public class simpleIfExample { 
  5.   
  6. public static void main(String[] args) {
  7.  
  8.   int x= 37;
  9.   int y= 37;
  10.                
  11. if(x==y)
  12.     System.out.println(x+ " is equal to " + y);
  13. }
  14.  
  15. if(x>y){
  16.     System.out.println(x+ " is greater than " + y);
  17. }
  18.  
  19. if(x<y){
  20.     System.out.println(x+ " is less than " + y);
  21. }
  22. }

Output:
  1. 37 is equal to 37



 Else Statement:

  •  if(condition){ //} else { // }

Java program to compare two numbers in java using if else


  1. package com.instanceofjava; 
  2. import java.lang.*; 
  3.  
  4. public class ifElseExample { 
  5.   
  6. public static void main(String[] args) {
  7.  
  8.   int x= 37;
  9.   int y= 37;
  10.                
  11. if(x==y){
  12.     System.out.println(x+ " is equal to " + y);
  13. }else if(x>y){
  14.     System.out.println(x+ " is greater than " + y);
  15. }else{
  16.     System.out.println(x+ " is less than " + y);
  17. }
  18. }



Output:
  1. 37 is equal to 37


Java program to find leap year or not in java using if else


  1. package com.instanceofjava; 
  2. import java.lang.*; 
  3.  
  4. public class ifElseExample { 
  5.   
  6. public static void main(String[] args) {
  7.  
  8.     int year = 2015;                      
  9.   //if year is divisible by 4, it is a leap year

  10.  if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
  11.  System.out.println("Year " + year + " is a leap year");
  12.  else
  13.       System.out.println( year + " is not a leap year");
  14.   
  15.  
  16. }

Output:
  1. 2015 is not a leap year


Java program to find even or odd using if else statment


  1. package com.instanceofjava; 
  2. import java.lang.*; 
  3.  
  4. public class ifElseEvenOddExample { 
  5.  
  6. public static void main(String[] args) {
  7.   
  8. int a=10;
  9. if((a%2)==0){
  10.  
  11.  System.out.println(a+"is even number");
  12.  
  13. }else{ 

  14.     System.out.println(a+"is odd number");
  15.  
  16. }
  17.  
  18. }

Output:
  1. 10 is even number

Top 25 Java Basic Interview Questions for Freshers

Imp Note: Openings for 2016 and 2017 pass outs (MNC) in india. Send your profile to Instanceofjava@gmail.com subject should be: yourName_fresher_resume

1.What is the most Important feature of java?

  • Java is platform independent language.

2.What do you mean by Platform Independence?

  • Platform Independence  you can run and compile program in one platform and can execute in any other platform.



3.What is JVM(Java Virtual Machine)?
  • JVM is Java Virtual Machine which is a run time Environment for the compiled java class.

4.What is JIT Compiler?

  • Just-In-Time(JIT) compiler is  used to improve the performance. JIT compiles parts of the byte code that have similar functionality at the same time,

5.Are JVM's Platform Independent?

  •  JVM'S are not platform Independent. JVM'S are platform Specific.

6.What if main method declare as private?

  • No,It will compile fine but in run time it will error like main method should be in public.cannot find main method.

7.What is platform?

  • A platform is basically the hardware or software environment in which a program runs.
  • There are two types of platforms software and hardware.
  • Java provides software-based platform.

8.What all memory areas are allocated by JVM?

  • Heap, Stack, Program Counter Register and Native Method Stack

9.What is the base class of all classes?

  • java.lang.Object

10.What is javac ?

  • It produces the java byte code from *.java file.
  • It is the intermediate representation of your source code that contains instructions.

11.Can we mark constructors final?

  • No, Constructor cannot be declared final.

12.What are two different ways to call garbage collector?

  • System.gc() OR Runtime.getRuntime().gc().

13.Can we override a static method?

  • No, we cannot override a static method. Static means class level.

14.Use of finalize() method in java?

  •  finalize() method is used to free the allocated resource.

15.Is it possible to overload main() method of a class?

  • Yes, we can overload main() method as well. 
  • But every time public static main(String[] args) will be called automatically by JVM.
  • Other methods need to call explicitly.

16. Does Java support operator overloading?

  • Operator overloading is not supported in Java.

17.Can I declare a data type inside loop in java?

  • Any Data type declaration should not be inside the loop. Its possible but not recommended.


18.List two java ID Es?

  • 1.Eclipse, 2.Net beans and 3.IntelliJ

19.Can we inherit the constructors?

  • No, we cannot inherit constructors. 
  • We can call super class constructors from subclass constructor by using super() call.

20.Can this keyword be assigned null value?
  • No, this keyword cannot have null values assigned to it.
21.Basic java interview programs for freshers 
22.Java Quiz for freshers

23. Top 25 java interview Questions for freshers  

24.Top 15 oops concepts interview questions and answers

25. Top 40 Java interview Programs asked in interview for freshers

You Might Like:



Java programming interview questions
  1. Print prime numbers? 
  2. What happens if we place return statement in try catch blocks 
  3. Write a java program to convert binary to decimal 
  4. Java Program to convert Decimal to Binary
  5. Java program to restrict a class from creating not more than three objects
  6. Java basic interview programs on this keyword 
  7. Interfaces allows constructors? 
  8. Can we create static constructor in java 
  9. simple java interview questions on Super keyword
  10. Java interview questions on final keyword
  11. Can we create private constructor in java
  12. Java Program Find Second highest number in an integer array 
  13. Java interview programming questions on interfaces 
  14. Top 15 abstract class interview questions  
  15. Java interview Questions on main() method  
  16. Top 20 collection framework interview Questions
  17. Java Interview Program to find smallest and second smallest number in an array 
  18. Java Coding Interview programming Questions : Java Test on HashMap  
  19. Explain java data types with example programs 
  20. Constructor chaining in java with example programs 
  21. Swap two numbers without using third variable in java 
  22. Find sum of digits in java 
  23. How to create immutable class in java 
  24. AtomicInteger in java 
  25. Check Even or Odd without using modulus and division  
  26. String Reverse Without using String API 
  27. Find Biggest substring in between specified character
  28. Check string is palindrome or not?
  29. Reverse a number in java?
  30. Fibonacci series with Recursive?
  31. Fibonacci series without using Recursive?
  32. Sort the String using string API?
  33. Sort the String without using String API?
  34. what is the difference between method overloading and method overriding?
  35. How to find largest element in an array with index and value ?
  36. Sort integer array using bubble sort in java?
  37. Object Cloning in java example?
  38. Method Overriding in java?
  39. Program for create Singleton class?
  40. Print numbers in pyramid shape?
  41. Check armstrong number or not?
  42. Producer Consumer Problem?
  43. Remove duplicate elements from an array
  44. Convert Byte Array to String
  45. Print 1 to 10 without using loops
  46. Add 2 Matrices
  47. Multiply 2 Matrices
  48. How to Add elements to hash map and Display
  49. Sort ArrayList in descending order
  50. Sort Object Using Comparator
  51. Count Number of Occurrences of character in a String
  52. Can we Overload static methods in java
  53. Can we Override static methods in java 
  54. Can we call super class static methods from sub class 
  55. Explain return type in java 
  56. Can we call Sub class methods using super class object? 
  57. Can we Override private methods ? 
  58. Basic Programming Questions to Practice : Test your Skill
  59. Java programming interview questions on collections

Long Wrapper Class

Long Wrapper Class:

  • Long Class is presented in java.lang package.
  • java.lang.Long class is used to represent primitive Long Value to Long object.

Long Class :

Float Class Definition

  1. public final class Long
  2. extends Number 
  3. implements Comparable<Long>



Constructors:

1.Long(long value):
  • The Constructor Long(long value) represents the specified long argument.

2.Long(String s):
  • The Constructor Long (String s) represents the long value indicated by the String parameter.

Methods:

1.public static int bitCount(long i); Program:

  1. package com.instanceofjava; 
  2. import java.lang.*; 
  3.  
  4. public class LongExample { 
  5.  
  6. public static void main(String[] args) {
  7.  
  8.   long l = 4561; 

  9.  System.out.println("Number = " + l);
  10.  System.out.println("Binary = " + Long.toBinaryString(l));
  11.  System.out.println("Number of one bits = " + Long.bitCount(l));
  12.  
  13. }
  14. }

Output:
  1. Number = 4561 
  2. Binary = 1000111010001 
  3. Number of one bits = 6

2.public byte byteValue():

This method returns value of long as byte.

Program:

 

  1. package com.instanceofjava;
  2.  import java.lang.*;

  3. public class LongExample {

  4. public static void main(String[] args) {

  5.  Long obj = new Long(30);

  6.  byte b = obj.byteValue();
  7.  System.out.println("Value of b = " + b);
  8.  
  9.  }
  10. }


Output:
  1. Value of b = 30

3.public int compareTo(Long anotherLong):

Program:

  1. package com.instanceofjava;
  2. import java.lang.*;

  3. public class LongExample {

  4. public static void main(String[] args) {
  5.  
  6.    Long a = new Long(63255);
  7.   Long b = new Long(71678);
  8.  
  9.    int result=  a.compareTo(b);
  10.    ifresult> 0) {
  11.    System.out.println("a is greater than b");
  12.    }
  13.    else ifresult< 0) {
  14.    System.out.println("a is less than b");
  15.    }
  16.    else {
  17.    System.out.println("a is equal to b");
  18.    }
  19.  
  20.    }
  21. }




Output:
  1. a is less than b

4.public static Long decode(String nm) throws NumberFormatException:

Program:


  1. package com.instanceofjava;
  2. import java.lang.*;

  3. public class LongExample{

  4.  public static void main(String[] args) {

  5.    Long l = new Long(10);
  6.    String str = "57820";
  7.    System.out.println("Number = " + l.decode(str));
  8.  
  9.   }
  10. }

Output:
  1. 57820




Float Wrapper Class

  • Float class is presented in java.lang package
  • java.lang.Float class is used to represent primitive float value to Float object.

Float Class Definition

  1. public final class Float
  2. extends Number
  3. implements Comparable<Float>

Float Class Constructors

1.public Float(double value)


  1. package com.instanceofjavatutorial;
  2.  
  3. public class FloatDemo {
  4.  
  5. public static void main(String[] args) {
  6.  

  7.  Float f = new Float(22.56d);
  8.   System.out.println(f);
  9.  
  10.  
  11. }
  12. }

Output:
  1. 22.56


2.public Float(float value)


  1. package com.instanceofjavatutorial;
  2.  
  3. public class FloatDemo {
  4.  
  5. public static void main(String[] args) {
  6.  

  7.  Float f = new Float(22.56f);
  8.   System.out.println(f);
  9.  
  10.  
  11. }
  12. }

Output:
  1. 22.56


3.public Float(String s) throws NumberFormatException


  1. package com.instanceofjavatutorial;
  2.  
  3. public class FloatDemo {
  4.  
  5. public static void main(String[] args) {
  6.  

  7.  Float f = new Float("22.56f");
  8.   System.out.println(f);
  9.  
  10.  
  11. }
  12. }

Output:
  1. 22.56

Float Class Methods:

1.public static Float valueOf(String s) throws NumberFormatException 

  • This method used to convert string value to float value. If the string contains non parsable value then it throws NumberFormatException 

  1. package com.instanceofjavatutorial;
  2.  
  3. public class FloatValueOfDemo {
  4.  
  5. public static void main(String[] args) {
  6.  
  7.  String str="56.32";

  8.  Float f = Float.valueOf(str);
  9.   System.out.println(f);
  10.  
  11.  
  12. }
  13. }

Output:
  1. 56.32

2.public String toString()
  • This method returns String value from Float Object.

  1. package com.instanceofjavatutorial;
  2.  
  3. public class FloatValueOfDemo {
  4.  
  5. public static void main(String[] args) {
  6.   
  7.  Float f = new Float("12.3")
  8.  String str=f.toString();

  9.   System.out.println(str);
  10.  
  11.  
  12. }
  13. }



Output:
  1. 12.3

3.public static float parseFloat(String s) throws NumberFormatException

  • This method returns float value from string object. If string doesnt contains parsable float value then throws NumberFormatException 

  1. package com.instanceofjavatutorial;
  2.  
  3. public class FloatDemo {
  4.  
  5. public static void main(String[] args) {
  6.  
  7.  String str="20";

  8.  Float f = Float.parseFloat(str);
  9.   System.out.println(f);
  10.  
  11.  
  12. }
  13. }

Output:
  1. 20.0



Character Class

  • Character class is presented in java.lang package
  • java.lang.Character class is used to represent primitive character value to character object.

Character Class Definition:

  1. public final class Character
  2.  extends Object 
  3. implements Serializable, Comparable<Character>

Character Class Constructors:

1. public Character(char value)
  • Character class having only one constructor which accepts char primitive value.

Java Program to convert char primitive value to Character Object.

  1. package com.instanceofjavatutorial;
  2.  
  3. public class CharacterDemo {
  4.  
  5. public static void main(String[] args) {
  6.  

  7.  Character ch = new Character ('a');
  8.   System.out.println(ch);
  9.  
  10.  
  11. }
  12. }

Output:
  1. a

 Character Class Methods:

1.public char charValue()

  • This method returns the primitive char value from the Character object.

Java code to get char primitive value from Character Object.

  1. package com.instanceofjavatutorial;
  2.  
  3. public class CharacterCharValueDemo {
  4.  
  5. public static void main(String[] args) {
  6.  

  7.  Character ch = new Character ('a');
  8.   char c=ch.charValue();

  9.  System.out.println(c);
  10.  
  11. }
  12. }

Output:
  1. a

2.public static String toString(char c) :

  • toString(char c) method present in Character class accepts "char" primitive values and returns String objects representing that character.
Java code to convert char primitive value to String object

  1. package com.instanceofjavatutorial;
  2.  
  3. public class CharactertoStringDemo {
  4.  
  5. public static void main(String[] args) {

  6.   char ch ='I';
  7.  
  8.   String str="";
  9.  
  10.   str=Character.toString(ch);
  11.  
  12.   System.out.println(str);
  13. }
  14. }

Output:
  1. I

3.public static Character valueOf(char c)

  • valueOf(char c)  is static method present in Character class used to convert char value to Chraracter object.
  • It accepts char primitive value and returns Character object

Java code to convert char primitive value to String object

  1. package com.instanceofjavatutorial;
  2.  
  3. public class CharactervalueOfDemo {
  4.  
  5. public static void main(String[] args) {

  6.   char ch ='S';
  7.  
  8.   Character chobj='';
  9.  
  10.   chobj=Character.valueOf(ch);
  11.  
  12.   System.out.println(chobj);
  13. }
  14. }

Output:
  1. S
4.public static char toUpperCase(char ch)

  • toUpperCase(char ch) static method present in Character class used to convert a character to uppercase.
  • It accepts a character and returns same character in uppercase.


Java code to convert char primitive value to uppercase

  1. package com.instanceofjavatutorial;
  2.  
  3. public class CharacteruppercaseDemo {
  4.  
  5. public static void main(String[] args) {

  6.   char ch ='a';
  7.  
  8.   char c=Character.valueOf(ch);
  9.  
  10.   System.out.println(c);
  11. }
  12. }



Output:
  1. A

5.public static char toLowerCase(char ch) 

  •  toLowerCase(char ch) static method present in Character class used to convert a character to lowercase.
  • It accepts a character and returns same character in lowercase.


Java code to convert char primitive value to lowercase

  1. package com.instanceofjavatutorial;
  2.  
  3. public class CharacterlowercaseDemo {
  4.  
  5. public static void main(String[] args) {

  6.   char ch ='L';
  7.  
  8.   char c=Character.valueOf(ch);
  9.  
  10.   System.out.println(c);
  11. }
  12. }

Output:
  1. l



Integer Wrapper class

  • Integer  class is present in java.lang package.
  • java.lang.Integer  is used to represent integer primitive value in form of object.

Class Definition

  1. public final class Integer
  2. extends Number 
  3. implements Comparable<Integer>

Integer Class Constructors

1.public Integer(int value):
  • It takes int primitive value as an argument.
Java code to convert int primitive to Integer object


  1. package com.instanceofjavatutorial;
  2.  
  3. public class IntegerDemo {
  4.  
  5. public static void main(String[] args) {
  6.  


  7.  Integer obj=new Integer (37);
  8.  
  9.  System.out.println(obj);
  10.  
  11.  
  12. }
  13. }

Output:
  1. 37

2.public Integer(String s)  throws NumberFormatException:

  • It takes String value as an argument. 

Java code to convert String to Integer object


  1. package com.instanceofjavatutorial;
  2.  
  3. public class IntegerDemo {
  4.  
  5. public static void main(String[] args) {
  6.  


  7.  Integer obj=new Integer ("123");
  8.  
  9.  System.out.println(obj);
  10.  
  11.  
  12. }
  13. }

Output:
  1. 123

Integer Class Methods:

3.public static int parseInt(String s) throws NumberFormatException :
  • This method takes String as an argument and converts to the int value
  • Static method present in Integer Class used to parse the string to the corresponding int value.in
  • We can use this method by class name Integer.parseInt("number").
  • If the String contains non numeric value then this method throws NumberFormatException 

 Java Program to parse a string or convert String to Integer value

  1. package com.instanceofjavatutorial;
  2.  
  3. public class IntegerParseIntDemo {
  4.  
  5. public static void main(String[] args) {
  6.  

  7.  int x= Integer.parseInt("34");
  8.   System.out.println(x);
  9.  
  10.  int y=  Integer.parseInt("56");
  11.    System.out.println(y);
  12.  
  13.  int z=  Integer.parseInt("98");
  14.  System.out.println(z);
  15.  
  16. }
  17. }

Output:
  1. 34
  2. 56
  3. 98
4.public int intValue()

  • This method returns the int value from the Integer Object.
  • obj.intValue()- returns a int value of Object obj.



Java Program to get int value from a Integer Object.

  1. package com.instanceofjavatutorial;
  2.  
  3. public class IntegerIntValueDemo {
  4.  
  5. public static void main(String[] args) {
  6.  

  7.  Integer obj= new Integer(25);

  8.  
  9.  int y= obj.intValue();
  10.  
  11.  System.out.println(y);
  12.  
  13. }
  14. }

Output:
  1. 25

3.public int compareTo(Integer anotherInteger) 

  •  This method is used to compare two Integer Objects and returns int value
  •  0- Integer is equal to the argument Integer
  • < 0 if this Integer is numerically less than the argument Integer
  • > 0 if this Integer is numerically greater than the argument

Java Program to compare two Integer Objects.

  1. package com.instanceofjavatutorial;
  2.  
  3. public class IntegercompareToDemo {
  4.  
  5. public static void main(String[] args) {
  6.  

  7.    Integer obj1 = new Integer("34");
  8.    Integer obj2 = new Integer("08");
  9.  
  10.   int val =  obj1.compareTo(obj2);
  11.  
  12.    if(val > 0) {
  13.  
  14.    System.out.println("obj1 is greater than obj2");
  15.  
  16.    }
  17.    else if(val < 0) {
  18.  
  19.    System.out.println("obj1 is less than obj2");
  20.  
  21.    }
  22.    else {
  23.  
  24.    System.out.println("obj1 is equal to obj2");
  25.  
  26.    }
  27. }
  28. }

Output:
  1. obj1 is greater than obj2


4.public float floatValue()

  • This method used to convert integer value to float value.

Java Program to convert Integer to float

  1. package com.instanceofjavatutorial;
  2.  
  3. public class IntegerfloatValueDemo {
  4.  
  5. public static void main(String[] args) {
  6.  

  7.    Integer obj1 = new Integer("34");
  8.    Integer obj2 = new Integer("23");
  9.    
  10.     float f 1= obj1.floatValue();
  11.     float f 2= obj2.floatValue();
  12.  
  13.    System.out.println(f1);
  14.    System.out.println(f2); 

  15. }
  16. }

Output:
  1. 34.0
  2. 23.0

5.public String toString()

  • This method used to convert Integer to string object.

Java Program to convert Integer to String Object.

  1. package com.instanceofjavatutorial;
  2.  
  3. public class IntegerfloatValueDemo {
  4.  
  5. public static void main(String[] args) {
  6.  

  7.    Integer obj1 = new Integer("12");
  8.    Integer obj2 = new Integer("34");
  9.    
  10.     String  str1= obj1.toString();
  11.     String  f 2= obj2.toString();
  12.  
  13.    System.out.println(str1);
  14.    System.out.println(str2); 

  15. }
  16. }

Output:
  1. 12
  2. 34

Byte Wrapper Class

Byte Wrapper class Programs:


  • The java.lang.Byte class is used represent byte primitive value in form of Byte Object

  1. public final class Byte
  2. extends Number implements Comparable<Byte>

Byte Class Constructors:


1.Byte(byte value)
2.Byte(String s)

Byte Class Methods:

  • public byte byteValue() returns the value of this Byte as a byte.

Program:

  1. package com.instanceofjavatutorial;

  2. import java.lang.*; 

  3. public class ByteClass {

  4. public static void main(String[] args) {

  5.       Byte a;
  6.       a = new Byte("100");

  7.       byte t;
  8.       t = a.byteValue();

  9.       String s= "byte value of Byte object " + a + " is " + t;

  10.       System.out.println( s);

  11.    }
  12. }


Output:
  1. byte value of Byte object 100 is 100












Oracle and the Community Celebrate 20 Years of Java

Java 20 years


Oracle and the Community Celebrate 20 Years of Java 
  • Look Ahead to How Java Will Continue to Transform the Way We Work and Live Oracle, users and the development community worldwide are celebrating 20 years of Java this year. Today, Java serves as the critical backbone of software that touches both our work and personal lives. From innovations in enterprise big data, cloud, social, mobile and the Internet of Things, to connected cars, smartphones and video games, Java continues to help developers push the boundaries in technology innovation.

java 20 years



Evolution of the World’s #1 Programming Language
 
  • Introduced in 1995, Java is the programming language of choice for 9 million developers and today powers 7 billion devices. Improving road and air safety, collecting information from the world’s oceans for science applications, increasing grain crop quality and quantifying to help feed the hungry, simulating the human brain and musculoskeletal system, and gaming are some of the intriguing projects worldwide that use the Java technology. 
  • Enterprise developers can choose from an ecosystem of 30 Java EE 6 and Java EE 7 compatible implementations from 12 vendors. Additionally, more than 125 million Java-based media devices have been deployed and over 10 billion Java Cards have been shipped since Java’s introduction.
  • Under the stewardship of Oracle, two major platform releases including Java 7 and Java 8 have been delivered, with Java 9 slated for 2016. The Java Community Process (JCP) is more open and transparent than ever before, and serves as an integral element of community participation in the ongoing evolution of the technology. The OpenJDK Community, the place to collaborate on an open-source implementation of the Java Platform, Standard Edition, is continuously attracting new contributors to its already broad base of participation.
  • In March 2014, Oracle announced availability of Java SE 8 after receiving final approval in the Java Community process. This release, which included the largest upgrade to the Java programming model since the platform was introduced in 1995, was developed collaboratively in the OpenJDK Community. Soon after, in April 2014, the Java Platform, Micro Edition 8 (Java ME 8) and the related releases of Oracle's Java Embedded products were also made available after final approval in the Java Community Process.  With a consistent Java 8 platform across embedded devices, desktops, data centers and the cloud, customers can deploy applications faster; process and analyze in-flight data; and act on events as quickly as they occur.


java on cloud IOT

Ushering in the Next Era of Java 
  • Oracle and the Java community are now focused on delivering new innovations in Java 9. The key planned feature of this release is Project Jigsaw, which aims to modularize the platform in order to make it scalable to a wider range of devices, make it easier for developers to construct and maintain libraries and large applications, and improve security, maintainability, and performance. Other features slated for Java 9 include the Java Shell, an interactive tool for evaluating snippets of Java code; a new HTTP client API to support HTTP/2 and Web Sockets; a port to the ARM AArch64 architecture on Linux; and a variety of updates to existing APIs along with some significant performance improvements.
  • Visit the Duke’s Choice Award winners to see the remarkable work being done today by the Java community. 

“Java has grown and evolved to become one of the most important and dependable technologies in our industry today. Those who have chosen Java have been rewarded many times over with increases in performance, scalability, reliability, compatibility, and functionality.The Java ecosystem offers outstanding libraries, frameworks, and resources to help programmers from novice to expert alike.  The development of Java itself occurs in the transparent OpenJDK community.  With the considerable investment from Oracle and others in the community, we look forward to the next 20 years of Java’s evolution and growth.”

- Georges Saab, vice president of development, Java Platform Group, Oracle


 "IBM is celebrating Java's 20th anniversary as one of the most important industry led programming platforms spanning mobile, client and enterprise software platforms. IBM began its commitment to Java at its inception over two decades ago, and has seen the Java ecosystem and developer community bring unsurpassed value to the investments our clients have made in their Java based solutions. IBM looks forward to the next 20 years of growth and innovation in the Java ecosystem including Mobile, Cloud, Analytics and Internet of Things."  


-Harish Grama, vice president, Middleware Products, IBM Systems


“Programming languages don’t always live a long life, and those that do, don’t always enjoy a healthy one. But Java has stood the test of time and the test of the vast range of applications using it, from large enterprise systems to small device games.”

- Al Hilwa, IDC program director for Application Development Research





For Every 2 years Release will be there for java Under Oracle

  • The next version of java is Java 9 is going to be released on 2016 itself.  This shows how the team is working to ensure that there is everything for us to develop. 
  • Oracle and the java community now focusing on key project of Java 9 Project Jigsaw which helps us to build and maintain libraries and large applications and improves security maintainability and performance.

Get the education you need at better price

  • Oracle Training and Certification is offering 20 percent discount on all Java certification exams. The offer available globally is now open and expires on December 31, 2015.  at the time of registration you need to provide promotional code  as Java20
  • Clicke here for more details

Bloggers Meet At Oracle Hyderabad:

  • Today we attended an event organized by oracle on the occasion of "20 years of java".
  • One week back we got a message on instanceofjava Facebook page from oracle person 
    Gopal Kommuri saying that "I am writing on behalf of Oracle and trying to reach out to you to discuss about a bloggers meet we are planning to do in the next week".
  • I was surprised  because we www.instanceofjava.com are so young compared to others  but we are doing good on java and helping people like you and growing fast.
  • Anyway we are happy and said for sure will be attending the event.
  • Today june 13th 2015 morning 11 o clock we reached oracle office expecting that it was a big corporate event with lot of people.
  • Got a warm welcome from  Anita George and we entered into the meeting hall.
  • There are few Bloggers and higher officials.
  • Ms. Vandana Shenoy, Directory Corporate Communications, Oracle gave a warm welcome speech and introduced the presenters.
  • Sanket Atal, Group Vice President, India R&D, Oracle and he gave presentation titled “Java – 20 years of Innovation”. It was a very nice speech starting from how Java was created to the present day and how the future is promising for that how the oracle is doing things better to keep java alive.
  • Prior to Oracle Sanket held senior positions at MakeMy Trip and CA Technologies as CTO & Head of  Technology Center. He earlier worked with oracle in 1997 for over 13 years . He was the founding member of the team that setup the R&D centre for Oracle in the City of Portland Oregon , US.



                    • Inspiring and encouraging speech by Harshad Oak Founder , IndicThreads&Rightrix Solution , First Java Champion in India , Oracle ACE Director.
                    • Harshad has written many books on java including Oracle Jdeveloper 1og, Empowering J2EE Development, Pro Jakartha commons and J2EE 1.4 Bible.



                    • Innovative presentation by  Debraj Dutta  winner of the Oracle IoT Developer Challenge
                    • He showed us "Bot-So" which is taking photos and videos and calculating temperature by responding to twitter tweets designed using java 8 ,twitter 4j and Google drive  built on RaspberryPi hardware and Java platform.
                    • Bot-So is a smart social robot that interacts with you via twitter. The robot can be developed for remote home surveillance by sending commands via twitter. A tweet sent to the robot will trigger it to survey a space when the motion detector is triggered.
                    • He tweeted commands like "take a picture "  and it took a picture of us. it was amazing
                    • Java - Internet of everything.

                    • Here its Bot-So. (Robot-social)
                    • It can take a picture and video by rotating 120 degrees


                    • And we celebrated 20th java birth day by cutting a nice cake.

                    Happy birth day java
                    • After that had a group photo and nice lunch with team. Had a nice discussion with Sreekanth Narayanan.
                    •  met other bloggers and enjoyed the session and found it informative and encouraging.
                    • Its me Saidesh 1st from left and Indira second from right
                    Java 20 years




                    java 20 years




                    Select Menu