Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › How well does Java translate to C?
New Posts  All Forums:Forum Nav:

How well does Java translate to C?

post #1 of 14
Thread Starter 
I'm currently learning Java this semester then going to C next semester.

I understand just about every basic idea of Java (printing, DateFormats, DecimalFormats, if, else, switch, while, do-while, for, Arrays, Stacks, classes, methods, etc etc etc)

How easy will C be? Or is it a completely different world?
    
CPUMotherboardGraphicsRAM
AMD Phenom II X6 1090T Black Edition ASUS M4A89GTD PRO/USB3 XFX HD-577A-ZNFC Radeon HD 5770 G.SKILL 8gb (2x4gb) 1333mhz 
Hard DriveOSMonitorKeyboard
WD Caviar Black WD1002FAEX 1TB 7200 R Windows 7 Home Premium (none yet) Nothing special 
PowerCaseMouse
CORSAIR CMPSU-850TX 850W COOLER MASTER HAF 922 Logitech G700 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
AMD Phenom II X6 1090T Black Edition ASUS M4A89GTD PRO/USB3 XFX HD-577A-ZNFC Radeon HD 5770 G.SKILL 8gb (2x4gb) 1333mhz 
Hard DriveOSMonitorKeyboard
WD Caviar Black WD1002FAEX 1TB 7200 R Windows 7 Home Premium (none yet) Nothing special 
PowerCaseMouse
CORSAIR CMPSU-850TX 850W COOLER MASTER HAF 922 Logitech G700 
  hide details  
Reply
post #2 of 14
well if you were talking about C++ i here knowing java gives you a head start. C requires a lot of stuff to be done manually stuff like memory management... If I remember correctly.
Core 2 Haf
(16 items)
 
  
CPUMotherboardGraphicsRAM
C2Q Q9550 ASUS P5E3 Deluxe Wifi-AP GTX 480 Kingston HyperX DDR3 KHX1600C9D3K2/8G 
RAMHard DriveCoolingOS
PNY 1333 55gb, 320Gb, 500GB, 1TB Hyper 212 EVO Win 7 Ultimate 64bit 
OSOSPowerCase
Lubuntu 13.04 x64 OS X 10.8.5 TX750 Haf 912 
  hide details  
Reply
Core 2 Haf
(16 items)
 
  
CPUMotherboardGraphicsRAM
C2Q Q9550 ASUS P5E3 Deluxe Wifi-AP GTX 480 Kingston HyperX DDR3 KHX1600C9D3K2/8G 
RAMHard DriveCoolingOS
PNY 1333 55gb, 320Gb, 500GB, 1TB Hyper 212 EVO Win 7 Ultimate 64bit 
OSOSPowerCase
Lubuntu 13.04 x64 OS X 10.8.5 TX750 Haf 912 
  hide details  
Reply
post #3 of 14
You learning C or C++? C doesn't have strings nor classes. Where as C++ does.

Either one would be easier to learn once you know the basics of Java though as Java's syntax is very much C-like
post #4 of 14
There is no OOP in C. So no classes, private variables, objects.
Small command prompt programs are easier in C but once you want to use a GUI or send messsages over a network you have to write a lot more code to get this done.
the syntax is mostly the same, for/if/switchcase is all the same.

and like cdoublejj said, C doesn't run on a virtual machine so it doesn't has garbage collection.
if you do something like
char *array = malloc(32);
*array = malloc(32);

then you have 32 bytes allocated in your memory that you can't access and will stay there until you close the program. This is called a memory leak.
To solve this you have to release the memory before allocating more memory.

char *array = malloc(32);
free(array);
*array = malloc(32);

This very often leads to bugs because you freed something too early and then you tried reading data that was no longer allocated.

