Posts

Showing posts from 2016

Number Programs

1.Happy Number :    import java.util.*;    class happy    {      public static int sum(int n)        {         int s,i,d;         s=0;         for(i=n;i!=0;i=i/10)             {               d=i%10;               s=s+(d*d);             }           return s;        }      public static void main()       {         Scanner sn=new Scanner(System.in);         int num,s;         System.out.println("enter a number");         num=sn.nextInt();         s=num;             while(s>6)          ...

Pre-icse Preparation

Programs to hunt for Pre-icse : 1.Arrays *Bubble Sort with numbers and strings. *Selection Sort with numbers and strings. *Binary Search with numbers and strings. *Linear Search with numbers and strings. *Merging of two arrays. *Arranging even and odd digits in arrays from opposite sides. *Fibonacci series in arrays. 2.String *Vowels printing and counting. *Reverse of sentences. *Reverse of words in a sentence. *Counting of spaces, capitals and small alphabets. *Extraction of words. *Piglatin form. *Programs having use of substring. To be continued..

Important Definitions

Java – Glossary of Terms 1. Abstract methods : All methods in an interface are abstract i.e., their body needs to be defined in a class that implement the interface. 2. Accessor method : It is a method that returns the value of a data : member of the class. It is actually for Private members. 3. Arguments : The values which are passed to the method during its call from the caller. 4. Base class : It is a class which is inherited by another class. 5. Binary file : store information in a form of bytes. 6. Block : It is a group of zero or more statements between balanced braces and can be used anywhere a single statement is allowed. 7. Break : It is a keyword, which is used to terminate the loop or switch case, when the condition is satisfied. 8. Buffer : is a high speed temporary storage, which is also known as cache memory 9. Buffered reader : It buffers the input and improves the performance. 10. Byte stream classes : They are built up to provide the functionality of reading and w...

Pre-icse Revision

Java Facts James Gosling is the founder of Java (in 1995) it was formally announced in 1997. Java is a case sensitive language which means that the uppercase and lowercase letters are distinct. Blue J is an environment of Java (IDE) developed by David Barns and Michael Kollins. There are 5 types of Tokens in Java. The conversion process of Java is unique, (two step). Java follows UNICODE character set. char type is a Unicode character stored as an unsigned number in two bytes (range 0..65,535 or ‘\u0000′..’\uFFFF’). After the two // characters, Java ignores everything to the end of the line. After the /* characters, Java will ignore everything until it finds a */. Class and interface names start with an uppercase letter, and continue in lowercase. Lowercase is used for variable and method names. If a name has multiple words, use Camel Case The names of constants should be in all uppercase. The wildcard * only makes the classes in this package visible, not any of the su...

Constructors

Constructors in Java A Constructor is a member method of a class which has same name as that of a class; has no return type not even void, used to initialize the instance variables of a class, and gets invoked automatically as soon as the object of the class is created. class Constr { int n; Constr( ) { n = 0; }                                                  public static void main( ) { // invokes the constructor Constr obj = new Constr( );.    System.out.println(obj.n); } } Types of Constructors Non Parameterized Constructors Parameterized Constructors A constructor that accepts no parameters are called non parameterized  constructors, non parameterized constructors that initialize the instance variables to zero, null and empty values are called  Default Constructors.  Above is an example of default constructor. A...

Functions

Functions in Java A function is a block or portion of code within a larger program which consists of some declarations and executable statements, which performs a specific task and is relatively independent of the remaining code. The term method is used alternatively with function and means the same in Java programming language. A larger block of code is broken down into smaller and simpler modules called ‘member methods’ this is how the OOP language Java implements ‘Modularity’. Advantages of using Functions – 1. To cope with the complexity of code by breaking down complex bigger code into smaller and simpler ones. 2. Hiding details (thus implementing Abstraction) 3. Reusability of Code 4. Makes debugging of errors easy. Anatomy of a function FUNCTION NAME ( ) { Body of the function… } Let us now see all the components individually – 1. These are keywords which define the accessibility of the function, if nothing is mentioned then by default it is ‘friendly’ friendly is ...

Flow Control in Java Programs

Flow Control in Java Programs if Statement The purpose of the if statement is to make decisions, and execute different parts of your program depending on a boolean true/false value. The ‘if’ statement has this form, where condition is true or false if (condition) { … // Do this clause if the condition is true. } Alternative forms of if statements – if (condition) { … // Do this clause if the condition is true } else { … // Do this clause if the condition is false } Always make sure that the number of if clause should not exceed the number of else clause, because it will result in ‘dangling else problem’, in such case make use of if…else if…else construct as shown below – if (condition 1) { … // Do this clause if the condition is true } else if (condition 2) { … // Do this clause if the condition is false } else { … // Do this clause if the condition is false } switch…case Statement The if statement allows you to select one of two sections of code to...