Date published: 


Java programming: Java program code consists of instructions which will be . If you like to learn using PDF books then try learning java from following e-books. Java is the most popular programming language & is the language of choice for Android programming. mystical poems of rumi Translated from the Persian by meteolille.infoy Annotated and prepared Mystical Poems of Rumi Programming with Java: a Primer,3e.

Language: English, Spanish, Hindi
Country: Madagascar
Genre: Lifestyle
Pages: 106
Published (Last): 10.08.2016
ISBN: 823-6-29502-863-7
PDF File Size: 18.81 MB
Distribution: Free* [*Regsitration Required]
Uploaded by: NORRIS

92282 downloads 167285 Views 37.80MB ePub Size Report

This book is intended for people with at least some basic programming back- ground what programming is, but you've heard Java is easy to learn, really. programming languages are presented through writing Java programs. Java is selected as creating computer programs and, with examples given in this book, . For most of the examples given in this tutorial, you will find a 'Try it' option, which you can use to execute your Java programs at the spot and enjoy your learning.

Hello World example 3 2. Add two matrices 4 3. Armstrong number 7 4. Binary Search 11 5. Bubble sort 14 6. Command line arguments 17 7.

Remember that smallest prime number is 2. We have used sqrt method of Math package which find square root of a number.

To check if an integer say n is prime you can check if it is divisible by any integer from 2 to n-1 or check from 2 to sqrt n , first one is less efficient and will take more time. Java program to print Floyds triangle This java program prints Floyds triangle. This is a simple pattern to print but helpful in learning how to create other patterns.

Key to develop pattern is using nested loops appropriately. Java program to reverse a string This java program reverses a string entered by the user. We use charAt method to extract characters from the string and append them in reverse order to reverse the entered string. Java program to check palindrome Java palindrome program: Java program to check if a string is a palindrome or not.

Remember a string is a palindrome if it remains unchanged when reversed, for example dad is a palindrome as reverse of dad is dad whereas program is not a palindrome.

Programs pdf java

Some other palindrome strings are mom, madam, abcba. Interface in Java Interface in Java: Java interfaces are like Java classes but they contain only static final constants and declaration of methods. Methods are not defined and classes which implements an interface must define the body of method s of interface s.

Final constants cant be modified once they are initialized; final, interface, extend and implements are Java keywords. Declaration of interface:. Interface program in Java In our program we create an interface named Info which contains a constant and a method declaration.

We create a class which implements this interface by defining the method declared inside it. Java program to compare two strings This program compare strings i. If you wish to compare strings but ignoring the case then use compareToIgnoreCase method. To check two strings for equality you can use equals method which returns true if strings are equal otherwise false. Java program for linear search Java program for linear search: Linear search is very simple, To check if an element is present in the given list we compare search element with every element in the list.

If the number is found then success occurs otherwise the list doesnt contain the element we are searching. Above code locate first instance of element to found, you can modify it for multiple occurrence of same element and count how many times it occur in the list. Similarly you can find if an alphabet is present in a string.

Java program for binary search Java program for binary search: This code implements binary search algorithm. Please note input numbers. Java program to find all substrings of a string Java program to find substrings of a string: For example substrings of fun are: Java code to print substrings of a string is given below.

Empty string is considered to be substring of every string also known as NULL string. Java program to generate random numbers Java program to generate random numbers: This code generates random numbers in range 0 to both inclusive.

To generate random floats use nextFloat which returns float between 0. Java program to perform garbage collection This program performs garbage collection. Free memory in java virtual machine is printed and then garbage collection is done using gc method of RunTime class, freeMemory method returns amount of free memory in jvm, getRunTime method is used to get reference of current RunTime object.

Obviously the amount of available after garbage collection will be different on your computer. Numbers are not important, what is important is that amount of memory available is more than before. You can use this code in your program or projects which uses large amount of memory or where frequently new objects are created but are required for a short span of time.

