Why is it good advice to indent all the statements inside a set of braces in java programming?
it is necessary to indent all the statements inside a set of braces so that the compiler can know what & when to be compiled.An opening braces indicates that a new process has created & closing braces indicates that the process is getting terminated at that point.
#include<stdio.h>
#include<conio.h>
int find_gcd(int,int);
int find_lcm(int,int);
int main(){
int num1,num2,gcd,lcm;
clrscr();
printf("\nEnter two numbers:\n ");
scanf("%d %d",&num1,&num2);
gcd=find_gcd(num1,num2);
printf("\n\nGCD of %d and %d is: %d\n\n",num1,num2,gcd);
if(num1>num2)
lcm = find_lcm(num1,num2);
else
lcm = find_lcm(num2,num1);
printf("\n\nLCM of %d and %d is: %d\n\n",num1,num2,lcm);
return 0;
}
int find_gcd(int n1,int n2){
while(n1!=n2){
if(n1>n2)
return find_gcd(n1-n2,n2);
else
return find_gcd(n1,n2-n1);
}
return x;
}
API is an Application Programming Interface.
It is an interface that defines the ways by which an application program may request services from libraries and/or operating systems.
An API determines the vocabulary and calling conventions the programmer should employ to use the services. It may include specifications for routines, data structures, object classes, and protocols used to communicate between the requesting software and the library.
An API itself is largely abstract in that it specifies an interface and controls the behavior of the objects specified in that interface. The software that provides the functionality described by an API is said to be an implementation of the API. An API is typically defined in terms of the programming language used to build the application.
The API initialism may sometimes be used as a reference, not only to the full interface, but also to one function, or even a set of multiple APIs provided by an organization. Thus, the scope of meaning is usually determined by the person or document that communicates the information.
Write a program for Multiplication of two matrices in java?
//Matrix multiplication import java.util.Scanner; public class Matrix
{
public static void main(String args[])
{
Scanner s= new Scanner(System.in);
int i,j,k; System.out.println("enter the value of n"); int n=s.nextInt(); int a[][]=new int[n][n]; int b[][]=new int[n][n]; int c[][]=new int[n][n]; System.out.println("enter the array elements of a:"); for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=s.nextInt();
}
}//end of a matrix System.out.println("enter the array elements of b:"); for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
b[i][j]=s.nextInt();
}
}//end of b matrix System.out.println("the result matrix is:");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
{ c[i][j]+=a[i][k]*b[k][j]; }
}
} for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(+c[i][j]);
}System.out.println();
}
}//end of main
}//end of class
Write a c program to compare two strings without using builtin function?
A string is a character array, so you can compare them one character at a time:
String x = "test"
String y = "test"
for(int i = 0; i < x.length && i < y.length; i++)
{
if(x[i] != y[i])
return false;
}
return true;
What is the difference between a computer hacker and a computer fraud?
A hacker is someone who take time on a computer to learn how to manipulate the system and have access to the system.
Hacking is the process of manipulating data in order to get into the system without permision
What is difference between parameter and argument in java?
They are synonyms.
Some people use the word 'argument' for the 'formal parameter' and 'parameter' for the 'actual parameter', others do on the other way around.
PS:
example for the formal parameters (function declaration):
int myfun (const char *s, int p);
example for the actual parameters (function calling):
myfun ("Hello", 44);
"Overloading" a function means that you have multiple functions with the same name, but different signatures. The signature of a function is its return type and number/types of parameters.
For example:
void foo(int a, char b)
can be distinguished from
void foo()
which can be distinguished from
void foo(double a)
which can be distinguished from
void foo(int a)
The program will call the correct function based off of the number and types of parameters it is given. So:
foo(1) will call the 4th example
foo(1.0) will call the 3rd example
foor() will call the 2nd example
and foo(1, 't') will call the 1st example
Note that MOST programming languages do not allow you to distinguish between function signatures by return type, thus:
void foo()
and
int foo()
is not allowed.
Function overloading should not be confused with function overriding. Overriding involves inheritance and is related to polymorphism.
Is it necessary to give the size of array?
Depends on the language. For C, no you don't. You can type blank brackets (int Arr[]) when declaring the array, or you can just use a pointer (int* Arr). Both will allow you to use the variable as an array without having to declare the specific size. Hope this answers your question.
In Java, an array is an object, and one which is dynamically allocated space. The default constructor does not require a size be specified.
What is the need of overloading in java?
Overloading is very useful in Java. For instance, methods can be overload as long as the type or number of parameters (arguments) differ for each version of the method. This comes in handy when, for instance, you need to perform a complex mathematical operation, but sometimes need to do it with two numbers and sometimes three, etc.
What are the characteristics of object oriented systems?
the three main design principles of object oriented programming are the following:
hashcode is an integer number which is provide to each object by jvm note that this is not address of object but for convencing internally they use
Java uses the hash function given below:- s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] where s[i] is the ith character of the string, n is the length of the string, and ^ indicates exponentiation.
I am not sure why you label it "hybrid". Java compiles the source code, not for a specific processor, but for what you might consider a fictitious processor. That is, it doesn't compile for the specific machine code understood by a real processor.As for the reason, that's because that's what Java is all about. Java programs are supposed to be compiled only once, and then run on any computer that has an appropriate Java runtime (the "Java Virtual Machine").
What is the function in java to find the size of given variable?
Dependion on the variable there are several methods to do it, this can only be applied to primitive types and arrays, for an array its the "name_of_array.length", for the arraylist this change just a little, it would be like "name_of_array_list.size()", for an int, double, float, long, byte, it would be like "name_of_variable.LENGTH" this is a public variable so you dont need a get, an finally for the String there is a method "name_of_string.length()" this would return the size of this String
How do you print 1 to 10 number using for loop?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace printnumber
{
class Program
{
static void Main(string[] args)
{
int i;
for (i = 0; i < 20; i++)
{
Console.Write(i);
Console.Read();
}
}
}
}
In Java, literal character strings such as "foo" are implemented as instances of the String class. These strings are constant and can not be modified directly. Mutable character strings, or string variables, are implemented as instances of StringBuffer class. It is also possible to work directly with arrays of chars, but String and related classes offer lots of useful methods.
Program to find palindrome in a string?
#include
#include
void main()
{
char str1[80];
int i,j,flag=1;
printf("enter a word:");
gets(str1);
for(i=0,j= (strlen(str1)-1);i<=(strlen(str1)-1),j>=0;i++,j--)
{
if(str1[i]!=str1[j])
flag=0;
}
if(flag)
printf("palindrome");
else
printf("not a palindrome");
}
What does the Java compiler translate Java source code to?
The Java compiler translates Java source code to Java byte code.
What is the function of a layoutmanager in java?
The function of a layout manager is to help the java programmer with aligning and positioning components inside the AWT or Java Swing components like a Frame or a Panel. Without the layout managers the programmer will have to position these components one by one manually which is very difficult and may also result in poor layout response when the user re-sizes the UI window.
Some of the commonly used layout managers are:
a. BorderLayout
b. GridLayout
c. GridBagLayout
d. Etc
Which produces faster program execution a compiler or pure interpreter?
A compiled program would execute faster than an interpreter running the same code step by step.
Why return type is not considered while overloading a function?
YES only if: The return type in the child class is a sub-type of the return type of the parent class.
Ex:
public int getName() {} - Parent class method
public String getName() {} - Child class method
If we implement the above two methods in the class hierarchy we will get compilation errors. whereas if we try the below implementation it will work:
public Object getName() {} - Parent class method
public String getName() {} - Child class method
This is because String is a sub-type of Object and hence it works.
This is also called as Covariant Overriding.
Note: This feature is available only from Java 1.5. Earlier versions of Java expect overriding methods to have exactly the same return type as the super class method.
What does the finalize method do in java?
The "finalize" method is called when an object is removed from memory. If you need to do any cleanup (closing streams/files, displaying output, etc.) you can put it in an overridden finalize method.
What are the advantages of different java datatypes?
The Basic data types in Java are
The String type is an object.
To learn more about Java go to:
[http://java.sun.com/docs/books/tutorial/java/index.html]
How do you run midlet program?
You need a J2ME implementation. Is short this means you need either:
- an Java enabled mobile phone or other handset (i.e one that can play games)
- a mobile device emulator.
For an emulator look for Wireless Toolkit (WTK) on Sun Microsystems or in the Sony Ericsson SDK. Usually you use this toolkit to write and build the MIDlet to begin with.