Posts

Showing posts from 2015

Arrays in Java

Hello Guys.... This is my second post and in this i am going to talk about Arrays in Java Programming Language. So let's get started:- 1-D Array There are two ways of declaring 1-D array in java :- 1st Method (without using the new keyword) :- Consider this code :-  When we  run this code in a file named array.java we get the output as follows :- Months -  1 2 3 4 5 6 7 8 9 10 11 12 2nd Method (using the new keyword) :- Consider this code :- When we run this code in a file named array.java we get the output as follows :- Rahul Malhotra is a coder   2-D Array    We can declare the 2-D array in java also by two methods :- 1st Method (using the new keyword) :- The declaration of the 2-D array is the same by the two methods that we just discussed in the 1-D array. The main feature that Java provides in the 2-D array is that, out of the two attributes, one attribute is fixed and other can vary.... Let's learn wi

Important Basics of Java Programming Language

Hello Guys.... This is my first post and in this i am going to talk about some of the important basics and concepts of Java Programming Language which are generally ignored by most of us... I hope that after reading this post many basic concepts regarding java will be cleared to you.So let's get started:-   1. Automatic Type Promotion  Consider this code :-  public class promotion {     public static void main(String args[])     {         byte a=10;         byte b=2;         byte c=a*b;         System.out.println("Result of 10x2 = "+c);     } } When we  run this code in a file named promotion.java we get the error as follows :- Exception in thread "main" java.lang.Error: Unresolved compilation problem:     Type mismatch: cannot convert from int to byte     at promotion.main(promotion.java:7) So why do we get this error ???? as we know that the range of the byte is 256 and the multiplication of  'a' and 'b' is 20 whi