Java program to get ip address This program prints IP or internet protocol address of your computer system. InetAddress class of java. Java has a very vast Networking API and can be used to develop network applications. Java program to reverse number This program prints reverse of a number i.

You can also reverse or invert a number using recursion. You can use this code to check if a number is palindrome or not, if the reverse of an integer is equal to integer then its a palindrome number else not. Java program to transpose matrix This java program find transpose of a matrix of any order. This code can be used to check if a matrix symmetric or not, just compare the matrix with its transpose if they are same then its symmetric otherwise non symmetric, also its useful for calculating orthogonality of a matrix.

Java program to multiply two matrices This java program multiply two matrices. Before multiplication matrices are checked whether they can be multiplied or not. This is a basic method of multiplication, there are more efficient algorithms available.

Also this approach is not recommended for sparse matrices which contains a large number of elements as zero. Java program to open Notepad How to open Notepad through java program: Notepad is a text editor which comes with Windows operating system, It is used for creating and editing text files.

Pdf java programs

You may be developing java programs in it but you can also open it using your java code. How to open notepad using Java program. Download Notepad program. Explanation of code: You can also specify a file while opening notepad such as exec notepad programming. You can launch other applications using exec method, for example exec calc will launch calculator application.

If an application is present in a directory which is not set in environment variable PATH then you can specify complete path of application. How to find a digit string from the given alphanumeric string. Matcher; import java.

Pdf java programs

This would produce the following result: Found value: This order was placed for QT! This order was placed for QT Found value: This example shows how we can search a word within a String object using indexOf method which returns a position index of a word within the string if found. Otherwise it returns The above code sample will Result: How to optimize string concatenation?

The above code sample will produce the following result. The result may vary. This example shows how to merge two arrays into a single array by the use of list.


Addall array1. ArrayList; import java. Arrays; import java. How to check if two arrays are equal or not? Following example shows how to use equals method of Arrays to check if two arrays are equal or not.

How to use method overriding in Inheritance for subclasses? This example demonstrates the way of method overriding by subclasses with different number and type of parameters. Is array 1 equal to array 2?? Inside area for figure. Area is: Following example shows how to implement stack by creating user defined push method for entering elements and pop method for retriving elements from the stack. How to implement Queue? Following example shows how to implement a queue in an employee structure.

The employees name are: JVM is an acronym for Java Virtual Machine, it is an abstract machine which provides the runtime environment in which java bytecode can be executed. It is a specification. It physically exists. Many types: Class Method Area 2. Stack 4. Program Counter Register 5. Native Method Stack. It is used to improve the performance.

JIT compiles parts of the byte code that have similar functionality at the same time, and hence reduces the amount of time needed for compilation. Here the term compiler refers to a translator from the instruction set of a Java virtual machine JVM to the instruction set of a specific CPU. A platform is basically the hardware or software environment in which a program runs.

There are two types of platforms software-based and hardwarebased. Java provides software-based platform. The Java platform differs from most other platforms in the sense that its a software-based platform that runs on top of other hardware-based platforms. It has two components: Runtime Environment 2. The bytecode. Java is compiled to be a byte code which is the intermediate language between source code and machine code.

This byte code is not platform specific and hence can be fed to any platform. The classloader is a subsystem of JVM that is used to load classes and interfaces. There are many types of classloaders e. Bootstrap classloader, Extension classloader, System classloader, Plugin classloader etc. Yes, save your java file by. The local variables are not initialized to any default value, neither primitives nor object references. But they have been categorized in many sections such as constructor interview questions, static interview questions, Inheritance Interview questions, Abstraction interview question, Polymorphism interview questions etc.

Object based programming languages follow all the features of OOPs except Inheritance. The object references are all initialized to null in Java. Constructor is just like a method that is used to initialize the state of an object.

It is invoked at the time of object creation. The default constructor provides the default values to the objects. The java compiler creates a default constructor only if there is no constructor in the class.