Those * are used to declarate pointers. Pointers are probably the hardest thing to get used to. In java everything is automaticly a pointer except the primitive types (int/char/double/etc). In C you have to write yourself if something is gonna be a pointer. After 3 years of learning C at school i still don't know when i have to use * or & or nothing. Luckily the compiler usually catches those errors.
Edited by Sisaroth - 11/1/12 at 3:03am
2013
(11 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i7 2700k GIGABYTE GA-Z77-D3H Sapphire HD 7870 XT Boost G.SKILL 1866 Sniper 2x4 GB 
Hard DriveHard DriveOSMonitor
Samsung 840 Basic Crucial MX200 Windows 10 HP IPS 23-inch 1080p 
PowerCaseMouse
Be quiet! BN144 System Power 7 500W NZXT Tempest 210 Zowie FK1 
  hide details  
Reply
2013
(11 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i7 2700k GIGABYTE GA-Z77-D3H Sapphire HD 7870 XT Boost G.SKILL 1866 Sniper 2x4 GB 
Hard DriveHard DriveOSMonitor
Samsung 840 Basic Crucial MX200 Windows 10 HP IPS 23-inch 1080p 
PowerCaseMouse
Be quiet! BN144 System Power 7 500W NZXT Tempest 210 Zowie FK1 
  hide details  
Reply
post #5 of 14
The thing is if you can learn one language its pretty easy to switch to another language you just have to read the syntax.

So it won't be hard. I myself learned Java then C++ then C(weird right?).
post #6 of 14
Quote:
Originally Posted by Sisaroth View Post

and like cdoublejj said, C doesn't run on a virtual machine so it doesn't has garbage collection.

The fact that Java runs in a virtual machine isn't correlated with the presence of GC at all.

See, the D language has GC and it actually doesn't run in a VM.

Also, there is actually a GC algorithm for C: Hans-Böhm, which works as a plugin and gets compiled with your code.
Quote:
Originally Posted by Makyl View Post

I myself learned Java then C++ then C(weird right?).

Not necessarily weird to start with Java since its a good starter language and the syntax is more easy-to-use.

But sure from a programming standpoint its a bit in reverse order. tongue.gif
Ti-89 Titanium
(13 items)
 
   
CPUMotherboardRAMHard Drive
Motorola 68k @16 MHz Ti-89 HW4 256 KB 2.6 MB Flash ROM 
OSMonitorPowerCase
Ti-89 OS 3.10 LCD Dot-Matrix 160x100 4x 1.5V AAA Ti-89 HW4 Black 
CPUMotherboardGraphicsRAM
Intel Core™ i7 930 Gigabyte GA-X58A-UD3R 2.0 Gigabyte GTX 470 SOC G.Skill RX 2x4GB 1600C8 
Hard DriveHard DriveOptical DriveCooling
PNY Prevail Elite 120GB Hitachi 7K1000.C 1TB LG GH24LS50 Noctua NH-C12P SE14 
OSOSMonitorKeyboard
Windows 8 Pro x64 Lubuntu 13.10 x64 Samsung BX2250 Logitech Illuminated 
PowerCaseMouseAudio
Be Quiet! S.P. E⁷ 600W Fractal Design Core 3000 Logitech G300 AKG K240 Studio 
  hide details  
Reply
Ti-89 Titanium
(13 items)
 
   
CPUMotherboardRAMHard Drive
Motorola 68k @16 MHz Ti-89 HW4 256 KB 2.6 MB Flash ROM 
OSMonitorPowerCase
Ti-89 OS 3.10 LCD Dot-Matrix 160x100 4x 1.5V AAA Ti-89 HW4 Black 
CPUMotherboardGraphicsRAM
Intel Core™ i7 930 Gigabyte GA-X58A-UD3R 2.0 Gigabyte GTX 470 SOC G.Skill RX 2x4GB 1600C8 
Hard DriveHard DriveOptical DriveCooling
PNY Prevail Elite 120GB Hitachi 7K1000.C 1TB LG GH24LS50 Noctua NH-C12P SE14 
OSOSMonitorKeyboard
Windows 8 Pro x64 Lubuntu 13.10 x64 Samsung BX2250 Logitech Illuminated 
PowerCaseMouseAudio
Be Quiet! S.P. E⁷ 600W Fractal Design Core 3000 Logitech G300 AKG K240 Studio 
  hide details  
Reply
post #7 of 14
Quote:
Originally Posted by NoDoubtFilms View Post

I'm currently learning Java this semester then going to C next semester.
I understand just about every basic idea of Java (printing, DateFormats, DecimalFormats, if, else, switch, while, do-while, for, Arrays, Stacks, classes, methods, etc etc etc)
How easy will C be? Or is it a completely different world?

Coming from Java, it will be easier than learning C from scratch - I can tell you that much.
But in the world of C, you get to do most things yourself.
Quote:
Originally Posted by Plan9 View Post

You learning C or C++? C doesn't have strings nor classes. Where as C++ does.
Either one would be easier to learn once you know the basics of Java though as Java's syntax is very much C-like

+1
Quote:
Originally Posted by Sisaroth View Post

There is no OOP in C. So no classes, private variables, objects.
Small command prompt programs are easier in C but once you want to use a GUI or send messsages over a network you have to write a lot more code to get this done.
the syntax is mostly the same, for/if/switchcase is all the same.
and like cdoublejj said, C doesn't run on a virtual machine so it doesn't has garbage collection.
if you do something like
char *array = malloc(32);
*array = malloc(32);
then you have 32 bytes allocated in your memory that you can't access and will stay there until you close the program. This is called a memory leak.
To solve this you have to release the memory before allocating more memory.
char *array = malloc(32);
free(array);
*array = malloc(32);
This very often leads to bugs because you freed something too early and then you tried reading data that was no longer allocated.
Those * are used to declarate pointers. Pointers are probably the hardest thing to get used to. In java everything is automaticly a pointer except the primitive types (int/char/double/etc). In C you have to write yourself if something is gonna be a pointer. After 3 years of learning C at school i still don't know when i have to use * or & or nothing. Luckily the compiler usually catches those errors.

typedefs solve the not knowing when to use a pointer problem/confusion.
Code:
typedef struct _my_type
{
        int val1;
        int val2;
} my_type, *p_my_type;

Then just use p_my_type everywhere in the code. No need for "*" or "&".

Also you can use realloc(). No need to free and then release to allocate memory at the same address.
Quote:
Originally Posted by Makyl View Post

The thing is if you can learn one language its pretty easy to switch to another language you just have to read the syntax.
So it won't be hard. I myself learned Java then C++ then C(weird right?).

Bit more than just reading the syntax, but sure tongue.gif

Quote:
Originally Posted by adridu59 View Post

The fact that Java runs in a virtual machine isn't correlated with the presence of GC at all.
See, the D language has GC and it actually doesn't run in a VM.
Also, there is actually a GC algorithm for C: Hans-Böhm, which works as a plugin and gets compiled with your code.
Not necessarily weird to start with Java since its a good starter language and the syntax is more easy-to-use.
But sure from a programming standpoint its a bit in reverse order. tongue.gif

The problem is that without the managed type of VM like in Java, the GC doesn't know enough about the program to be efficient enough so this is why you typically see the managed runtime and GC association. Garbage collection is just not something that is well suited to C or C++, though it is quite neat I must say. A virtual machine is different to a runtime - the runtime is where the GC lives.

Although arguably, the Java GC is pretty crap.
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #8 of 14
Quote:
Originally Posted by tompsonn View Post

Bit more than just reading the syntax, but sure tongue.gif.

Yeah but it would be easy to learn another language of you know one of the languages. It becomes quite easy,actually.
post #9 of 14
WOAH, i never said any thin at all about Garbage Collection or VM. What i'm saying is some stuff that is done for you in C++ has to be done by hand (more or less).
Core 2 Haf
(16 items)
 
  
CPUMotherboardGraphicsRAM
C2Q Q9550 ASUS P5E3 Deluxe Wifi-AP GTX 480 Kingston HyperX DDR3 KHX1600C9D3K2/8G 
RAMHard DriveCoolingOS
PNY 1333 55gb, 320Gb, 500GB, 1TB Hyper 212 EVO Win 7 Ultimate 64bit 
OSOSPowerCase
Lubuntu 13.04 x64 OS X 10.8.5 TX750 Haf 912 
  hide details  
Reply
Core 2 Haf
(16 items)
 
  
CPUMotherboardGraphicsRAM
C2Q Q9550 ASUS P5E3 Deluxe Wifi-AP GTX 480 Kingston HyperX DDR3 KHX1600C9D3K2/8G 
RAMHard DriveCoolingOS
PNY 1333 55gb, 320Gb, 500GB, 1TB Hyper 212 EVO Win 7 Ultimate 64bit 
OSOSPowerCase
Lubuntu 13.04 x64 OS X 10.8.5 TX750 Haf 912 
  hide details  
Reply
post #10 of 14
I learned C and Java at the same time. The procedural aspect of C gave me a more rewarding feeling as you had to do a bit more programming to achieve similar results. You also have to manage the memory manually if you are dealing with pointers which can be tricky; whenever you use the keyword new, you also use a corresponding delete to deallocate the memory. Structs in C are essentially classes without methods. Also when you end a character array in C you have to use the null character '\0'.

Also, the first thing you should learn are how to use scanf and printf statements as they will be used very frequently. Also, learn about the precompiled headers that are often used.

There are vast amount of libraries in java that can do complex things in one statement, in C it is not like that. Coming from Java and knowing the basics, you should pick up C quickly.
Edited by surfbumb - 11/3/12 at 1:07am
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 10 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 10 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › How well does Java translate to C?