A static method belongs to the class rather than object of a class. A static method can be invoked without the need for creating an instance of a class. Is used to initialize the static data member. It is executed before main method at the time of classloading. A method i. Object is required to call instance methods. Inheritance is a mechanism in which one object acquires all the properties and behaviour of another object of another class. It represents IS-A relationship.

It is used for Code Resusability and Method Overriding. To reduce the complexity and simplify the language, multiple inheritance is not supported in java in case of class. Aggregation represents weak relationship whereas composition represents strong relationship. For example: Pointer is a variable that refers to the memory address.

They are not used in java because they are unsafe unsecured and complex to understand. Because super or this must be the first statement. The object cloning is used to create the exact copy of an object. If a class have multiple methods by same name but different parameters, it is known as Method Overloading.

It increases the readability of the program. If a subclass provides a specific implementation of a method that is already provided by its parent class, it is known as Method Overriding. It is used for runtime polymorphism and to provide the specific implementation of the method. It is because the static method is the part of class and it is bound with class whereas instance method is bound with object and static gets memory in class area and instance gets memory in heap.

Method Overriding 1 Method overloading increases the readability of the program. Method overriding provides the specific implementation of the method that is already provided by its super class. Method overriding occurs in two classes that have IS-A relationship. In this case, parameter must be same. Yes, all functions in Java are virtual by default. Now, since java5, it is possible to override any method by changing the return type if the return type of the subclass overriding method is subclass type.

It is known as covariant return type. If you make any variable as final, you cannot change the value of final variable It will be constant. A final variable, not initalized at the time of declaration, is known as blank final variable.

Java Interview Questions 51 Can we intialize blank final variable? Yes, only in constructor if it is non- static. If it is static blank final variable, it can be initialized only in the static block. Runtime polymorphism or dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile-time.

In this process, an overridden method is called through the reference variable of a super class. The determination of the method to be called is based on the object being referred to by the reference variable.

In case of static binding type of object is determined at compile time whereas in dynamic binding type of object is determined at runtime. Abstraction is a process of hiding the implementation details and showing only functionality to the user. Abstraction lets you focus on what the object does instead of how it does it.

Abstraction hides the implementation details whereas encapsulation wraps code and data into a single unit. A class that is declared as abstract is known as abstract class. It needs to be extended and its method implemented. It cannot be instantiated. Interface is a blueprint of a class that have static constants and abstract methods.

It can be used to achieve fully abstraction and multiple inheritance.

Java Programming

No, because methods of an interface is abstract by default, and static and abstract keywords cant be used together. An interface that have no data member and method is known as a marker interface. For example Serializable, Cloneable etc. Abstract class Interface 1 An abstract class can have method body nonabstract methods. Interface have only abstract methods.

An interface cannot have instance variables. Interface cannot have constructor. Interface cannot have static methods. You can implement multiple interfaces.

An object reference can be cast to an interface reference when the object implements the referenced interface. A package is a group of similar type of classes interfaces and sub-packages. It provides access protection and removes naming collision. One can import the same package or same class multiple times. Neither compiler nor JVM complains about it. But the JVM will internally load the class only once no matter how many times you import the same class.

By static import, we can access the static members of a class directly, there is no to qualify it with the class name. Exception Handling is a mechanism to handle runtime errors.

100 Java Programs With Output Useful Collection of Java Programs - Aniket Pataskar

It is mainly used to handle checked exceptions. The classes that extend Throwable class except RuntimeException and Error are known as checked exceptions e. Checked exceptions are checked at compile-time. The classes that extend RuntimeException are known as unchecked exceptions e. ArithmeticException,NullPointerExcept ion etc. Unchecked exceptions are not checked at compiletime.

Java programs

It is not necessary that each try block must be followed by a catch block. It should be followed by either a catch block OR a finally block.

And whatever exceptions are likely to be thrown should be declared in the throws clause of the method. Forwarding the exception object to the invoking method is known as exception propagation. There is given a list of string handling interview questions with short and pointed answers.

If you know any string handling interview question, kindly post it in the comment section. The simple meaning of immutable is unmodifiable or unchangeable. Once string object has been created, its value cant be changed. Because java uses the concept of string literal.

Suppose there are 5 reference variables,all referes to one object sachin. If one reference variable changes the value of the object, it will be affected to all the reference variables. That is why string objects are immutable in java. There are two ways to create the string object, by string literal and by new keyword.

To make Java more memory efficient because no new objects are created if it exists already in string constant pool. The toString method returns the string representation of any object. If you print any object, java compiler internally invokes the toString method on the object.

So overriding the toString method, returns the desired output, it can be the state of an object etc. Core Java: Nested classes and Interfaces Interview Questions 94 What is nested class? A class which is declared inside another class is known as nested class.

There are 4 types of nested class member inner class, local inner class, annonymous inner class and static nested class. Yes, inner classes are non-static nested classes i.

No, local variable must be constant if you want to access it in local inner class. Any interface i. It is static by default. Garbage collection is a process of reclaiming the runtime unused objects.

It is performed for memory management. It is used to perform cleanup processing. You, cant change the value of final variable, cant override final method, cant inherit final class.

The finalize method can be used to perform any cleanup processing. By Runtime. Serialization is a process of writing the state of an object into a byte stream.

It is mainly used to travel objects state on the network.

Pdf java programs

Deserialization is the process of reconstructing the object from the serialized state. It is the reverse operation of serialization. Externalizable interface is used to write the state of an object into a byte stream in compressed format.

It is not a marker interface. Serializable is a marker interface but Externalizable is not a marker interface. When you use Serializable interface, your class is serialized automatically by default. But you can override writeObject and readObject two methods to control more complex object serailization process. When you use Externalizable interface, you have a complete control over your classs serialization process.

JAVA Programming Tutorial for Beginners PDF

By InetAddress. Reflection is the process of examining or modifying the runtime behaviour of a class at runtime. It is used in: Eclipse, MyEclipse, NetBeans. Debugger Test Tools etc.

Flag for inappropriate content. Related titles. Jump to Page. Search inside document. Java Interview Questions part 2 Hello World is passed as an argument to println method, you can print whatever you want. Java programming source code Output of program: Another method to check odd or even, for explanation see: Java programming if else statement Output of program: You can test multiple conditions such as Loop body is executed till value of a is greater than value of b and c is not equal to zero.

Java source code You can easily modify the above java program to print alphabets in upper case. Java program to print multiplication table This java program prints multiplication table of a number entered by the user using a for loop. Java programming source code while or do Output of program: Java Method example program Output of program: Java string class program Output of program: Java static block program Output of program: Java static method example program Output of program: To run type: If you are just starting to learn Java then it is recommended to buy Java programming book.

A Java book will help you to learn basic concepts easily and will act as a reference for all time. This is similar to a hello world Java program. Download java programming class file. Output of program: Java programming language Below is the list of java programs which will help you in learn java programming language. As your programming experience grows in Java you may be developing your own project or software, using a simple text editor isn't recommended. Following are two popular and open source IDE's:.

Using IDE helps you a lot while coding as they offer many useful features such as you can create GUI in Netbeans without writing any code, Netbeans will show you any compilation error before you compile your code and it can also show hints on how to fix that. Java technology has changed our life as most of the devices we use today includes java that's why to learn java programming is a good thing.

Java was developed by Sun Microsystems but now owned by Oracle. Java program consists of classes which contain methods; you can't write a method outside of a class. Objects are instances of classes. Consider the following code:. There is a ProgrammingLanguage class, and all programming languages will be instances of this class. We have considered only two attributes language name and type; we can create instances of the class using "new" keyword.

Related Documents

Copyright © 2019 meteolille.info. All rights reserved.